如何更改 CDockablePane 标题

发布于 2024-08-22 03:07:41 字数 368 浏览 8 评论 0原文

如何强制刷新 MFC 功能包中 CDockablePane 的标题?我正在使用选项卡式 Visual Studio 样式示例,并且我想更改选项卡的标题。

不过,这些似乎缓存在某个地方,因为当我更改默认值时,它使用应用程序在上次运行时使用的内容。我在注册表中找不到与此相关的任何内容。

我正在修改字符串表 IDS_FILE_VIEW 和 IDS_CLASS_VIEW 以设置新的标题。我已进入 CDockablePane::CreateEx 方法,并且 lpszCaption 参数确实包含新标题,但旧标题仍在使用。

在隐藏并再次显示窗格之前,新的标题似乎不会加载。这应该是一个提示,但我无法弄清楚。

为什么它不直接使用我传递给 CreateEx 的标题???

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???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

静待花开 2024-08-29 03:07:41

简而言之,这是 MFC 功能包中的一个错误——实际上是 BCG 软件库中的错误。错误在于您无法动态更改这些标题。他们的答案是“你为什么要这么做?”

可停靠窗格中选项卡式窗格的标题存储在注册表中。如果注册表中已存在字幕,则不会使用创建时使用的字幕。

因此,第一次运行应用程序时,它将使用字符串表中的标题。之后,它使用注册表中的标题。

使用应用程序向导创建的设置,注册表设置位于:

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

存储在该注册表项中的值基本上是一个二进制文件,在启动时由对接管理器序列化到窗格中。内容未记录,但您可以在 afxdockablepane.cpp 中查看代码的作用。

我希望这可以帮助遇到此问题的其他人。

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.

甲如呢乙后呢 2024-08-29 03:07:41

嗯,我误解了,但我只是在 CDockablePane 的实例上调用“SetWindowText”。
它的标题更改为我传递给“SetWindowText”的内容...

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

迟到的我 2024-08-29 03:07:41

我遇到了类似的问题,在第一次关闭应用程序后,两个窗格具有相同的名称。我删除了注册表项,第一次启动时一切正常,第二次我再次遇到相同的错误。
SetWindowText("我的窗格");在窗格的重写 OnSize 中完成了肮脏的工作。它不是设置窗口标题的最佳位置,但正如 Colerman 上面所说,SetWindowsText 并不总是按其应有的方式工作。

无论如何,当应用程序启动时,窗格定位过程总是在窗格创建完成后调用 OnSize ,所以对我来说,这个肮脏的黑客做到了这一点。

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.

熟人话多 2024-08-29 03:07:41

窗口的名称在 LoadState() 时序列化。删除与应用程序中窗口位置相关的所有注册表信息。就我而言,它位于 HKCU\Software\My App Name。

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.

溇涏 2024-08-29 03:07:41

我遇到了同样的问题,但由于我不喜欢这里提供的任何解决方案,我进一步发现您可以通过引用 CDockingManager 并调用它来轻松禁用从注册表加载状态`s 方法 DisableRestoreDockState

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

淤浪 2024-08-29 03:07:41

由于选项卡的文本存储在注册表内,并且执行此操作的代码非常隐藏且未记录,因此我发现了一种令人讨厌的方法来执行您想要的操作。

将 .rc 文件中的字符串表更改为您想要的内容,例如,我在此处将 ClassView 更改为 LayerView:

STRINGTABLE
BEGIN
    IDS_CLASS_VIEW          "Layer View"
    ...
END

在您的大型机类中添加此调用:

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

这将存储意味着当您关闭打开您的应用程序,存储在注册表中的名称将是您放入 .rc 文件中的名称。

现在您可以注释掉对DisableRestoreDockState 的调用,因为正确的调用存储在注册表中。用户计算机上的新安装也可以正常工作。

我没有在最终版本中保留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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文