且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MFC MDI选项卡控件标题更改

更新时间:2022-06-24 14:52:00

此解决方案仅在您的报表窗口从CFrameWnd派生时适用.

CFrameWndCDocument类的基本窗口标题存储在成员变量m_strTitle中,该成员变量可以使用虚函数SetTitle()GetTitle()进行设置和检索.因此,您应该使用SetTitle()更改标题或覆盖函数.请注意,这只会更改成员变量.您仍然必须呼叫SetWindowText().成员变量由Create()初始化,并将窗口名称传递给Create().

如果不使用SetTitle(),则屏幕上的标题将使用m_ strTitle文本进行更新.

必须注意的另一点是自动创建框架窗口.由文档模板创建的CFrameWnd窗口具有隐式样式FWS_ADDTOTITLE.设置此样式后,每次在设置内部空闲标志时都会更新标题.要删除该标志,请覆盖框架窗口类的PreCreateWindow():
This solution applies only when your report windows are derived from CFrameWnd.

The basic window title of CFrameWnd and CDocument classes is stored in the member variable m_strTitle which can be set and retrieved with the virtual functions SetTitle() and GetTitle(). So you should use SetTitle() to change the title or overwrite the function. Note that this will only change the member variable. You must still call SetWindowText(). The member variable is initialized by Create() with the window name passed to Create().

If not using SetTitle(), the on screen title will be updated using the m_strTitle text.

Another point that must be observed is the automatic creation of frame windows. CFrameWnd windows created by document templates have the implicit style FWS_ADDTOTITLE. When this style is set, the title is updated each time when an internal idle flag is set. To remove the flag, overwrite PreCreateWindow() of your frame window class:
BOOL CMyFrame::PreCreateWindow(CREATESTRUCT& cs)
{
    // Style FWS_ADDTOTITLE is always set when creating a frame window.
    // See CDocTemplate::CreateNewFrame() in doctmpl.cpp
    cs.style &= ~FWS_ADDTOTITLE;
    // Change CFrameWnd to the base class if necessary
    return CFrameWnd::PreCreateWindow(cs);
}