Provide DoEvents function in front-ends
[xboard.git] / winboard / winboard.c
index 088badb..3515cb3 100644 (file)
@@ -786,12 +786,14 @@ void ThawUI()
  *\r
 \*---------------------------------------------------------------------------*/\r
 \r
+static void HandleMessage P((MSG *message));\r
+static HANDLE hAccelMain, hAccelNoAlt, hAccelNoICS;\r
+\r
 int APIENTRY\r
 WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,\r
        LPSTR lpCmdLine, int nCmdShow)\r
 {\r
   MSG msg;\r
-  HANDLE hAccelMain, hAccelNoAlt, hAccelNoICS;\r
 //  INITCOMMONCONTROLSEX ex;\r
 \r
   debugFP = stderr;\r
@@ -823,6 +825,17 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    0,    /* lowest message to examine */\r
                    0))   /* highest message to examine */\r
     {\r
+       HandleMessage(msg);\r
+    }\r
+\r
+\r
+  return (msg.wParam); /* Returns the value from PostQuitMessage */\r
+}\r
+\r
+static void\r
+HandleMessage (MSG *message)\r
+{\r
+    MSG msg = *message;\r
 \r
       if(msg.message == WM_CHAR && msg.wParam == '\t') {\r
        // [HGM] navigate: switch between all windows with tab\r
@@ -890,7 +903,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
          if(currentElement < 5 && IsIconic(hwndMain))    ShowWindow(hwndMain, SW_RESTORE); // all open together\r
          SetFocus(h);\r
 \r
-         continue; // this message now has been processed\r
+         return; // this message now has been processed\r
        }\r
       }\r
 \r
@@ -909,14 +922,24 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
            if(chatHandle[i] && IsDialogMessage(chatHandle[i], &msg)) {\r
                done = 1; break;\r
        }\r
-       if(done) continue; // [HGM] chat: end patch\r
+       if(done) return; // [HGM] chat: end patch\r
        TranslateMessage(&msg); /* Translates virtual key codes */\r
        DispatchMessage(&msg);  /* Dispatches message to window */\r
       }\r
-    }\r
-\r
+}\r
 \r
-  return (msg.wParam); /* Returns the value from PostQuitMessage */\r
+void\r
+DoEvents ()\r
+{ /* Dispatch pending messages */\r
+  MSG msg;\r
+  while (PeekMessage(&msg, /* message structure */\r
+                    NULL, /* handle of window receiving the message */\r
+                    0,    /* lowest message to examine */\r
+                    0,    /* highest message to examine */\r
+                    PM_REMOVE))\r
+    {\r
+       HandleMessage(msg);\r
+    }\r
 }\r
 \r
 /*---------------------------------------------------------------------------*\\r