diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-17 19:36:24 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-17 19:36:24 -0400 |
| commit | 0adac4d3ca1ec91e6364fe11276323803418c2ff (patch) | |
| tree | 5160d2aa05131638ff2f4662627cb967c3b5407b /redo/uitask_windows.c | |
| parent | 257fd8f07c821a9dd1f879e94c703cbbb9a2c764 (diff) | |
Began the drudgery of converting all the Windows code to use cgo, because I'm not going to wait to debug this smashed stack.
Diffstat (limited to 'redo/uitask_windows.c')
| -rw-r--r-- | redo/uitask_windows.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/redo/uitask_windows.c b/redo/uitask_windows.c new file mode 100644 index 0000000..9177e19 --- /dev/null +++ b/redo/uitask_windows.c @@ -0,0 +1,78 @@ +/* 17 july 2014 */ + +#include "winapi_windows.h" +#include "_cgo_export.h" + +void uimsgloop(void) +{ + MSG msg; + int res; + + for (;;) { + SetLastError(0); + res = GetMessage(&msg, NULL, 0, 0); + if (res < 0) + xpanic("error calling GetMessage()", GetLastError()); + if (res == 0) /* WM_QUIT */ + break; + /* TODO IsDialogMessage() */ + TranslateMessage(&msg); + DispatchMessage(&msg); + } +} + +void issue(void *request) +{ + SetLastError(0); + if (PostMessage(msgwin, msgRequested, 0, (LPARAM) request) == 0) + xpanic("error issuing request", GetLastError()); +} + +HWND msgwin; + +#define msgwinclass L"gouimsgwin" + +static LRESULT CALLBACK msgwinproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) { + case WM_COMMAND: + return forwardCommand(hwnd, uMsg, wParam, lParam); + case msgRequested: + xperform((void *) lParam); + return 0; + default: + return DefWindowProc(hwnd, uMsg, wParam, lParam); + } + xmissedmsg("message-only", "msgwinproc()", uMsg); + return 0; /* unreachable */ +} + +DWORD makemsgwin(char **errmsg) +{ + WNDCLASS wc; + HWND hwnd; + + ZeroMemory(&wc, sizeof (WNDCLASS)); + wc.lpfnWndProc = msgwinproc; + wc.hInstance = hInstance; + wc.hIcon = hDefaultIcon; + wc.hCursor = hArrowCursor; + wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); + wc.lpszClassName = msgwinclass; + if (RegisterClass(&wc) == 0) { + *errmsg = "error registering message-only window classs"; + return GetLastError(); + } + msgwin = CreateWindowEx( + 0, + msgwinclass, L"package ui message-only window", + 0, + CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, + HWND_MESSAGE, NULL, hInstance, NULL); + if (msgwin == NULL) { + *errmsg = "error creating message-only window"; + return GetLastError(); + } + return 0; +} |
