From 80b6e513ba9428f4acbacfe32852db1e7f4d80c9 Mon Sep 17 00:00:00 2001 From: ulhc <350246356@qq.com> Date: Wed, 3 Dec 2025 19:00:27 +0800 Subject: [PATCH] Handle WM_IME_COMPOSITION for MBCS support Add handling for WM_IME_COMPOSITION to ensure correct WM_IME_CHAR values in MBCS apps. --- backends/imgui_impl_win32.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backends/imgui_impl_win32.cpp b/backends/imgui_impl_win32.cpp index e7d93554d..9cce66b48 100644 --- a/backends/imgui_impl_win32.cpp +++ b/backends/imgui_impl_win32.cpp @@ -879,15 +879,19 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandlerEx(HWND hwnd, UINT msg, WPA case WM_INPUTLANGCHANGE: ImGui_ImplWin32_UpdateKeyboardCodePage(io); return 0; + 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) + LRESULT result = ::DefWindowProc(hwnd, msg, wParam, lParam); + return (lParam & GCS_RESULTSTR) ? 1 : result; + } 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); io.AddInputCharacterUTF16(wch);