I'm having trouble figuring out how to update my WM_CHAR handler to work with the new /utf-8 execution mode +manifest. I have it working correctly if I use strings from source with unicode characters. The windows title and console will display them as they should, but now I want my user input to handle it correctly as well.
I can't find documentation about it anywhere, so at some point I tried to just figure it out manually but no luck.
So I try to print the data like this:
case WM_CHAR: println("WM_CHAR: 0x{:X}[{}]", (uint32)wParam, GetUTF8CharCount((uint32)wParam));
The count function is this:
static uint GetUTF8CharCount(uint32 c) { if (c <= 0x7F) { /* U+0000 ... U+007F */ return 1; } else if (c < 0x07FF) { /* U+0080 ... U+07FF */ return 2; } else if (c < 0xFFFF) { /* U+0800 ... U+FFFF */ return 3; } else { /* U+10000 ... U+10FFFF */ return 4; }}
If I type 'ウ' in a textbox the following info prints:
[Info]: WM_CHAR: 0x4581[3][Info]: WM_CHAR: 0x4581[3][Info]: WM_CHAR: 0xA6[2]
This website tells me that only the last byte is correct.It makes no sense to me, how do I interpret this msg?
Edit:
Additionally I've printed the following info:
CPINFOEX cpInfo;GetCPInfoEx(CP_ACP, 0, &cpInfo);println("ACP: {}, IsWindowUnicode: {}", GetACP(), IsWindowUnicode(hWnd));println("CPINFOEX: {{{}, {}, {}, {}, {}}}", cpInfo.CodePage, std::string(cpInfo.CodePageName), *((uint16*)cpInfo.DefaultChar), cpInfo.MaxCharSize, (uint32)cpInfo.UnicodeDefaultChar);
Result:
[Info]: ACP: 65001, IsWindowUnicode: 0[Info]: CPINFOEX: {65001, 65001 (UTF-8), 63, 4, 65533}
To emphasize that it does work (if I add it directly in source):
Edit 2:
It seems to be related to the active language. If I set my keyboard layout to US-international (my default), then press Win+; to type the 🎉 emoji I get F0 9F 8E 89
, but switching to Japanese causes the 0x4581
to appear