Under what circumstances would an EDIT control treat MBCS as UNICODE?

115 Views Asked by At

I am maintaining a large legacy application build using MBCS.

On a Windows 7 system with Japanese as the system locale and English as the UI locale I have an issue where the selection position of an edit control is being returned incorrectly. I have tested on a Japanese installed XP and Windows 7 with the same result.

[codesnippet]

CEdit* pEdit = state->GetEdit() ; 

auto hWnd = pEdit->GetSafeHwnd() ; 
if ( hWnd ) 
{ 
    ::SendMessageA(hWnd, EM_GETSEL, (WPARAM)&nStart, (LPARAM)&nEnd) ;

    TCHAR buffer[128]; 
    ::SendMessageA(hWnd, WM_GETTEXT, (WPARAM)_countof(buffer), (LPARAM)&buffer); 

    _RPT4(_CRT_WARN, 
          "String '%s' selection [%d,%d], unicode? %s", 
          buffer, 
          nStart, 
          nEnd, 
         (::IsWindowUnicode(hWnd)) ? "True" : "False"); 

[/codesnippet] 

With the Carat at the end of the string this produces the output

String '未定義' selection [3,3], unicode? False

What on earth can be going on? I have built a little test application and that works as I would expect producing the output

String '未定義' selection [6,6], unicode? False

It is an MBCS build as sizeof(TCHAR) == 1, and I cannot switch to UNICODE as it is a legacy application.

0

There are 0 best solutions below