Migrated main.c.

This commit is contained in:
Pietro Gagliardi 2016-04-22 14:06:22 -04:00
parent 0e85afb3ff
commit 6124d45c62
2 changed files with 41 additions and 50 deletions

View File

@ -1,50 +0,0 @@
// 6 april 2015
#include "uipriv_windows.h"
// TODO http://blogs.msdn.com/b/oldnewthing/archive/2005/04/08/406509.aspx when adding accelerators, TranslateMessage() before IsDialogMessage()
static void msgloop_else(MSG *msg)
{
TranslateMessage(msg);
DispatchMessageW(msg);
}
void uiMain(void)
{
MSG msg;
int res;
HWND active;
for (;;) {
SetLastError(0);
res = GetMessageW(&msg, NULL, 0, 0);
if (res < 0)
logLastError("error calling GetMessage() in uiMain()");
if (res == 0) // WM_QUIT
break;
active = GetActiveWindow();
if (active == NULL) {
msgloop_else(&msg);
continue;
}
// TODO find documentation that says IsDialogMessage() calls CallMsgFilter() for us, because that's what's happening
// TODO rewrite this whole function to compensate
if (IsDialogMessage(active, &msg) != 0)
continue;
msgloop_else(&msg);
}
}
void uiQuit(void)
{
PostQuitMessage(0);
}
void uiQueueMain(void (*f)(void *data), void *data)
{
if (PostMessageW(utilWindow, msgQueued, (WPARAM) f, (LPARAM) data) == 0)
// TODO make sure this is safe to call across threads
logLastError("error queueing function to run on main thread in uiQueueMain()");
}

41
windows/main.cpp Normal file
View File

@ -0,0 +1,41 @@
// 6 april 2015
#include "uipriv_windows.hpp"
// TODO http://blogs.msdn.com/b/oldnewthing/archive/2005/04/08/406509.aspx when adding accelerators, TranslateAccelerators() before IsDialogMessage()
void uiMain(void)
{
MSG msg;
int res;
HWND active;
for (;;) {
res = GetMessageW(&msg, NULL, 0, 0);
if (res < 0) {
logLastError(L"error calling GetMessage()");
break; // bail out on error
}
if (res == 0) // WM_QUIT
break;
// TODO really active? or parentToplevel(msg->hwnd)?
active = GetActiveWindow();
if (active != NULL)
// TODO find documentation that says IsDialogMessage() calls CallMsgFilter() for us, because that's what's happening
if (IsDialogMessage(active, &msg) != 0)
continue;
TranslateMessage(msg);
DispatchMessageW(msg);
}
}
void uiQuit(void)
{
PostQuitMessage(0);
}
void uiQueueMain(void (*f)(void *data), void *data)
{
if (PostMessageW(utilWindow, msgQueued, (WPARAM) f, (LPARAM) data) == 0)
// TODO this is likely not safe to call across threads (allocates memory)
logLastError(L"error queueing function to run on main thread");
}