最近在工作中,遇到了需要将软件从中文转成英文的问题。通常来说,MFC界面上的控件均可以用SetWindowText来解决。但对于Ribbon,往往不怎么好使。也是从网上找了很多资料,最终总结如下。
先上效果图
中文版:
英文版:
如图中,我的界面包括了Ribbon界面中的三种控件,Panel,Button,Category。
当需要从代码去修改时,代码如下
//对于Category界面,修改方法为在MainFrm中的OnCreate生成界面的函数中,加入如下代码
CMFCRibbonCategory *pCategory = m_wndRibbonBar.GetCategory(1);
pCategory->SetName(_T("System"));
//对于Panel界面,修改方法如下,但要特别注意。Panel可能是设计时就没有考虑的问题,直接来说,是不能修改的,只能通过新建子类去进行强转
强转子类如下,新建MFC类,继续MFCRibbonPanel
.h文件为
#pragma once
#include "afxribbonpanel.h"
//继承RibbonPanel的子类
class MyRibbonPanel :public CMFCRibbonPanel
{
public:
MyRibbonPanel(void);
~MyRibbonPanel(void);
void SetPanelName(CString name);
};
.cpp文件为
#include "StdAfx.h"
#include "MyRibbonPanel.h"
MyRibbonPanel::MyRibbonPanel(void)
{
}
MyRibbonPanel::~MyRibbonPanel(void)
{
}
void MyRibbonPanel::SetPanelName(CString name)
{
//在这里进行名字转行赋值
m_strName=name;
}
然后,我们在MainFrm中,加载上述类然后,转换界面名字代码如下
CMFCRibbonPanel *pPanel1 = pCategory->GetPanel(0);
MyRibbonPanel* pMyPanel1 = (MyRibbonPanel*)pPanel1;//这里把父类的对象强制转换成子类对象,没有报错,说明可以转换
pMyPanel1->SetPanelName(_T("User Manage"));
CMFCRibbonPanel *pPanel2 = pCategory->GetPanel(1);
MyRibbonPanel* pMyPanel2 = (MyRibbonPanel*)pPanel2;//这里把父类的对象强制转换成子类对象,没有报错,说明可以转换
pMyPanel2->SetPanelName(_T("Motor Control Panel"));
CMFCRibbonPanel *pPanel3 = pCategory->GetPanel(2);
MyRibbonPanel* pMyPanel3 = (MyRibbonPanel*)pPanel3;//这里把父类的对象强制转换成子类对象,没有报错,说明可以转换
pMyPanel3->SetPanelName(_T("Robot Control Panel"));
CMFCRibbonPanel *pPanel4 = pCategory->GetPanel(3);
MyRibbonPanel* pMyPanel4 = (MyRibbonPanel*)pPanel4;//这里把父类的对象强制转换成子类对象,没有报错,说明可以转换
pMyPanel4->SetPanelName(_T("Equipment Info"));
//对于按钮,转换代码如下
CMFCRibbonButton* pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_LOGIN));
pRibbonBtn->SetText(_T("Login"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_LOGOFF));
pRibbonBtn->SetText(_T("Logout"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_MANAGER));
pRibbonBtn->SetText(_T("Edit"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_AXISMOTION));
pRibbonBtn->SetText(_T("Axis Control"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_IOTEST1));
pRibbonBtn->SetText(_T("IO CARD 1"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_IOTEST2));
pRibbonBtn->SetText(_T("IO CARD 2"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_IOTEST3));
pRibbonBtn->SetText(_T("IO CARD 3"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_IOTEST4));
pRibbonBtn->SetText(_T("IO CARD 4"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_IOTEST5));
pRibbonBtn->SetText(_T("IO CARD 5"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_IOTEST6));
pRibbonBtn->SetText(_T("IO CARD 6"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_IOTEST7));
pRibbonBtn->SetText(_T("IO CARD 7"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_IOTEST8));
pRibbonBtn->SetText(_T("IO CARD 8"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_VELOCITY));
pRibbonBtn->SetText(_T("Axis Speed Setting"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_ETHERNET_CL));
pRibbonBtn->SetText(_T("Ethernet Client"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_RECORD));
pRibbonBtn->SetText(_T("View Record"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_CALITRAY));
pRibbonBtn->SetText(_T("Tray Calib"));
pRibbonBtn = DYNAMIC_DOWNCAST(CMFCRibbonButton, m_wndRibbonBar.FindByID(ID_TOOLS_BTN_TRAYPOINTS));
pRibbonBtn->SetText(_T("Tray Points"));