to 楼上: IDR_MAINFRAME 是主窗体的名字吧,这可不是childframe的名字哦~ 同意lovenoend(有容乃大)
to bcpl(Flex'n Relax) 我什么时机调用SetWindowText那?我试过这个方法,但是当ChildFrame切换时,系统就恢复它默认的Text形式了。 to lovenoend(有容乃大) 对于不同ChildFrame我有不同的字标题,如何针对不同的childFrame设置标题?多谢。
void CMDIFrameWnd::OnUpdateFrameTitle(BOOL bAddToTitle) { if ((GetStyle() & FWS_ADDTOTITLE) == 0) return; // leave it alone!#ifndef _AFX_NO_OLE_SUPPORT // allow hook to set the title (used for OLE support) if (m_pNotifyHook != NULL && m_pNotifyHook->OnUpdateFrameTitle()) return; #endif CMDIChildWnd* pActiveChild = NULL; CDocument* pDocument = GetActiveDocument(); if (bAddToTitle && (pActiveChild = MDIGetActive()) != NULL && (pActiveChild->GetStyle() & WS_MAXIMIZE) == 0 && (pDocument != NULL || (pDocument = pActiveChild->GetActiveDocument()) != NULL)) UpdateFrameTitleForDocument(pDocument->GetTitle()); else { LPCTSTR lpstrTitle = NULL; CString strTitle; if (pActiveChild != NULL) { strTitle = pActiveChild->GetTitle(); if (!strTitle.IsEmpty()) lpstrTitle = strTitle; } UpdateFrameTitleForDocument(lpstrTitle); } } void CFrameWnd::OnUpdateFrameTitle(BOOL bAddToTitle) { if ((GetStyle() & FWS_ADDTOTITLE) == 0) return; // leave it alone!#ifndef _AFX_NO_OLE_SUPPORT // allow hook to set the title (used for OLE support) if (m_pNotifyHook != NULL && m_pNotifyHook->OnUpdateFrameTitle()) return; #endif CDocument* pDocument = GetActiveDocument(); if (bAddToTitle && pDocument != NULL) UpdateFrameTitleForDocument(pDocument->GetTitle()); else UpdateFrameTitleForDocument(NULL); }
CFrameWnd *pFrame = pMDIFrame->GetActiveFrame();
if(pFrame->GetSafeHwnd())
{
pFrame->SetWindowText("Hello");
}最好还处理这个:
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs if( !CMDIChildWnd::PreCreateWindow(cs) )
return FALSE; cs.style &= ~FWS_ADDTOTITLE; // add this
return TRUE;
}
IDR_MAINFRAME 是主窗体的名字吧,这可不是childframe的名字哦~
同意lovenoend(有容乃大)
我什么时机调用SetWindowText那?我试过这个方法,但是当ChildFrame切换时,系统就恢复它默认的Text形式了。
to lovenoend(有容乃大)
对于不同ChildFrame我有不同的字标题,如何针对不同的childFrame设置标题?多谢。
{
if ((GetStyle() & FWS_ADDTOTITLE) == 0)
return; // leave it alone!#ifndef _AFX_NO_OLE_SUPPORT
// allow hook to set the title (used for OLE support)
if (m_pNotifyHook != NULL && m_pNotifyHook->OnUpdateFrameTitle())
return;
#endif CMDIChildWnd* pActiveChild = NULL;
CDocument* pDocument = GetActiveDocument();
if (bAddToTitle &&
(pActiveChild = MDIGetActive()) != NULL &&
(pActiveChild->GetStyle() & WS_MAXIMIZE) == 0 &&
(pDocument != NULL ||
(pDocument = pActiveChild->GetActiveDocument()) != NULL))
UpdateFrameTitleForDocument(pDocument->GetTitle());
else
{
LPCTSTR lpstrTitle = NULL;
CString strTitle; if (pActiveChild != NULL)
{
strTitle = pActiveChild->GetTitle();
if (!strTitle.IsEmpty())
lpstrTitle = strTitle;
}
UpdateFrameTitleForDocument(lpstrTitle);
}
}
void CFrameWnd::OnUpdateFrameTitle(BOOL bAddToTitle)
{
if ((GetStyle() & FWS_ADDTOTITLE) == 0)
return; // leave it alone!#ifndef _AFX_NO_OLE_SUPPORT
// allow hook to set the title (used for OLE support)
if (m_pNotifyHook != NULL && m_pNotifyHook->OnUpdateFrameTitle())
return;
#endif CDocument* pDocument = GetActiveDocument();
if (bAddToTitle && pDocument != NULL)
UpdateFrameTitleForDocument(pDocument->GetTitle());
else
UpdateFrameTitleForDocument(NULL);
}
跟到CMultiDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName,
BOOL bMakeVisible)
进去后,如果lpszPathName == NULL,那么进入新建文档执行块,这时进入SetDefaultTitle(pDocument),即设置当前文档的默认标题,好让我们看一下怎么设置标题,继续跟,进入GetDocString函数,这个函数就是得到默认文件名了,默认文件名就是String Table中的类似IDR_MAINFRAME的第一个值,再往后面看到没有pDocument->SetTitle(strDocName);太简单了吧!只要打开文档后,我们重新调用文档的SetTitle函数就改变了当前文档所在子框架和主框架的title了,如果想单独修改文档所在子框架的title或主框架mainframe的title,那就得到框架指针调用SetWindowText好了。讲了这么多,不知道对不对,欢迎大家与我交流。