This one should be easy for you'all out there - I know, I've said that before, but on this one I mean it.
I have a windows app that presents a menu interface. When you push the right buttons and make the right selections, it then goes off and processes a file. Depending on the file size, it might take it some time. In order to keep the user from giving up in dispair, I've placed a dialog on the screen with a progress bar and a Cancel button to allow them to kill the process and gain control back if it appears to take too long.
The problem is, the Cancel button doesn't work. I don't see (in the dialog handler) the message come through, and I'm sure it's because the routine that is running has taken control away from the message loop completely while it's doing its thing. I periodicaly call a function that updates the progress bar, but it never gets back to the loop, so the Cancel never gets read or dispatched.
So, the question is, what do I need to add (for example, into the progress bar update function) to assure that messages that occur during the processing get handled? Is there a simple call that will cause the message loop to get exercised and then return when it's empty? Do I actually have to build another message loop into the progress bar function?
Here is the code of the message loop as it exists now, for reference (hDlgModeless is the dialog's window handle):
I have a windows app that presents a menu interface. When you push the right buttons and make the right selections, it then goes off and processes a file. Depending on the file size, it might take it some time. In order to keep the user from giving up in dispair, I've placed a dialog on the screen with a progress bar and a Cancel button to allow them to kill the process and gain control back if it appears to take too long.
The problem is, the Cancel button doesn't work. I don't see (in the dialog handler) the message come through, and I'm sure it's because the routine that is running has taken control away from the message loop completely while it's doing its thing. I periodicaly call a function that updates the progress bar, but it never gets back to the loop, so the Cancel never gets read or dispatched.
So, the question is, what do I need to add (for example, into the progress bar update function) to assure that messages that occur during the processing get handled? Is there a simple call that will cause the message loop to get exercised and then return when it's empty? Do I actually have to build another message loop into the progress bar function?
Here is the code of the message loop as it exists now, for reference (hDlgModeless is the dialog's window handle):
Code:
while (GetMessage (&msg, NULL, 0, 0)) {
if (hDlgModeless == NULL || !IsDialogMessage (hDlgModeless, &msg)) {
if (!TranslateAccelerator (msg.hwnd, hAccelTable, &msg)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
}