- if (GetMessage(&msg, NULL, 0, 0) == 1) {
- while (msg.message != WM_QUIT) {
+ while (1) {
+ HANDLE *handles;
+ int nhandles, n;
+
+ handles = handle_get_events(&nhandles);
+
+ n = MsgWaitForMultipleObjects(nhandles, handles, FALSE, INFINITE,
+ QS_ALLINPUT);
+
+ if ((unsigned)(n - WAIT_OBJECT_0) < (unsigned)nhandles) {
+ handle_got_event(handles[n - WAIT_OBJECT_0]);
+ sfree(handles);
+ continue;
+ }
+
+ sfree(handles);
+
+ if (GetMessage(&msg, NULL, 0, 0) != 1)
+ break;
+ do {
+ if (msg.message == WM_QUIT)
+ goto finished; /* two-level break */
+