Miles Davies
2013-08-19 08:42:09 UTC
I am maintaining a large legacy application build using MBCS. On a system with Japanese as the system locale I have an issue where the selection position of an edit control is being returned incorrectly.
[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<
[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<