Skip to content

Instantly share code, notes, and snippets.

@mcarbonneaux
Last active October 24, 2016 19:02
Show Gist options
  • Save mcarbonneaux/64fcb05799e7d1e89612598eccfcb50f to your computer and use it in GitHub Desktop.
Save mcarbonneaux/64fcb05799e7d1e89612598eccfcb50f to your computer and use it in GitHub Desktop.
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