WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit d27dce5

Browse files
ulhcocornut
authored andcommitted
Backends: Win32: handle WM_IME_CHAR/WM_IME_COMPOSITION messages to support Unicode inputs on MBCS Windows. (#9099, #3653, #5961)
1 parent 87b1933 commit d27dce5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

backends/imgui_impl_win32.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
// CHANGELOG
2323
// (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)
2425
// 2025-10-19: Inputs: Revert previous change to allow for io.ClearInputKeys() on focus-out not losing gamepad state.
2526
// 2025-09-23: Inputs: Minor optimization not submitting gamepad input if packet number has not changed.
2627
// 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
788789
io.AddInputCharacter(wch);
789790
}
790791
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;
791810
case WM_SETCURSOR:
792811
// This is required to restore cursor when transitioning from e.g resize borders to client area.
793812
if (LOWORD(lParam) == HTCLIENT && ImGui_ImplWin32_UpdateMouseCursor(io, bd->LastMouseCursor))

docs/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Other Changes:
7777
selects `VkSwapchainCreateInfoKHR`'s `compositeAlpha` value based on
7878
`cap.supportedCompositeAlpha`, which seems to be required on some Android
7979
devices. (#8784) [@FelixStach]
80+
- Win32: handle WM_IME_CHAR/WM_IME_COMPOSITION to support Unicode inputs on
81+
MBCS (non-Unicode) Windows. (#9099, #3653, #5961) [@ulhc, @ocornut, @Othereum]
8082
- Examples:
8183
- Win32+DirectX12: ignore seemingly incorrect D3D12_MESSAGE_ID_FENCE_ZERO_WAIT
8284
warning on startups on some setups. (#9084, #9093) [@RT2Code, @LeoGautheron]

0 commit comments

Comments
 (0)