Pelles C forum
C language => Pocket PC and Smartphone questions => Topic started by: drgott on December 11, 2009, 09:03:08 PM
-
The sample GPS program uses a for(;;) loop to handle messages. I was wondering why. Can events triggered by the GPS driver only be handled with MsgWaitForMultipleObjects() ? Why do we even have to wait for the GPS events? They'll come when and if they'll come, just like the user tapping a button. And why wait INFINITEly?
-
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.
-
I don't know if it helps you, but at Pelles homepage at the capter Source code -> Pocket PC Samples -> GPS there is an example for handling GPS-datas.
-
See http://forum.pellesc.de/index.php?topic=3096.0
Sergey
-
The site covering PocketPC (Pocket PC) products that are related GPS or to Navigation. In some cases these products may also be used with WinCE palmtops. The terms "pocket pc," sometimes called ppc, and "WinCE" may be used interchangeably in this context however some products may be specific to one platform or the other.
-
I would first look into amalgamating them into one app since they all work to a common output.
If that was not possible I would look at designing a common data base for them all to access.
Finally I wold look at Frankie's suggestion.