0

I use the DialogBox API to display a dialog at my application. In the WM_INITDIALOG message handling at the DLGPROC procedure call back, I could see the text string is correct Unicode at debugger and SetDlgItemText is used to set the text on Rich Edit control in the dialog. However when I tried to get the text from dialog by using GetDlgItemText API , it was all question marks for those characters.

My project is compiled as Unicode. And I also used the spy++ and it shows the Windows Proc is Unicode.

I am testing Chinese on Windows 7 with English Locale, so I also installed the Chinese Language Pack for my machine and it doesn't help either.

I could not explain what I see here. It would be appreciated if any one could shed some lights on this or how to debug further.

windfly2006
  • 1,703
  • 3
  • 25
  • 48
  • Unicode and TCHAR is a hell, can you try `GetFlgItemTextW` with `wchar_t` instead of `GetFlgItemText` and TCHAR? maybe some settings cause your program use ANSI version of the function and conversion from Unicode to ANSI was the source of your error – BigBoss Oct 17 '12 at 20:40
  • I figured out the reason, it is the RichEdit control problem which seems not using unicode by default. I would add more information on the answer. – windfly2006 Oct 17 '12 at 21:47

1 Answers1

0

It turns out that it is due to the RichEdit control there. If I just use a text box, the Chinese characters would be displayed correctly along with other English characters. So after doing some reading, particular this one, I gave some tries and I got it working. So basically I should not use SetDlgItemText, instead I should use the following code (where m_strDisplay is the text to display on rich edit):

::SendMessage(hWndText, EM_AUTOURLDETECT, TRUE, NULL);
SETTEXTEX TextInfo = {0};
TextInfo.flags = ST_DEFAULT|SF_UNICODE;
TextInfo.codepage = 1200;
SendMessage(hWndText, EM_SETTEXTEX, (WPARAM)&TextInfo, (LPARAM)(LPCTSTR)m_strDisplay);

to set the text on RichEdit control.

Community
  • 1
  • 1
windfly2006
  • 1,703
  • 3
  • 25
  • 48