|
-
October 14th, 2005, 12:13 AM
#1
How do I make my dialog show up if it is doing work?
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:
Code:
// enter modal loop
DWORD dwFlags = MLF_SHOWONIDLE;
if (GetStyle() & DS_NOIDLEMSG)
dwFlags |= MLF_NOIDLEMSG;
VERIFY(RunModalLoop(dwFlags) == m_nModalResult);
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?).
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....
-
October 14th, 2005, 12:15 AM
#2
Re: How do I make my dialog show up if it is doing work?
Ok, right as I hit "Submit", I realized I could just do a ShowWindow myself.
doh!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|