Discussion:
EM_GETSEL returning character position rather than byte position in MBCS build with Japanese text
(too old to reply)
Miles Davies
2013-08-19 08:42:09 UTC
Permalink
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<
Miles Davies
2013-08-21 10:36:30 UTC
Permalink
Post by Miles Davies
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.
[snip]

After a lengthy investigation it turns out the issue is due to the use of Rogue Wave's Objective Grid. If I remove "#include <gxall.h>" all is well.
Loading...