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.
How do I rename the MFC ribbon panel?
1.6k views Asked by zhangjz AtThere are 5 answers
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);
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
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);
You can try SetWindowText function. Also you could override the drawing of the text and add you own text there.
Hope this helps.