I have a MFC application compiled with the MBCS character set. I have a submenu off of my main menu that I would like to add unicode characters to. Can that be done?
1 Answers
You can force the use of Unicode strings even in MBCS apps by explicitely calling the Unicode form of an API and passing it a Unicode string.
In your case, ModifyMenuW() is the API that sets the menu item text (assuming the menu item already exists):
ModifyMenuW(GetMenu()->m_hMenu,ID_APP_ABOUT, MF_BYCOMMAND , 0, L"\u573F");
This code displays a Chinese ideogram (I have no idea of its meaning) instead of the original text
The L
in front of the string says it's a Unicode string. \u573F
is the way you encode a Unicode char in your C++ ASCII source file. The W
at the end of the API name: It stands for Wide and denotes the Unicode form of the API.
Note that if your goal is to translate the full UI of your app, this is a complete other story: The method I showed here is only suitable for one-shot calls. You can't create a full UI that way.
You can translate your MBCS app to Japanese, Russian, whatever,... without switching to Unicode (Although it would be a very good idea to do that switch. But that can be costly for legacy apps).
You have 2 friends to help you out there: appTranslator lets you very easily translate your app (and manage your translations (Disclaimer: This is my own ad ;-) and Microsoft AppLocale helps you test MBCS apps in different codepages without actually changing the codepage of your computer (which requires a reboot).

- 21,494
- 13
- 69
- 110
-
InsertMenuW(m_hMenu,i,MF_BYPOSITION,j,L"\u573F") just gives me a ? in my menu. Am I missing something? – JonDrnek Aug 05 '11 at 20:40
-
Which OS? If XP: Do you have support (iow fonts) for East Asian Languages installed? – Serge Wautier Aug 05 '11 at 21:35
-
WIndows 7 Ultimate. I have the chinese code page installed though it is not active. – JonDrnek Aug 06 '11 at 02:33
-
Weird :-( 1st: With Vista+, East Asian fonts are installed by default. I added this line at the end of my CMainFrame::OnCreated() and it works fine: InsertMenuW(GetMenu()->m_hMenu,0,MF_BYPOSITION,10000,L"\u573F") ; – Serge Wautier Aug 06 '11 at 10:34
-
This will work UNLESS you are using the MFCFeaturePack and are using a CMFCMenuBar. The CMFCMenuBar stores the menu text internally in a CString which breaks this approach – JonDrnek Sep 02 '11 at 14:52