开发者

Russian characters not showing up correctly in MFC unicode list box

I have an MFC application compiled with MBCS set.

I have created a unicode list box on a regular MBCS dialog using the following code:

DWORD dwStyle = WS_CHILD|WS_VISIBLE|WS_VSCROLL;
hLangListBox =  CreateWindowExW(WS_EX_CLIENTEDGE, //extended styles
              _T(L"listbox"),                //control 'class' name
              L"Language",              //control caption
              dwStyle,                      //control style 
              10,                      //position: left
              10,                       //position: top
              200,                     //width
              100,                    //height
              GetSafeHwnd(),         //parent window handle
              //control's ID
              reinterpret_cast<HMENU>(static_cast<INT_PTR>(ID_LANGUAGE_ENGLISH+20)),
              AfxGetInstanceHandle(),                        //application instance
              0);    

When I inspect this dialog using Spy++ I see my Window Proc: has (Unicode) so I believe it is being created correctly.

I am populating the listbox with one of the following commands depending on if I have the data in a unicode string or a regular string

CStringW m_LanguageNames[MAX_LANG];

CString sFilename;

....

::SendMessageW(hLangListBox,LB_INSERTSTRING ,nMenuPos,reinterpret_cast<LPARAM>(theApp.m_LanguageNames[i].GetBuffer()));

::SendMessage(hLangListBox,LB_INSERTSTRING ,nMenuPos,reinterpret_cast<LPARAM>(sFileName.GetBuffer()));

Things look ok for most entries,

I can see

Chinese: 中开发者_StackOverflow文(简体)

French: Française

Japanese: 日本

but Russian looks like a P followed by a bunch of bars (P||||||), not Pусский. When I look at the contents of the CStringW in Visual Studio I do see the correct text.

Why can I see the other languages correctly and not russian? I am running on Windows 7 ultimate and compiling with Visual Studio 10

Edit

If I change my system locale to Russian I can see the russian characters fine. However, the ç in Française does not appear correct.

I thought unicode strings were independent of the system locale. Is that correct?

To populate my unicode CStringW I am doing:

CA2W tmp_wide(po.msgstr,CodePage);
m_LanguageNames[i] = tmp_wide;

where po.msgstr is a CString that was read in from a file. In this case, CodePage is set to 1251

If I inspect the variables in Visual Studio it appears that the conversion is happening correctly.

It appears that my unicode list box can display unicode characters from a MBCS such as Chinese fine, but that it can't display unicode characters from a SBCS that is different from my current code page.


Same problem, solved after a long time. In my case the default font of dialog is set to "MS Sans Serif", just change to use the more recent font "Microsoft Sans Serif" and everything is resolved!


I have not solved this yet, but I think it is likely this is a font issue. I'm not going any farther with this, but the next step would be to have an owner drawn list box and specify an appropriate font for each language

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜