Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top