// @pyswig int|PumpWaitingMessages|Pumps all waiting messages for the current thread. // @rdesc Returns non-zero (exit code from PostQuitMessage) if a WM_QUIT message was received, else 0 static PyObject *PyPumpWaitingMessages(PyObject *self, PyObject *args) { UINT firstMsg = 0, lastMsg = 0; if (!PyArg_ParseTuple (args, "|ii:PumpWaitingMessages", &firstMsg, &lastMsg)) return NULL; // @pyseeapi PeekMessage and DispatchMessage MSG msg; WPARAM result = 0; // Read all of the messages in this next loop, // removing each message as we read it. Py_BEGIN_ALLOW_THREADS while (PeekMessage(&msg, NULL, firstMsg, lastMsg, PM_REMOVE)) { // If it's a quit message, we're out of here. if (msg.message == WM_QUIT) { if(0 != msg.wParam) result = msg.wParam; else result = 1; break; } // Otherwise, dispatch the message. if(NULL == hDialogCurrent || !IsDialogMessage(hDialogCurrent,&msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } // End of PeekMessage while loop // @xref Py_END_ALLOW_THREADS return PyWinLong_FromVoidPtr((void *)result); } http://blogs.msdn.com/oldnewthing/archive/2005/02/17/375307.aspx