Thank you for posting the result of your investigation, this was useful!
I'm coming from https://github.com/ocornut/imgui/pull/9099 (I am maintainer of that software) and things have been rather confusing but your latest comment helped connect some pieces of the puzzle.
I'd be ideally trying to solve this, aka allow MBCS-compiled apps using RegisterClassA(), DefWindowProcA() etc to work on all setups. I've been hoping I can avoid calling ImmGetCompositionString() (suggested by https://github.com/ocornut/imgui/pull/3653/files and implied by WM_IME_COMPOSITION ) in order to avoid requiring user to link my library with imm32.
So I am looking at:
\> To let your program work regardless of how the “language for non-Unicode programs” is set, you should handle WM_IME_COMPOSITION message properly. The simplest way to handle the message is to pass it to the DefWindowProcW() function.
However if i do this:
case WM_IME_COMPOSITION:
{
// Handling WM_IME_COMPOSITION ensure that WM_IME_CHAR value is correct even for MBCS apps.
// (see #9099, #3653 and https://stackoverflow.com/questions/77450354 topics)
IMGUI_DEBUG_LOG("WM_IME_COMPOSITION wParam %08X, lParam %08X\n", wParam, lParam);
return ::DefWindowProcW(hwnd, msg, wParam, lParam);
}
case WM_IME_CHAR:
if (::IsWindowUnicode(hwnd) == FALSE)
{
unsigned short ch = (unsigned short)wParam;
if (::IsDBCSLeadByte(HIBYTE(wParam)))
ch = MAKEWORD(HIBYTE(wParam), LOBYTE(wParam));
wchar_t wch = 0;
::MultiByteToWideChar(bd->KeyboardCodePage, MB_PRECOMPOSED, (char*)&ch, sizeof(ch), &wch, 1);
IMGUI_DEBUG_LOG("WM_IME_CHAR %08X -> %08X -> %08X\n", wParam, ch, wch);
io.AddInputCharacterUTF16(wch);
return 1;
}
return 0;
Then I get the correct char in WM_IME_CHAR, followed by a ? :
[07650] WM_IME_COMPOSITION wParam 00008882, lParam 000001B9
[07681] WM_IME_COMPOSITION wParam 0000D982, lParam 000001B9
[07686] WM_IME_COMPOSITION wParam 0000D982, lParam 000001B9
[07696] WM_IME_COMPOSITION wParam 0000D982, lParam 000001B9
[07707] WM_IME_COMPOSITION wParam 00007B96, lParam 000001B9
[07769] WM_IME_COMPOSITION wParam 00007B96, lParam 00001E00
[07769] WM_IME_CHAR 00007B96 -> 00007B96 -> 0000672C
[07769] WM_IME_CHAR 0000003F -> 0000003F -> 0000003F
[07770] [io] Processed: Text: '本' (U+0000672C)
[07770] [io] Processed: Text: '?' (U+0000003F)
[07858] [io] Processed: MouseButton 0 Down (Mouse)
[07865] [io] Processed: MouseButton 0 Up (Mouse)
If I change WM_IME_COMPOSITION handle to always return 1 or to always return 1 when (lParam & GCS_RESULTSTR) then I get the correct WM_IME_CHAR only.
I am curious if you have an idea about this? Thank you greatly!