|
21 | 21 |
|
22 | 22 | // CHANGELOG |
23 | 23 | // (minor and older changes stripped away, please see git history for details) |
| 24 | +// 2025-12-03: Inputs: handle WM_IME_CHAR/WM_IME_COMPOSITION messages to support Unicode inputs on MBCS (non-Unicode) Windows. (#9099, #3653, #5961) |
24 | 25 | // 2025-10-19: Inputs: Revert previous change to allow for io.ClearInputKeys() on focus-out not losing gamepad state. |
25 | 26 | // 2025-09-23: Inputs: Minor optimization not submitting gamepad input if packet number has not changed. |
26 | 27 | // 2025-09-18: Call platform_io.ClearPlatformHandlers() on shutdown. |
@@ -788,6 +789,24 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandlerEx(HWND hwnd, UINT msg, WPA |
788 | 789 | io.AddInputCharacter(wch); |
789 | 790 | } |
790 | 791 | return 0; |
| 792 | + case WM_IME_COMPOSITION: |
| 793 | + { |
| 794 | + // Handling WM_IME_COMPOSITION ensure that WM_IME_CHAR value is correct even for MBCS apps. |
| 795 | + // (see #9099, #3653 and https://stackoverflow.com/questions/77450354 topics) |
| 796 | + LRESULT result = ::DefWindowProcW(hwnd, msg, wParam, lParam); |
| 797 | + return (lParam & GCS_RESULTSTR) ? 1 : result; |
| 798 | + } |
| 799 | + case WM_IME_CHAR: |
| 800 | + if (::IsWindowUnicode(hwnd) == FALSE) |
| 801 | + { |
| 802 | + if (::IsDBCSLeadByte(HIBYTE(wParam))) |
| 803 | + wParam = (WPARAM)MAKEWORD(HIBYTE(wParam), LOBYTE(wParam)); |
| 804 | + wchar_t wch = 0; |
| 805 | + ::MultiByteToWideChar(bd->KeyboardCodePage, MB_PRECOMPOSED, (char*)&wParam, 2, &wch, 1); |
| 806 | + io.AddInputCharacterUTF16(wch); |
| 807 | + return 1; |
| 808 | + } |
| 809 | + return 0; |
791 | 810 | case WM_SETCURSOR: |
792 | 811 | // This is required to restore cursor when transitioning from e.g resize borders to client area. |
793 | 812 | if (LOWORD(lParam) == HTCLIENT && ImGui_ImplWin32_UpdateMouseCursor(io, bd->LastMouseCursor)) |
|
0 commit comments