Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

waiting for the end of modeless dialog

I need help for the following problem: In my code I use a modeless dialog box because I have to make some changes in the view during the dialog is displayed. But the function which calls the dialog box have to stop until the dialogbox is destroyed. How can I make the function wait for the end of the destruction of the dialogbox.


Comments

  • You can use the IsWindow() API.

    View? I believe you use MFC with a global CDialog object, you can do this checking (assuming m_pDialog is the modeless dialog to examine):



    if( ::IsWindow( m_pDialog->m_hWnd ) )

    {

    // dialog is alive

    }

    else

    {

    // dialog is dead

    }



    HTH

    : I need help for the following problem: In my code I use a modeless dialog box because I have to make some changes in the view during the dialog is displayed. But the function which calls the dialog box have to stop until the dialogbox is destroyed. How can I make the function wait for the end of the destruction of the dialogbox.

    :






  • Thank you for your help.

    But I think my problem is still a little bit different:



    newTJoint->SetRefPosition( MatePosition);



    CDJoint *dlgJoint = NULL;

    dlgJoint = TheApplication->EnableDlgJoint();



    dlgJoint->m_pJoint = newTJoint;

    dlgJoint->m_plane = MatePlane;

    ...



    The EnableDlgJoint() function creates the modeless dialog box (new and CDialog::Create). So every think is working fine...

    The modeless Dialog is displayed and at the same time the rest of the code is executed.

    But I need that the rest of the code waits for the end of the dialog (DestroyWindow). So after the EnableDlgJoint I need some function like

    WaitForEndOfDialog()?

    I have the impression I have to use Threads and Events for this problem. I was just wondering if there is maybe for modeless Dialogbox already something which solved this problem.



    Thanks.















    : You can use the IsWindow() API.

    : View? I believe you use MFC with a global CDialog object, you can do this checking (assuming m_pDialog is the modeless dialog to examine):

    :

    : if( ::IsWindow( m_pDialog->m_hWnd ) )

    : {

    : // dialog is alive

    : }

    : else

    : {

    : // dialog is dead

    : }

    :

    : HTH

    : : I need help for the following problem: In my code I use a modeless dialog box because I have to make some changes in the view during the dialog is displayed. But the function which calls the dialog box have to stop until the dialogbox is destroyed. How can I make the function wait for the end of the destruction of the dialogbox.

    : :

    :

    :

    :






  • I see, sorry for misunderstanding.



    Ok, you can solve this by either using threads or maybe have a small message pump after you create the dialog, something along this:

    while(::IsWindow(m_pDialog->m_hWnd))

    {

    PeekMessage(PM_REMOVE), !IsDialogMessage(), Translate and Dispatch.

    }



    Which might work but alot of headaches (What if the user ends the application at this point?)



    Maybe a better alternative is to move the portion of code you want to be called "after" the dialog is destroyed into some public function in your view, pass a pointer of the view to the dialog upon creation and then call that function upon OnClose of the dialog.



    HTH, apology again for missing the original point.





    : Thank you for your help.

    : But I think my problem is still a little bit different:

    :

    : newTJoint->SetRefPosition( MatePosition);

    :

    : CDJoint *dlgJoint = NULL;

    : dlgJoint = TheApplication->EnableDlgJoint();

    :

    : dlgJoint->m_pJoint = newTJoint;

    : dlgJoint->m_plane = MatePlane;

    : ...

    :

    : The EnableDlgJoint() function creates the modeless dialog box (new and CDialog::Create). So every think is working fine...

    : The modeless Dialog is displayed and at the same time the rest of the code is executed.

    : But I need that the rest of the code waits for the end of the dialog (DestroyWindow). So after the EnableDlgJoint I need some function like

    : WaitForEndOfDialog()?

    : I have the impression I have to use Threads and Events for this problem. I was just wondering if there is maybe for modeless Dialogbox already something which solved this problem.

    :

    : Thanks.

    :

    :

    :

    :

    :

    :

    :

    : : You can use the IsWindow() API.

    : : View? I believe you use MFC with a global CDialog object, you can do this checking (assuming m_pDialog is the modeless dialog to examine):

    : :

    : : if( ::IsWindow( m_pDialog->m_hWnd ) )

    : : {

    : : // dialog is alive

    : : }

    : : else

    : : {

    : : // dialog is dead

    : : }

    : :

    : : HTH

    : : : I need help for the following problem: In my code I use a modeless dialog box because I have to make some changes in the view during the dialog is displayed. But the function which calls the dialog box have to stop until the dialogbox is destroyed. How can I make the function wait for the end of the destruction of the dialogbox.

    : : :

    : :

    : :

    : :

    :

    :

    :






  • Thank you very much.



    You are right. The best think would be to restructure my code as you proposed.



    Thanks a lot.



    Matthias







    : I see, sorry for misunderstanding.

    :

    : Ok, you can solve this by either using threads or maybe have a small message pump after you create the dialog, something along this:

    : while(::IsWindow(m_pDialog->m_hWnd))

    : {

    : PeekMessage(PM_REMOVE), !IsDialogMessage(), Translate and Dispatch.

    : }

    :

    : Which might work but alot of headaches (What if the user ends the application at this point?)

    :

    : Maybe a better alternative is to move the portion of code you want to be called "after" the dialog is destroyed into some public function in your view, pass a pointer of the view to the dialog upon creation and then call that function upon OnClose of the dialog.

    :

    : HTH, apology again for missing the original point.

    :

    :

    : : Thank you for your help.

    : : But I think my problem is still a little bit different:

    : :

    : : newTJoint->SetRefPosition( MatePosition);

    : :

    : : CDJoint *dlgJoint = NULL;

    : : dlgJoint = TheApplication->EnableDlgJoint();

    : :

    : : dlgJoint->m_pJoint = newTJoint;

    : : dlgJoint->m_plane = MatePlane;

    : : ...

    : :

    : : The EnableDlgJoint() function creates the modeless dialog box (new and CDialog::Create). So every think is working fine...

    : : The modeless Dialog is displayed and at the same time the rest of the code is executed.

    : : But I need that the rest of the code waits for the end of the dialog (DestroyWindow). So after the EnableDlgJoint I need some function like

    : : WaitForEndOfDialog()?

    : : I have the impression I have to use Threads and Events for this problem. I was just wondering if there is maybe for modeless Dialogbox already something which solved this problem.

    : :

    : : Thanks.

    : :

    : :

    : :

    : :

    : :

    : :

    : :

    : : : You can use the IsWindow() API.

    : : : View? I believe you use MFC with a global CDialog object, you can do this checking (assuming m_pDialog is the modeless dialog to examine):

    : : :

    : : : if( ::IsWindow( m_pDialog->m_hWnd ) )

    : : : {

    : : : // dialog is alive

    : : : }

    : : : else

    : : : {

    : : : // dialog is dead

    : : : }

    : : :

    : : : HTH

    : : : : I need help for the following problem: In my code I use a modeless dialog box because I have to make some changes in the view during the dialog is displayed. But the function which calls the dialog box have to stop until the dialogbox is destroyed. How can I make the function wait for the end of the destruction of the dialogbox.

    : : : :

    : : :

    : : :

    : : :

    : :

    : :

    : :

    :

    :

    :






  • Hi there,

    Maybe a bit late (I don't visit here too often), but here's an idea that just might be worth thinking about. I don't know what exactly you need done while the dialog is open, but I figure it is some kind of background stuff. To solve it with multiple threads might be a bit of an overkill, to solve it by peeking for destroy messages seems a bit of a nasty approach. There is always what is called the 'idle' thread. This isn't really a thread (you may well know what it is, but just for completeness...), it's really an idle-message your app receives when there are no other messages waiting. So you can have all kinds of background stuff done while your dialog waits for user input. So what if you do make it a modal dialog, so that your app automatically waits for it to close, and move the code you want executed meanwhile to a function or method that responds to the idle message.

    Just a thought.



    Greets,

    Mark









    : Thank you very much.

    :

    : You are right. The best think would be to restructure my code as you proposed.

    :

    : Thanks a lot.

    :

    : Matthias

    :

    :

    :

    : : I see, sorry for misunderstanding.

    : :

    : : Ok, you can solve this by either using threads or maybe have a small message pump after you create the dialog, something along this:

    : : while(::IsWindow(m_pDialog->m_hWnd))

    : : {

    : : PeekMessage(PM_REMOVE), !IsDialogMessage(), Translate and Dispatch.

    : : }

    : :

    : : Which might work but alot of headaches (What if the user ends the application at this point?)

    : :

    : : Maybe a better alternative is to move the portion of code you want to be called "after" the dialog is destroyed into some public function in your view, pass a pointer of the view to the dialog upon creation and then call that function upon OnClose of the dialog.

    : :

    : : HTH, apology again for missing the original point.

    : :

    : :

    : : : Thank you for your help.

    : : : But I think my problem is still a little bit different:

    : : :

    : : : newTJoint->SetRefPosition( MatePosition);

    : : :

    : : : CDJoint *dlgJoint = NULL;

    : : : dlgJoint = TheApplication->EnableDlgJoint();

    : : :

    : : : dlgJoint->m_pJoint = newTJoint;

    : : : dlgJoint->m_plane = MatePlane;

    : : : ...

    : : :

    : : : The EnableDlgJoint() function creates the modeless dialog box (new and CDialog::Create). So every think is working fine...

    : : : The modeless Dialog is displayed and at the same time the rest of the code is executed.

    : : : But I need that the rest of the code waits for the end of the dialog (DestroyWindow). So after the EnableDlgJoint I need some function like

    : : : WaitForEndOfDialog()?

    : : : I have the impression I have to use Threads and Events for this problem. I was just wondering if there is maybe for modeless Dialogbox already something which solved this problem.

    : : :

    : : : Thanks.

    : : :

    : : :

    : : :

    : : :

    : : :

    : : :

    : : :

    : : : : You can use the IsWindow() API.

    : : : : View? I believe you use MFC with a global CDialog object, you can do this checking (assuming m_pDialog is the modeless dialog to examine):

    : : : :

    : : : : if( ::IsWindow( m_pDialog->m_hWnd ) )

    : : : : {

    : : : : // dialog is alive

    : : : : }

    : : : : else

    : : : : {

    : : : : // dialog is dead

    : : : : }

    : : : :

    : : : : HTH

    : : : : : I need help for the following problem: In my code I use a modeless dialog box because I have to make some changes in the view during the dialog is displayed. But the function which calls the dialog box have to stop until the dialogbox is destroyed. How can I make the function wait for the end of the destruction of the dialogbox.

    : : : : :

    : : : :

    : : : :

    : : : :

    : : :

    : : :

    : : :

    : :

    : :

    : :

    :

    :

    :






  • all dialogs in MFC are modeless? if you trace DoModal() down you will see it goes down to some function (RunModal()???) that does a message pump with while(::IsWindow()). Weird but true!



    : Hi there,

    : Maybe a bit late (I don't visit here too often), but here's an idea that just might be worth thinking about. I don't know what exactly you need done while the dialog is open, but I figure it is some kind of background stuff. To solve it with multiple threads might be a bit of an overkill, to solve it by peeking for destroy messages seems a bit of a nasty approach. There is always what is called the 'idle' thread. This isn't really a thread (you may well know what it is, but just for completeness...), it's really an idle-message your app receives when there are no other messages waiting. So you can have all kinds of background stuff done while your dialog waits for user input. So what if you do make it a modal dialog, so that your app automatically waits for it to close, and move the code you want executed meanwhile to a function or method that responds to the idle message.

    : Just a thought.

    :

    : Greets,

    : Mark

    :

    :

    :

    :

    : : Thank you very much.

    : :

    : : You are right. The best think would be to restructure my code as you proposed.

    : :

    : : Thanks a lot.

    : :

    : : Matthias

    : :

    : :

    : :

    : : : I see, sorry for misunderstanding.

    : : :

    : : : Ok, you can solve this by either using threads or maybe have a small message pump after you create the dialog, something along this:

    : : : while(::IsWindow(m_pDialog->m_hWnd))

    : : : {

    : : : PeekMessage(PM_REMOVE), !IsDialogMessage(), Translate and Dispatch.

    : : : }

    : : :

    : : : Which might work but alot of headaches (What if the user ends the application at this point?)

    : : :

    : : : Maybe a better alternative is to move the portion of code you want to be called "after" the dialog is destroyed into some public function in your view, pass a pointer of the view to the dialog upon creation and then call that function upon OnClose of the dialog.

    : : :

    : : : HTH, apology again for missing the original point.

    : : :

    : : :

    : : : : Thank you for your help.

    : : : : But I think my problem is still a little bit different:

    : : : :

    : : : : newTJoint->SetRefPosition( MatePosition);

    : : : :

    : : : : CDJoint *dlgJoint = NULL;

    : : : : dlgJoint = TheApplication->EnableDlgJoint();

    : : : :

    : : : : dlgJoint->m_pJoint = newTJoint;

    : : : : dlgJoint->m_plane = MatePlane;

    : : : : ...

    : : : :

    : : : : The EnableDlgJoint() function creates the modeless dialog box (new and CDialog::Create). So every think is working fine...

    : : : : The modeless Dialog is displayed and at the same time the rest of the code is executed.

    : : : : But I need that the rest of the code waits for the end of the dialog (DestroyWindow). So after the EnableDlgJoint I need some function like

    : : : : WaitForEndOfDialog()?

    : : : : I have the impression I have to use Threads and Events for this problem. I was just wondering if there is maybe for modeless Dialogbox already something which solved this problem.

    : : : :

    : : : : Thanks.

    : : : :

    : : : :

    : : : :

    : : : :

    : : : :

    : : : :

    : : : :

    : : : : : You can use the IsWindow() API.

    : : : : : View? I believe you use MFC with a global CDialog object, you can do this checking (assuming m_pDialog is the modeless dialog to examine):

    : : : : :

    : : : : : if( ::IsWindow( m_pDialog->m_hWnd ) )

    : : : : : {

    : : : : : // dialog is alive

    : : : : : }

    : : : : : else

    : : : : : {

    : : : : : // dialog is dead

    : : : : : }

    : : : : :

    : : : : : HTH

    : : : : : : I need help for the following problem: In my code I use a modeless dialog box because I have to make some changes in the view during the dialog is displayed. But the function which calls the dialog box have to stop until the dialogbox is destroyed. How can I make the function wait for the end of the destruction of the dialogbox.

    : : : : : :

    : : : : :

    : : : : :

    : : : : :

    : : : :

    : : : :

    : : : :

    : : :

    : : :

    : : :

    : :

    : :

    : :

    :

    :

    :






  • It's funny to see how Microsoft solves certain problems. But since the code is there and usable, if one decides to use MFC, it might be just the proper thing to do to use the existing implementation. Else why use MFC?

    I think that improves 'cleaneliness', however yuck the word sounds :P

    It's comparable to a decision to use C++ rather than C, and still have your module loaded with global data and functions, and only one or two classes used simply as self-initialising data containers. Even though I have occasionally been guilty of doing exactly that, it kind of misses the point of the initial decision.



    Darn, I elaborate deeply on this matter which is basically already solved... Well then, happy easter weekend everyone!



    Greets,

    Mark Meijer







    : all dialogs in MFC are modeless? if you trace DoModal() down you will see it goes down to some function (RunModal()???) that does a message pump with while(::IsWindow()). Weird but true!

    :

    : : Hi there,

    : : Maybe a bit late (I don't visit here too often), but here's an idea that just might be worth thinking about. I don't know what exactly you need done while the dialog is open, but I figure it is some kind of background stuff. To solve it with multiple threads might be a bit of an overkill, to solve it by peeking for destroy messages seems a bit of a nasty approach. There is always what is called the 'idle' thread. This isn't really a thread (you may well know what it is, but just for completeness...), it's really an idle-message your app receives when there are no other messages waiting. So you can have all kinds of background stuff done while your dialog waits for user input. So what if you do make it a modal dialog, so that your app automatically waits for it to close, and move the code you want executed meanwhile to a function or method that responds to the idle message.

    : : Just a thought.

    : :

    : : Greets,

    : : Mark

    : :

    : :

    : :

    : :

    : : : Thank you very much.

    : : :

    : : : You are right. The best think would be to restructure my code as you proposed.

    : : :

    : : : Thanks a lot.

    : : :

    : : : Matthias

    : : :

    : : :

    : : :

    : : : : I see, sorry for misunderstanding.

    : : : :

    : : : : Ok, you can solve this by either using threads or maybe have a small message pump after you create the dialog, something along this:

    : : : : while(::IsWindow(m_pDialog->m_hWnd))

    : : : : {

    : : : : PeekMessage(PM_REMOVE), !IsDialogMessage(), Translate and Dispatch.

    : : : : }

    : : : :

    : : : : Which might work but alot of headaches (What if the user ends the application at this point?)

    : : : :

    : : : : Maybe a better alternative is to move the portion of code you want to be called "after" the dialog is destroyed into some public function in your view, pass a pointer of the view to the dialog upon creation and then call that function upon OnClose of the dialog.

    : : : :

    : : : : HTH, apology again for missing the original point.

    : : : :

    : : : :

    : : : : : Thank you for your help.

    : : : : : But I think my problem is still a little bit different:

    : : : : :

    : : : : : newTJoint->SetRefPosition( MatePosition);

    : : : : :

    : : : : : CDJoint *dlgJoint = NULL;

    : : : : : dlgJoint = TheApplication->EnableDlgJoint();

    : : : : :

    : : : : : dlgJoint->m_pJoint = newTJoint;

    : : : : : dlgJoint->m_plane = MatePlane;

    : : : : : ...

    : : : : :

    : : : : : The EnableDlgJoint() function creates the modeless dialog box (new and CDialog::Create). So every think is working fine...

    : : : : : The modeless Dialog is displayed and at the same time the rest of the code is executed.

    : : : : : But I need that the rest of the code waits for the end of the dialog (DestroyWindow). So after the EnableDlgJoint I need some function like

    : : : : : WaitForEndOfDialog()?

    : : : : : I have the impression I have to use Threads and Events for this problem. I was just wondering if there is maybe for modeless Dialogbox already something which solved this problem.

    : : : : :

    : : : : : Thanks.

    : : : : :

    : : : : :

    : : : : :

    : : : : :

    : : : : :

    : : : : :

    : : : : :

    : : : : : : You can use the IsWindow() API.

    : : : : : : View? I believe you use MFC with a global CDialog object, you can do this checking (assuming m_pDialog is the modeless dialog to examine):

    : : : : : :

    : : : : : : if( ::IsWindow( m_pDialog->m_hWnd ) )

    : : : : : : {

    : : : : : : // dialog is alive

    : : : : : : }

    : : : : : : else

    : : : : : : {

    : : : : : : // dialog is dead

    : : : : : : }

    : : : : : :

    : : : : : : HTH

    : : : : : : : I need help for the following problem: In my code I use a modeless dialog box because I have to make some changes in the view during the dialog is displayed. But the function which calls the dialog box have to stop until the dialogbox is destroyed. How can I make the function wait for the end of the destruction of the dialogbox.

    : : : : : : :

    : : : : : :

    : : : : : :

    : : : : : :

    : : : : :

    : : : : :

    : : : : :

    : : : :

    : : : :

    : : : :

    : : :

    : : :

    : : :

    : :

    : :

    : :

    :

    :

    :






Sign In or Register to comment.