开发者

How to change the CDockablePane caption

开发者 https://www.devze.com 2022-12-20 18:30 出处:网络
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.

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 show开发者_运维百科n 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???


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.


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


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.


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消