VS 2008 MFC Feature Pack - How do I

落爺英雄遲暮 提交于 2019-12-25 00:26:11

问题


I have an application I'm writing using the MFC Feature pack. It uses Document/View. Since these classes are derived from "normal" MFC classes, these questions may not be Feature Pack specific.

When a change is made, I add an asterisk * to the name on the tab, and the word (modified) to the main window title using the following code:

tabval = "Report_" + pDoc->rptData.reportId.Strip();
winval = tabval;
if (changed) {
    tabval += " *";
    winval += " (modified)";
}
frame->SetTitle(tabval);
frame->SetWindowText(tabval);
name = mainFrame->GetTitle();
mainFrame->SetWindowText(name + " - " + winval);

But when changing between tabs, the original text comes back. First question: how do I make the change sticky?

Second question: there's a tree view on the left and a properties window on the right. Switching between them (un)highlights the title bars to show which one is active. The user can also activate and interact with the document window, but there doesn't seem to be any way to give visual feedback that the document window is, in fact, active. How can I do that?


回答1:


It's not clear what types your variables are, but as you have pDoc and frame, I'm assuming that the former is your CDocument derived class and the latter is possibly a CFrameWnd or CMDIFrameWnd derived class.

If I'm not far wrong, then the reason why the tab titles aren't sticking is that you should be calling SetTitle on the CDocument that's behind each tabbed view, so something like

tabval = "Report_" + pDoc->rptData.reportId.Strip();
winval = tabval;
if (changed) {
    tabval += " *";
    winval += " (modified)";
}
pDoc->SetTitle(tabval);    // set tab title on CDocument



回答2:


I had a similar problem in the past. The cause of main window's title text changing back is the function CFrameWndEx::OnUpdateFrameTitle. As it is virtual, you can override it on your own derived class to have the behaviour you want. It is a solution that worked for me.



来源:https://stackoverflow.com/questions/16379047/vs-2008-mfc-feature-pack-how-do-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!