I have lengthy action that has a progress dialog. The dialog itself initiates the action: it spawns a worker thread and communicates with it using events.
The problem is, if in OnInitDialog, I post a message to myself to start the action, the dialog is not yet shown when it gets that message. So the whole operation happens with the dialog being invisible (even though I'm pumping messages).
By the time I get my posted message, shouldn't the dialog be visible???
If instead I post a WM_TIMER message, for, say 50ms, the dialog has appeared, and updates properly as progress increases.
This seems pretty bogus. Looking at MFC's modal dialog loop, I see this:
The MLF_SHOWONIDLE seems to be the culprit... only show the dialog when we're idle. Is there a way to get around this (without avoiding MFC altogether?).Code:// enter modal loop DWORD dwFlags = MLF_SHOWONIDLE; if (GetStyle() & DS_NOIDLEMSG) dwFlags |= MLF_NOIDLEMSG; VERIFY(RunModalLoop(dwFlags) == m_nModalResult);
Here are some code snippets:
Code:BOOL CCompileDialog::OnInitDialog() { BOOL fRet = __super::OnInitDialog(); PostMessage(WM_STARTCOMPILE, 0, 0); return fRet; }
In response to WM_STARTCOMPILE:
Code:while (TRUE) { MSG msg; // Read all of the messages in this next loop, // removing each message as we read it. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // Dispatch the message. DispatchMessage(&msg); } // End of PeekMessage while loop. int cObjects = 1; DWORD dwWait = MsgWaitForMultipleObjects(cObjects, &pInfo->hEventCompileDone, TRUE, INFINITE, QS_ALLEVENTS); if (dwWait == WAIT_OBJECT_0 + cObjects) { // More messages have arrived. continue; } else { // respond to my event, etc....




Reply With Quote