Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure WM_CHAR functions properly when _UNICODE is defined. #260

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion wingui/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,28 @@ static LRESULT ALIGN_STACK CALLBACK WndProc (const HWND hwnd,
exit( 0);
if( wParam != 9 || !(GetKeyState( VK_SHIFT) & 0x8000))
if( !key_already_handled)
add_key_to_queue( (int)wParam );
#if _UNICODE
/* if we are building against the unicode runtime, key messages
received by WM_CHAR will be UTF16 encoded; convert it to a
sequence UTF8 bytes and inject them one at a time.
see: https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-char */
wchar_t utf16[3]; /* may be a surrogate pair */
utf16[0] = LOWORD(wParam);
utf16[1] = HIWORD(wParam);
utf16[2] = 0;
unsigned char utf8[4 + 4 + 1];
int size = WideCharToMultiByte(CP_UTF8, 0, utf16, -1, 0, 0, 0, 0);
if (size > 0 && sizeof(utf8)) {
utf8[0] = 0;
WideCharToMultiByte(CP_UTF8, 0, utf16, -1, utf8, size, 0, 0);
for (int i = 0; i < size - 1; i++) {
add_key_to_queue((int) utf8[i]);
}
}
#else
add_key_to_queue((int)wParam);
#endif
}
key_already_handled = FALSE;
return 0;

Expand Down