2014-08-14 09:42:10 -05:00
|
|
|
// 17 july 2014
|
2014-07-17 18:36:24 -05:00
|
|
|
|
|
|
|
#include "winapi_windows.h"
|
|
|
|
#include "_cgo_export.h"
|
|
|
|
|
2014-08-14 09:42:10 -05:00
|
|
|
// note that this includes the terminating '\0'
|
2014-08-13 09:41:27 -05:00
|
|
|
#define NAREACLASS (sizeof areaWindowClass / sizeof areaWindowClass[0])
|
|
|
|
|
2014-07-17 18:36:24 -05:00
|
|
|
void uimsgloop(void)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
int res;
|
2014-08-12 16:18:45 -05:00
|
|
|
HWND active;
|
2014-08-13 09:41:27 -05:00
|
|
|
WCHAR classchk[NAREACLASS];
|
|
|
|
BOOL dodlgmessage;
|
2014-07-17 18:36:24 -05:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
SetLastError(0);
|
2014-07-17 22:14:22 -05:00
|
|
|
res = GetMessageW(&msg, NULL, 0, 0);
|
2014-07-17 18:36:24 -05:00
|
|
|
if (res < 0)
|
|
|
|
xpanic("error calling GetMessage()", GetLastError());
|
2014-08-14 09:42:10 -05:00
|
|
|
if (res == 0) // WM_QUIT
|
2014-07-17 18:36:24 -05:00
|
|
|
break;
|
2014-08-12 16:18:45 -05:00
|
|
|
active = GetActiveWindow();
|
2014-08-13 09:41:27 -05:00
|
|
|
if (active != NULL) {
|
|
|
|
HWND focus;
|
|
|
|
|
|
|
|
dodlgmessage = TRUE;
|
|
|
|
focus = GetFocus();
|
|
|
|
if (focus != NULL) {
|
|
|
|
// theoretically we could use the class atom to avoid a wcscmp()
|
2014-08-13 16:31:40 -05:00
|
|
|
// however, raymond chen advises against this - http://blogs.msdn.com/b/oldnewthing/archive/2004/10/11/240744.aspx
|
2014-08-13 09:41:27 -05:00
|
|
|
// while I have no idea what could deregister *my* window class from under *me*, better safe than sorry
|
|
|
|
// we could also theoretically just send msgAreaDefocuses directly, but what DefWindowProc() does to a WM_APP message is undocumented
|
|
|
|
if (GetClassNameW(focus, classchk, NAREACLASS) == 0)
|
|
|
|
xpanic("error getting name of focused window class for Area check", GetLastError());
|
|
|
|
if (wcscmp(classchk, areaWindowClass) == 0)
|
2014-08-13 13:09:53 -05:00
|
|
|
dodlgmessage = FALSE;
|
2014-08-13 09:41:27 -05:00
|
|
|
}
|
|
|
|
if (dodlgmessage && IsDialogMessageW(active, &msg) != 0)
|
|
|
|
continue;
|
|
|
|
}
|
2014-07-17 18:36:24 -05:00
|
|
|
TranslateMessage(&msg);
|
2014-07-17 22:14:22 -05:00
|
|
|
DispatchMessageW(&msg);
|
2014-07-17 18:36:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void issue(void *request)
|
|
|
|
{
|
|
|
|
SetLastError(0);
|
2014-07-17 23:22:21 -05:00
|
|
|
if (PostMessageW(msgwin, msgRequest, 0, (LPARAM) request) == 0)
|
2014-07-17 18:36:24 -05:00
|
|
|
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);
|
2014-07-25 14:58:24 -05:00
|
|
|
case WM_NOTIFY:
|
|
|
|
return forwardNotify(hwnd, uMsg, wParam, lParam);
|
2014-07-17 23:22:21 -05:00
|
|
|
case msgRequest:
|
2014-07-19 08:57:01 -05:00
|
|
|
doissue((void *) lParam);
|
2014-07-17 18:36:24 -05:00
|
|
|
return 0;
|
|
|
|
default:
|
2014-07-17 22:14:22 -05:00
|
|
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
2014-07-17 18:36:24 -05:00
|
|
|
}
|
|
|
|
xmissedmsg("message-only", "msgwinproc()", uMsg);
|
2014-08-14 09:42:10 -05:00
|
|
|
return 0; // unreachable
|
2014-07-17 18:36:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD makemsgwin(char **errmsg)
|
|
|
|
{
|
2014-07-17 22:14:22 -05:00
|
|
|
WNDCLASSW wc;
|
2014-07-17 18:36:24 -05:00
|
|
|
HWND hwnd;
|
|
|
|
|
2014-07-17 22:14:22 -05:00
|
|
|
ZeroMemory(&wc, sizeof (WNDCLASSW));
|
2014-07-17 18:36:24 -05:00
|
|
|
wc.lpfnWndProc = msgwinproc;
|
|
|
|
wc.hInstance = hInstance;
|
|
|
|
wc.hIcon = hDefaultIcon;
|
|
|
|
wc.hCursor = hArrowCursor;
|
|
|
|
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
|
|
|
|
wc.lpszClassName = msgwinclass;
|
2014-07-17 22:14:22 -05:00
|
|
|
if (RegisterClassW(&wc) == 0) {
|
2014-07-17 18:36:24 -05:00
|
|
|
*errmsg = "error registering message-only window classs";
|
|
|
|
return GetLastError();
|
|
|
|
}
|
2014-07-17 22:14:22 -05:00
|
|
|
msgwin = CreateWindowExW(
|
2014-07-17 18:36:24 -05:00
|
|
|
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;
|
|
|
|
}
|