Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. DoModal() question?

DoModal() question?

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gofur Halmurat
    wrote on last edited by
    #1

    Hello, Can we use DoModal like this: CMyAlert *alert = new CMYAlert; alert->Create(CMYAlert::IDD,this); // ... some code if (alert->DoModal()==IDOK) { message("IDOK is clicked") } I want to know when IDOK is clicked On CMyAlert, Is there another way to know it? thanks

    M M G 3 Replies Last reply
    0
    • G Gofur Halmurat

      Hello, Can we use DoModal like this: CMyAlert *alert = new CMYAlert; alert->Create(CMYAlert::IDD,this); // ... some code if (alert->DoModal()==IDOK) { message("IDOK is clicked") } I want to know when IDOK is clicked On CMyAlert, Is there another way to know it? thanks

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      Gofur Halmurat wrote:

      I want to know when IDOK is clicked On CMyAlert,

      The CMyAlert dialog will have to notify the parent window that the OK button was clicked. either by passing a pointer to the parent to the dialog? or from the dialog, send a private message to the parent window saying the OK was clicked. What is your intention ? Do you want to have the dialog dismissed when the user clicks on Ok ?


      Maximilien Lincourt Your Head A Splode - Strong Bad

      G 1 Reply Last reply
      0
      • M Maximilien

        Gofur Halmurat wrote:

        I want to know when IDOK is clicked On CMyAlert,

        The CMyAlert dialog will have to notify the parent window that the OK button was clicked. either by passing a pointer to the parent to the dialog? or from the dialog, send a private message to the parent window saying the OK was clicked. What is your intention ? Do you want to have the dialog dismissed when the user clicks on Ok ?


        Maximilien Lincourt Your Head A Splode - Strong Bad

        G Offline
        G Offline
        Gofur Halmurat
        wrote on last edited by
        #3

        Hello, My parent window has a button, if i click the button the CMyAlert appears, and there is a button on CMyAlert, when i click the button on CMyAlert, Some changes will have to be done on parent window. How can i implement this? either by passing a pointer to the parent to the dialog? or from the dialog, send a private message to the parent window saying the OK was clicked. How can i implement this option? can u show me with examples? thanks

        T 1 Reply Last reply
        0
        • G Gofur Halmurat

          Hello, My parent window has a button, if i click the button the CMyAlert appears, and there is a button on CMyAlert, when i click the button on CMyAlert, Some changes will have to be done on parent window. How can i implement this? either by passing a pointer to the parent to the dialog? or from the dialog, send a private message to the parent window saying the OK was clicked. How can i implement this option? can u show me with examples? thanks

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          are you wanting a modeless dialog by any chances ? if not, then why don't you do the job when the modal dialog is closed ?


          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          G 1 Reply Last reply
          0
          • T toxcct

            are you wanting a modeless dialog by any chances ? if not, then why don't you do the job when the modal dialog is closed ?


            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            G Offline
            G Offline
            Gofur Halmurat
            wrote on last edited by
            #5

            Hello, yes, i want a modeless dialog by any changes

            T 1 Reply Last reply
            0
            • G Gofur Halmurat

              Hello, yes, i want a modeless dialog by any changes

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              so you mustn't use DoModal() (which, as its name states, creates a Modal Dialog). use Create() method to create it. to have the possibility to modify the window which spamn it, you must give it a pointer to its parent (commonly, this) as a constructor parameter also read This[^] good article about modeless dialogs.


              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              G 1 Reply Last reply
              0
              • T toxcct

                so you mustn't use DoModal() (which, as its name states, creates a Modal Dialog). use Create() method to create it. to have the possibility to modify the window which spamn it, you must give it a pointer to its parent (commonly, this) as a constructor parameter also read This[^] good article about modeless dialogs.


                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                G Offline
                G Offline
                Gofur Halmurat
                wrote on last edited by
                #7

                Thanks, that was what i was looking for. it helped me alot

                1 Reply Last reply
                0
                • G Gofur Halmurat

                  Hello, Can we use DoModal like this: CMyAlert *alert = new CMYAlert; alert->Create(CMYAlert::IDD,this); // ... some code if (alert->DoModal()==IDOK) { message("IDOK is clicked") } I want to know when IDOK is clicked On CMyAlert, Is there another way to know it? thanks

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  And no, you can't use Create() and DoModal() - you use one or the other, depending on whether you want a modal or a modeless dialog. Mark

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  1 Reply Last reply
                  0
                  • G Gofur Halmurat

                    Hello, Can we use DoModal like this: CMyAlert *alert = new CMYAlert; alert->Create(CMYAlert::IDD,this); // ... some code if (alert->DoModal()==IDOK) { message("IDOK is clicked") } I want to know when IDOK is clicked On CMyAlert, Is there another way to know it? thanks

                    G Offline
                    G Offline
                    Gary R Wheeler
                    wrote on last edited by
                    #9

                    No. By calling the Create function for your alert dialog, you've made it a modeless dialog. Calling DoModal() in this case will not work correctly. There are two solutions here. One, use the alert dialog modally:

                    CMyAlert *alert = new CMyAlert;
                    if (alert->DoModal() == IDOK) {
                    message("IDOK is clicked");
                    }
                    delete alert;

                    The second is to use your alert dialog as a modeless dialog, and have it send a user-defined message to the parent when the OK button is clicked, which is more complicated:

                    #define WM_MyAlertMessage (WM_USER + 1)
                    void CMyAlert::OnOK()
                    {
                    CWnd *parent = GetParent();
                    if (parent != NULL) {
                    parent->SendMessage(WM_MyAlertMessage,0,0);
                    }
                    }
                    BEGIN_MESSAGE_MAP(CMyParentWindow,CDialog)
                    ON_MESSAGE(WM_MyAlertMessage,OnMyAlertMessage)
                    END_MESSAGE_MAP()
                    LRESULT CMyParentWindow::OnMyAlertMessage(WPARAM /*wParam*/,LPARAM /*lParam*/)
                    {
                    message("IDOK is clicked");
                    return (LRESULT)0;
                    }


                    Software Zen: delete this;

                    Fold With Us![^]

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups