Dialog + Modeless

HI,

  I am trying to create a dialog. I have a .EXE which already as its Dialog and this dialog is create with the function DoModal(). This EXE loads my dll. and at some point my dll needs to lauch a modeless dialog... I have tried the following:

        DlgPtr = new DlgClass();
        DlgPtr->Create( IDD_FIRST_DIALOG );
        DlgPtr->ShowWindow( SW_SHOW );

But this does not work. It pops up the dialog but its all grey and the hour glass is on it. making my entire app not function.

Thanks for any help!

maldini







Answer this question

Dialog + Modeless

  • AndyL

    But how do you recognize that the user has done his input.
    Use DoModal. You can not create a dialog without allowing message to be processed.

  • TheSun

    But DoModal() is a Blocking function. My state Machine can not afford to Block.

    thx
    maldini


  • ISW

    What are you doing after the Create Unless there is a message loop that gets executed your dialog will not work.

    What do you want to do

  • DanielAnywhere

    Modeless dialogs work perfect if you have a message loop in your thread that permanently pumps the the messages and deliver them.

    I.e a modeless box is something like a search/replace dialog in an editor.

    But your process/thread didn't have a message loop. More extrem its permanently excutes code. So window message doesn't get processed. So no window can live under such a situation. They wont get painted or will never react on user input.
    Painting and use input forces the existance of an active message loop!

    HTH



  • Siggi Bjarnason

    Than you need a second GUI thread to lunch and show the dialog!

  • mam6669

    Hi,

    What i really have is a state machine!!!,,,At some event sent from the main EXE, my dll which is realy a state machine must display a dialog which contains some activeXs and some buttons.. So after i do the Create and the ShowWindow... I basically do some small configuration and then go back to idle state awaiting for another message form the EXE..

    I am not too familliar with message loop, is that what I need. If so how to I go about setting one up...

    Thanks for the help in advance.
    maldiniSmile


  • breed

    Ok, I tried what you said, that is I placed the doModal in a thread. It seems to work. In order to kill my thread and the dialog i call the EndDialog( int nRet ) which unblocks the domodal() and brings the thread to its return.

    Is this OK , Is it good programming practice, If so whats the point of having a modeless Dialog. I have an EBOOK "Programming Windows with MFC" by Jeff Prosise. And there is a section about modeless Dialog


    Quote from the book

    "

    Modeless Dialog Boxes

    Once you've mastered modal dialog boxes, you'll discover that modeless dialog boxes are just a variation on what you've already learned. Modal and modeless dialog boxes are more alike than they are different. The key differences between them include the following:

    • Whereas a modal dialog box is displayed by calling CDialog::DoModal, modeless dialog boxes are displayed with CDialog::Create. Unlike DoModal, which doesn't return until the dialog box is dismissed, Create returns as soon as the dialog box is created. Therefore, the dialog box is still displayed when Create returns.
    • Modeless dialog boxes are dismissed by calling DestroyWindow, not End-Dialog. You mustn't allow CDialog::OnOK or CDialog::OnCancel to be called on a modeless dialog box, because both call EndDialog.
    • Modal dialog classes are usually instantiated on the stack so that de-struction is automatic. Modeless dialog classes are instantiated with new so that the dialog object won't be destroyed prematurely. One way to ensure that the modeless dialog object is deleted when the dialog box is destroyed is to override CDialog::PostNcDestroy in the derived dialog class and execute a delete this statement.

    There are other differences between modal and modeless dialog boxes that MFC handles for you........"

    Thanks alot for the help Maritn, It is really appriciated.

    maldini



  • Dialog + Modeless