Last active
October 24, 2016 19:02
-
-
Save mcarbonneaux/64fcb05799e7d1e89612598eccfcb50f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://stackoverflow.com/questions/10866311/getmessage-with-a-timeout | |
``` | |
BOOL GetMessageWithTimeout(MSG *msg, UINT to) | |
{ | |
BOOL res; | |
UINT_PTR timerId = SetTimer(NULL, NULL, to, NULL); | |
res = GetMessage(msg); | |
KillTimer(NULL, timerId); | |
if (!res) | |
return FALSE; | |
if (msg->message == WM_TIMER && msg->hwnd == NULL && msg->wParam == timerId) | |
return FALSE; //TIMEOUT! You could call SetLastError() or something... | |
return TRUE; | |
} | |
``` | |
or | |
``` | |
if (MsgWaitForMultipleObjects(0, NULL, FALSE, timeout, QS_ALLEVENTS) == WAIT_OBJECT_0) | |
{ | |
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) | |
{ | |
//dispatch the message | |
} | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment