How to change the CDockablePane caption
Asked Answered
F

6

8

How do I force a refresh the caption of a CDockablePane in the MFC feature pack? I'm working with the tabbed visual studio style example, and I want to change the captions for the tabs.

These seem to be cached somewhere though, as when I change from the defaults, it uses what the app used on it's previous run. I can find nothing in the registry pertaining to this.

I'm modifying the string table IDS_FILE_VIEW and IDS_CLASS_VIEW to set the new captions. I've stepped to the CDockablePane::CreateEx method and the lpszCaption parameter does contain the new caption, but the old caption is still being used.

The new captions don't seem to load until the pane is hidden and shown again. That should be a hint, but I can't figure it out.

Why won't it just use what I pass as the caption to CreateEx???

Foldboat answered 22/2, 2010 at 17:43 Comment(0)
F
7

In a nutshell, this is a bug in the MFC feature pack -- actually in the BCG Software library. The bug is that you cannot change these captions dynamically. Their answer is "why would you want to do that?"

The captions for tabbed panes in the dockable pane are stored in the registry. The captions used at creation are NOT used if the captions exist in the registry already.

So, the first time you run your application, it will use the captions from the string table. After that, it uses the captions from the registry.

Using the settings created by the AppWizard, the registry settings are at:

HKEY_CURRENT_USER\Software\Local AppWizard-Generated Applications\MyApp\Workspace\DockingManager-128\DockingPaneAndPaneDividers

The value stored in this key is basically a binary file that gets serialized into the panes at start up by the docking manager. The contents aren't documented but you can see what the code is doing in afxdockablepane.cpp.

I hope this helps someone else who comes across this issue.

Foldboat answered 23/2, 2010 at 21:58 Comment(5)
Great response thx. My answer to 'why would you want to do that?'...hmmm...internationalization (sorry BCG...English is not spoken everywhere). Ridiculous.Gloriole
Wow this is so absolutely ridiculous. I was looking for the reason our panes where incorrectly translated for about an hour until I stumbled upon this answer. Thank you very much.Juanjuana
Thanks for this tip. After changing the string resource and not getting a change in the tab title, I kept wondering if I had the correct string. Oddly, the hint that comes up when the mouse is placed over the tab DOES use the new string!Reinstate
In the event of hot-switching the lang of the interface. This kind of keys storing captions of the previous lang, are stored forever? Is there a good practice, a good time, a good OnEvent() to purge them?Offstage
Another solution: call GetParent()->SetWindowText from the CView (aka CWnd), child of CPane.Offstage
K
2

Hmmm, baybe I misunderstood, but I just call 'SetWindowText' on an instance of CDockablePane. Caption of it changes to what I pass to 'SetWindowText'...

Kibosh answered 9/3, 2010 at 13:17 Comment(1)
Yes, SetWindowText works, but not really as expected. You have to call SetWindowText sometime after Create is called, and it can't be the next call after Create. For instance, the VS example has a function called CreateDockingWindows. Adding a call to SetWindowText in that function (after the appropriate Create) doesn't work. The point of my original post was that the Create function takes a caption parameter that is completely ignored.Foldboat
W
1

I had similar problem that after first close of application two panes got same name. I deleted the registry keys, on first start everything was OK, on second I got again the same bug. SetWindowText("MyPane"); in overriden OnSize of pane did the dirty work. It is not the best place for setting the windows caption, but as Colerman stated above SetWindowsText is not working always as it should.

Anyway, when application is started, pane positing process always call OnSize after creation of pane is finished, so for me this dirty hack did the trick.

Windswept answered 11/12, 2013 at 22:14 Comment(0)
W
0

The name of the window is serialized at LoadState() time. Delete all the registry information related to window positions in your app. In my case it was at HKCU\Software\My App Name.

Willey answered 19/11, 2010 at 0:12 Comment(0)
W
0

I encountered the same problem, but as I don`t like any of solutions offered here I went further and found that you can easily disable loading of the state from the registry by refering to the CDockingManager and invoking it`s method DisableRestoreDockState

Woodchuck answered 6/6, 2013 at 15:23 Comment(0)
D
0

Since the text for the tab is stored inside the registry, and the code for doing that is pretty well hidden and undocumented I've found a nasty way of doing what you want.

Change the string table in your .rc file to what you want, for example I changed ClassView to LayerView here:

STRINGTABLE
BEGIN
    IDS_CLASS_VIEW          "Layer View"
    ...
END

In your mainframe class add this call:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1)
        return -1;

    BOOL bNameValid;

    // set the visual manager and style based on persisted value
    OnApplicationLook(theApp.m_nAppLook);

    GetDockingManager()->DisableRestoreDockState(TRUE); // <-- THIS CALL

This will store mean that when you close then open your app the name stored in the registry will be the one you put inside the .rc file.

Now you can comment out that call to DisableRestoreDockState because the correct one is stored in the registry. New installs in your user's computers will work as well.

I do not keep DisableRestoreDockState in the final release because I want the other settings to be restored.

HTH

Disconnect answered 9/12, 2013 at 6:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.