-
July 27th, 2004, 12:38 PM
#1
Wait for a modeless dialog to finish
I have a global function which creates a dialog box. I don't want this dialog to block the main window, so I decided to use a modeless dialog box. But the function that displays the dialog box needs to wait until the dialog is closed. The pseudo-code is something like this:
foo()
{
dlg.create();
dlg.ShowWindow();
wait until dlg is closed and then continue here
}
Does anyone know how to do this? Thank you very much!
-
July 27th, 2004, 12:48 PM
#2
Have the dialog send a message to your main window when it gets closed. You have to understand that if you add a waiting loop in that function (foo()), this loop will block the main window's message pump, if the function runs in the main thread.
One option is to switch to multithreading, but that is an overkill. A second option is to call the main window's message pump from inside the waiting loop, but that is an ugly hack.
In my oppinion, the smoothest solution is the message driven one.
-
July 27th, 2004, 12:57 PM
#3
Originally Posted by Gabriel Fleseriu
You have to understand that if you add a waiting loop in that function (foo()), this loop will block the main window's message pump, if the function runs in the main thread.
Well...one could use 'MsgWaitForMultipleObjects()' to avoid this, however, I also would suggest to send a 'termination' message to the main dialog...even in regard that this is a modeless dialog box...in other words the user should still be able to work with the main dialog (which would not be the case if the message queue would be blocked)...
-
July 27th, 2004, 01:32 PM
#4
-
July 28th, 2004, 09:28 PM
#5
Originally Posted by Gabriel Fleseriu
One option is to switch to multithreading, but that is an overkill.
Thank you very much for your hint. It dawns on me that using UI thread would solve the problem nicely.
-
July 29th, 2004, 03:35 AM
#6
Originally Posted by kyoko
It dawns on me that using UI thread would solve the problem nicely.
Well...did you read the second part of the sentence by Gabriel...the one with the 'overkill' in it...? From your description, I honestly see no need to add multithreading here...
-
July 29th, 2004, 09:56 PM
#7
Originally Posted by Andreas Masur
Well...did you read the second part of the sentence by Gabriel...the one with the 'overkill' in it...? From your description, I honestly see no need to add multithreading here...
Thank you for your comments. Honestly, I didn't know how to do it without using multithreading. using windows messages alone, doesn't seem to work, because foo() is a global function, and it can't receive windows messages, right?
-
July 30th, 2004, 01:12 AM
#8
So why does foo need to wait for the modeless dialog to be closed?
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
July 30th, 2004, 02:16 AM
#9
Well..and to follow souldog....in my eyes the following sentence of you is a contradiction...
I don't want this dialog to block the main window, so I decided to use a modeless dialog box.
Why not simply opening the dialog modally...and thus, your application cannot be used by the user as long as the dialog is open. If you need some kind of trigger, simply post a message to the main dialog as soon as the modal dialog is being closed...
-
July 31st, 2004, 09:26 AM
#10
Originally Posted by Andreas Masur
Well..and to follow souldog....in my eyes the following sentence of you is a contradiction...
Why not simply opening the dialog modally...and thus, your application cannot be used by the user as long as the dialog is open. If you need some kind of trigger, simply post a message to the main dialog as soon as the modal dialog is being closed...
Well, the dialog I want to pop up is a download progress dialog. It it a potentially long lasting process, so I don't want it to block the user to do other operations on the main dialog. On the other way, foo() needs to wait for the dialog to close before it can proceed, because foo() needs to do some operation with the downloaded file, only after the dialog is closed can foo() know the download is complete.
-
July 31st, 2004, 10:08 AM
#11
So what you need to do is break foo into two funcitons.
foo1()
{
//start download
//display progress dialog as modeless
//when done post message to main window
}
foo2()
{
//this is run when the main window gets the message that download is done
//do whatever foo did when progress is done.
}
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
July 31st, 2004, 04:07 PM
#12
As souldog pointed out (just like Gabriel), the way to go here is using messages rather than introducing threading...
-
February 3rd, 2016, 05:57 PM
#13
Re: Wait for a modeless dialog to finish
Originally Posted by GCDEF
dlg.RunModalLoop();
This is the easiest, cleanest solution.
I was looking for similar requirements of a modeless dialog, and this did the trick:
Code:
dlg.Create(IDD_MYDialog, CWndOfMainExe);
dlg.ShowWindow(SW_NORMAL);
dlg.RunModalLoop(MLF_NOIDLEMSG);
-
February 28th, 2016, 05:08 PM
#14
Re: Wait for a modeless dialog to finish
you can run while loop with PeekMessage
but i doubt it can be done properly
Last edited by Alexeyn; February 29th, 2016 at 04:59 PM.
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
|