Some Unicode-related fixups and additions in the new Windows code.

This commit is contained in:
Pietro Gagliardi 2014-07-17 23:14:22 -04:00
parent 0dc1538002
commit d8f302f157
2 changed files with 12 additions and 8 deletions

View File

@ -21,6 +21,10 @@ func xmissedmsg(purpose *C.char, f *C.char, uMsg C.UINT) {
panic(fmt.Errorf("%s window procedure message %d does not return a value (bug in %s)", C.GoString(purpose), uMsg, C.GoString(f))) panic(fmt.Errorf("%s window procedure message %d does not return a value (bug in %s)", C.GoString(purpose), uMsg, C.GoString(f)))
} }
func toUINT16(s string) C.LPCWSTR {
return C.LPCWSTR(unsafe.Pointer(syscall.StringToUTF16(s)))
}
func getWindowText(hwnd uintptr) string { func getWindowText(hwnd uintptr) string {
// WM_GETTEXTLENGTH and WM_GETTEXT return the count /without/ the terminating null character // WM_GETTEXTLENGTH and WM_GETTEXT return the count /without/ the terminating null character
// but WM_GETTEXT expects the buffer size handed to it to /include/ the terminating null character // but WM_GETTEXT expects the buffer size handed to it to /include/ the terminating null character

View File

@ -10,21 +10,21 @@ void uimsgloop(void)
for (;;) { for (;;) {
SetLastError(0); SetLastError(0);
res = GetMessage(&msg, NULL, 0, 0); res = GetMessageW(&msg, NULL, 0, 0);
if (res < 0) if (res < 0)
xpanic("error calling GetMessage()", GetLastError()); xpanic("error calling GetMessage()", GetLastError());
if (res == 0) /* WM_QUIT */ if (res == 0) /* WM_QUIT */
break; break;
/* TODO IsDialogMessage() */ /* TODO IsDialogMessage() */
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessageW(&msg);
} }
} }
void issue(void *request) void issue(void *request)
{ {
SetLastError(0); SetLastError(0);
if (PostMessage(msgwin, msgRequested, 0, (LPARAM) request) == 0) if (PostMessageW(msgwin, msgRequested, 0, (LPARAM) request) == 0)
xpanic("error issuing request", GetLastError()); xpanic("error issuing request", GetLastError());
} }
@ -41,7 +41,7 @@ static LRESULT CALLBACK msgwinproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
xperform((void *) lParam); xperform((void *) lParam);
return 0; return 0;
default: default:
return DefWindowProc(hwnd, uMsg, wParam, lParam); return DefWindowProcW(hwnd, uMsg, wParam, lParam);
} }
xmissedmsg("message-only", "msgwinproc()", uMsg); xmissedmsg("message-only", "msgwinproc()", uMsg);
return 0; /* unreachable */ return 0; /* unreachable */
@ -49,21 +49,21 @@ static LRESULT CALLBACK msgwinproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
DWORD makemsgwin(char **errmsg) DWORD makemsgwin(char **errmsg)
{ {
WNDCLASS wc; WNDCLASSW wc;
HWND hwnd; HWND hwnd;
ZeroMemory(&wc, sizeof (WNDCLASS)); ZeroMemory(&wc, sizeof (WNDCLASSW));
wc.lpfnWndProc = msgwinproc; wc.lpfnWndProc = msgwinproc;
wc.hInstance = hInstance; wc.hInstance = hInstance;
wc.hIcon = hDefaultIcon; wc.hIcon = hDefaultIcon;
wc.hCursor = hArrowCursor; wc.hCursor = hArrowCursor;
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
wc.lpszClassName = msgwinclass; wc.lpszClassName = msgwinclass;
if (RegisterClass(&wc) == 0) { if (RegisterClassW(&wc) == 0) {
*errmsg = "error registering message-only window classs"; *errmsg = "error registering message-only window classs";
return GetLastError(); return GetLastError();
} }
msgwin = CreateWindowEx( msgwin = CreateWindowExW(
0, 0,
msgwinclass, L"package ui message-only window", msgwinclass, L"package ui message-only window",
0, 0,