I am not sure that the GPS sample gives the best advice for the message passing loop. After looking through MSDN the following code appears to be the recommended way of handling the events.
int notFinished = 0;
do {
/* Wait for GPS or message queue events */
switch (MsgWaitForMultipleObjects(NUM_EVENTS, ahEvents, FALSE, INFINITE, QS_ALLINPUT)) {
case WAIT_OBJECT_0 + EVENT_NEWPOSITION:
/* Change in GPS position -- update dialog */
GPSPosition(hDevice, hwndDlg);
notFinished = 1;
break;
case WAIT_OBJECT_0 + EVENT_NEWSTATE:
/* Change in GPS state -- update dialog */
GPSState(hDevice, hwndDlg);
notFinished = 1;
break;
case WAIT_OBJECT_0 + NUM_EVENTS:
/* New message in queue */
/* need to use PeekMessage loop instead of simple GetMessage:
* multiple messages might have arrived in between,
* so GetMessage would lead to delayed processing */
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) {
notFinished = 0;;
break;
} else {
if (!IsWindow(hwndDlg) || !IsDialogMessage(hwndDlg, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
notFinished = 1;
}
}
break;
default:
notFinished = 0;
}
} while (notFinished > 0);
Hope this helps.