如何重命名 MFC 功能区面板?

发布于 2024-10-18 23:40:04 字数 125 浏览 5 评论 0原文

我正在编写一个多语言应用程序,它支持从一种语言动态切换到另一种语言。由于CMFCRibbonPanel类中有一个GetName函数,我认为还应该有一个SetName函数。但不幸的是我找不到想要的功能。如何动态重命名功能区面板?非常感谢。

I am programming a multi-language application which supports dynamical switch from one language to another. Since there is a GetName function in class CMFCRibbonPanel, I think there should also be a SetName function. But unfortunately I can't find the desired function. How do I rename a ribbon panel dynamically? Thank you very much.

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

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

发布评论

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

评论(5

我的鱼塘能养鲲 2024-10-25 23:40:05

您可能需要删除并重新添加它。这就是其他一些 MFC 功能区函数的工作原理。

You'll probably have to remove and re-add it. That's how some other MFC ribbon functions work.

〆一缕阳光ご 2024-10-25 23:40:05

结合 https://stackoverflow.com/a/5120994/6648895https://stackoverflow.com/a/25180098/6648895
在 VS 2013 中最终对我有用的是:

MyRibbonPanel* m_ribbonPanel;
m_ribbonPanel = static_cast<MyRibbonPanel*>(m_wndRibbonBar.GetCategory(1)->GetPanel(1));
CString s(_T("sdcasdc"));
m_ribbonPanel->SetName(s);

Combining https://stackoverflow.com/a/5120994/6648895 and https://stackoverflow.com/a/25180098/6648895
is what finally worked for me in VS 2013:

MyRibbonPanel* m_ribbonPanel;
m_ribbonPanel = static_cast<MyRibbonPanel*>(m_wndRibbonBar.GetCategory(1)->GetPanel(1));
CString s(_T("sdcasdc"));
m_ribbonPanel->SetName(s);
你的心境我的脸 2024-10-25 23:40:04

面板名称受到保护。

您可以从 CMFCRibbon 派生您自己的类并添加“SetName”方法。

class MyRibbonPanel : public CMFCRibbonPanel
{
public:
    MyRibbonPanel(LPCTSTR lpszName = NULL, HICON hIcon = NULL ) : CMFCRibbonPanel(lpszName, hIcon) {};
    void SetName(CString& name ) { m_strName = name; };
};

例如(在 VS2010 中创建虚拟 SDI 应用程序后)

CMFCRibbonCategory* pCategory = m_wndRibbonBar.AddCategory(_T("&Legume"),
    IDR_PROPERTIES,
    IDB_PROPERTIES_HC );


MyRibbonPanel* pMyPanel = (MyRibbonPanel*)pCategory->AddPanel(_T("Patate"), m_PanelImages.ExtractIcon(1));
pMyPanel->SetKeys(_T("zc"));
pMyPanel->SetCenterColumnVert();
pMyPanel->SetJustifyColumns();

CString s(_T("sdcasdc"));
pMyPanel->SetName(s);

the panel name is protected.

you can derive your own class from CMFCRibbon and add a "SetName" method.

class MyRibbonPanel : public CMFCRibbonPanel
{
public:
    MyRibbonPanel(LPCTSTR lpszName = NULL, HICON hIcon = NULL ) : CMFCRibbonPanel(lpszName, hIcon) {};
    void SetName(CString& name ) { m_strName = name; };
};

for example ( after creating a dummy SDI application in VS2010 )

CMFCRibbonCategory* pCategory = m_wndRibbonBar.AddCategory(_T("&Legume"),
    IDR_PROPERTIES,
    IDB_PROPERTIES_HC );


MyRibbonPanel* pMyPanel = (MyRibbonPanel*)pCategory->AddPanel(_T("Patate"), m_PanelImages.ExtractIcon(1));
pMyPanel->SetKeys(_T("zc"));
pMyPanel->SetCenterColumnVert();
pMyPanel->SetJustifyColumns();

CString s(_T("sdcasdc"));
pMyPanel->SetName(s);
情深缘浅 2024-10-25 23:40:04

如果您通过 VS 功能区 UI 创建了功能区并且不想手动创建它们,那么它也可能对其他人有用。

从之前的答案开始工作。

由于面板没有 ID,因此您也无法选择它们来创建指针。但是,如果面板包含带有 ID 的元素,您可以使用它们创建指向面板的指针,然后重命名,而不必手动创建它。

例如,我的面板上有一个组合 ID_TEST_COMBO

CMFCRibbonComboBox* m_RibbonTestCombo;
MyRibbonPanel*      m_ribbonPanel;
m_RibbonTestCombo= DYNAMIC_DOWNCAST(CMFCRibbonComboBox,m_wndRibbonBar.FindByID(ID_TEST_COMBO));
m_ribbonPanel = DYNAMIC_DOWNCAST(MyRibbonPanel, m_RibbonSSSRules->GetParentPanel());
CString s(_T("sdcasdc"));
m_ribbonPanel->SetName(s);

这允许您更改文本,而无需手动创建面板

It might also be useful to others if you have created your ribbons via the VS ribbon UI and don't want to have to manually create them.

Working on from the previous answer.

As panels don't have id's you can't select them to create a pointer too. But if the panels contain elements with ID's you can use these to create a pointer to the panel then rename instead of having to manually create it.

For example I have a combo on my panel, ID_TEST_COMBO

CMFCRibbonComboBox* m_RibbonTestCombo;
MyRibbonPanel*      m_ribbonPanel;
m_RibbonTestCombo= DYNAMIC_DOWNCAST(CMFCRibbonComboBox,m_wndRibbonBar.FindByID(ID_TEST_COMBO));
m_ribbonPanel = DYNAMIC_DOWNCAST(MyRibbonPanel, m_RibbonSSSRules->GetParentPanel());
CString s(_T("sdcasdc"));
m_ribbonPanel->SetName(s);

This allows you to change the text without having to manually create the panel

自控 2024-10-25 23:40:04

您可以尝试SetWindowText函数。
您也可以覆盖文本的绘制并在其中添加您自己的文本。

希望这有帮助。

You can try SetWindowText function.
Also you could override the drawing of the text and add you own text there.

Hope this helps.

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