VS 2008 MFC Feature Pack - How do I

2019-09-16 18:33发布

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?

2条回答
小情绪 Triste *
2楼-- · 2019-09-16 19:16

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
查看更多
劫难
3楼-- · 2019-09-16 19:33

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.

查看更多
登录 后发表回答