Question

I have a MFC application compiled with MBCS. We are also using the CMFCMenuBar from the MFC Feature Pack to display our menu.

I am trying to add unicode characters to my menu using the following code (from this question)

MENUITEMINFOW mi;
mi.cbSize = sizeof(MENUITEMINFOW);
mi.fMask = MIIM_ID | MIIM_TYPE;
mi.fType = MFT_STRING;
mi.wID = 34503; 
WCHAR text[128];
wcscpy_s(text,L"\u573F");
mi.dwTypeData = text;
InsertMenuItemW(hMenu,1,true,&mi);

The runs fine and the return code of InsertMenuItemW is 1, but I get a question mark in my menu instead of 圿

Why am I getting the question mark?

I am running Windows7 Ultimate

Was it helpful?

Solution

Your program is creating MBCS windows, not Unicode windows. Because it uses CreateWindowExA() instead of CreateWindowExW(). Verify this with Spy++. Use its finder tool to pick a window in your program, look at its properties. A window has "(Unicode)" marked for the Window Proc if it was created with CreateWindowExW().

Time to move to Unicode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top