I'm sure this is halfway to a faq but here goes.
I need to pump the message loop in some processing, something like the vb doevents function.
The usual implementation of this is something like:
Code:
while ( PeekMessage(&Msg,NULL,0,0,PM_REMOVE) ) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
The problem with this is that the window can be destroyed halfway through your processing. The expected solution to this would be not to process WM_DESTROY and WM_CLOSE:
Code:
if (Msg.message == WM_CLOSE || Msg.message == WM_DESTROY)
However, this does not work as WM_DESTROY and WM_CLOSE are not queued. ie. They are sent directly to the window procedure.
The only way I can think of is to trap the close and destroy messages, either in the main window proc or one set up for the purpose and set a flag to repost them at the end of the processing. However, this seems klunky.
Does anybody have a way of implementing doEvents without the window potentially disapearing?