MFC MDI选项卡控件标题更改
我创建了没有文档/视图体系结构的应用程序.原因是它不是基于文件的,它主要与数据库有关.大多数情况下,我用于报告.在进一步探讨这个问题之前,我确实在google中寻找解决方案.没有足够的帮助.
当我这样做的时候:
当用户打开报告窗口时,它的顶部有一个基本标题.在用户选择一个客户并请求显示数据后,一堆语句改变了标签栏的标题.到目前为止,这很好.这行得通.代码如下:
I have created my Application without Document/View Architecture. Reason is its not file based, its mostly related with database. Mostly I am using for Reporting. And before I go any further with the question, I did look for the solution in google. Not enough help.
When I did:
when user open a report window it has a basic caption at the top. After user select a Customer and request to display the data, a bunch of statement do the change of the caption of the tab bar. So far this is good. It work. Code is as below:
CWnd *pr=this->GetParent();
pr->SetWindowTextW(ch);
我面临的问题是:
1.当我最小化代码时,标题已更改为初始标题.
2.当我在新标签页中打开一个新窗口时,上一个窗口会立即丢失标题.
一直保持下去的正确方法是什么?
在此先感谢
The problem i am facing is :
1. When I minimize the code Caption got changed to the initial caption.
2. When I open a new window in new tab the previous window lost the caption immediately.
What can be the proper way to keep it all the time?
Thanks in advance
此解决方案仅在您的报表窗口从CFrameWnd派生时适用.CFrameWnd
和CDocument
类的基本窗口标题存储在成员变量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 ofCFrameWnd
andCDocument
classes is stored in the member variablem_strTitle
which can be set and retrieved with the virtual functionsSetTitle()
andGetTitle()
. So you should useSetTitle()
to change the title or overwrite the function. Note that this will only change the member variable. You must still callSetWindowText()
. The member variable is initialized byCreate()
with the window name passed toCreate()
.
If not usingSetTitle()
, 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 styleFWS_ADDTOTITLE
. When this style is set, the title is updated each time when an internal idle flag is set. To remove the flag, overwritePreCreateWindow()
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);
}