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. closing dialog by clicking on it

closing dialog by clicking on it

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
12 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.
  • A Antony M Kancidrowski

    Why not call EndDialog() :-D Ant.

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

    work fine :-D thank you anyway, do you have an idea of the reasons OnClose() doesn't work ? would the virtual BOOL CWnd::DestroyWindow(void); have work better too ?


    TOXCCT >>> GEII power

    A 1 Reply Last reply
    0
    • T toxcct

      hi everybody, i designed a dialog which i'd like to close by right-click anywhere inside it. For that, i overrided the WM_RBUTTONDOWN an i associated to it the following code :

      void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
      this->OnClose();
      CDialog::OnRButtonDown(nFlags, point);
      }

      Unfortunately, it doesn't work :( i've been obliged to create a "OK" button which i hide, and instead of calling OnClose(), i call OnOk() :

      void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
      this->OnOk();
      CDialog::OnRButtonDown(nFlags, point);
      }

      It now works, but i don't like this way of contourning the problem. can anybody tell me why my first code doesn't work, and what i could do do resolve th pb ...?


      TOXCCT >>> GEII power

      D Offline
      D Offline
      dart13
      wrote on last edited by
      #4

      You can do it like this: void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_CLOSE); CDialog::OnRButtonDown(nFlags, point); } and then in OnClose(), you can do the cleanup. OnClose() is called after WM_CLOSE is processed, I guess. So it doesn't actually close the window.

      T 1 Reply Last reply
      0
      • D dart13

        You can do it like this: void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_CLOSE); CDialog::OnRButtonDown(nFlags, point); } and then in OnClose(), you can do the cleanup. OnClose() is called after WM_CLOSE is processed, I guess. So it doesn't actually close the window.

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

        ok. yes, i was calling OnClose() to close, but it is called when the windows is about to be closed... ;) thx


        TOXCCT >>> GEII power

        1 Reply Last reply
        0
        • T toxcct

          hi everybody, i designed a dialog which i'd like to close by right-click anywhere inside it. For that, i overrided the WM_RBUTTONDOWN an i associated to it the following code :

          void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
          this->OnClose();
          CDialog::OnRButtonDown(nFlags, point);
          }

          Unfortunately, it doesn't work :( i've been obliged to create a "OK" button which i hide, and instead of calling OnClose(), i call OnOk() :

          void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
          this->OnOk();
          CDialog::OnRButtonDown(nFlags, point);
          }

          It now works, but i don't like this way of contourning the problem. can anybody tell me why my first code doesn't work, and what i could do do resolve th pb ...?


          TOXCCT >>> GEII power

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #6

          Any reason why OnRButtonDown() is calling OnLButtonDown()? toxcct wrote: Unfortunately, it doesn't work Because EndDialog() is not being called. Take a look at CDialog::OnOK() and CDialog::OnCancel(). Notice how they both call EndDialog().


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          T 1 Reply Last reply
          0
          • D David Crow

            Any reason why OnRButtonDown() is calling OnLButtonDown()? toxcct wrote: Unfortunately, it doesn't work Because EndDialog() is not being called. Take a look at CDialog::OnOK() and CDialog::OnCancel(). Notice how they both call EndDialog().


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

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

            DavidCrow wrote: Any reason why OnRButtonDown() is calling OnLButtonDown()? Nop, mistake from my own. fixed now. thanks for the directions to see.


            TOXCCT >>> GEII power

            1 Reply Last reply
            0
            • T toxcct

              work fine :-D thank you anyway, do you have an idea of the reasons OnClose() doesn't work ? would the virtual BOOL CWnd::DestroyWindow(void); have work better too ?


              TOXCCT >>> GEII power

              A Offline
              A Offline
              Antony M Kancidrowski
              wrote on last edited by
              #8

              You would use DestroyWindow() for a modeless dialog and EndDialog() for a modal dialog. OnClose() will call DestroyWindow() anyway IIRC. However without looking I can not recall why they are done differently. Now I will have to look and find out ;) Ant.

              A 1 Reply Last reply
              0
              • A Antony M Kancidrowski

                You would use DestroyWindow() for a modeless dialog and EndDialog() for a modal dialog. OnClose() will call DestroyWindow() anyway IIRC. However without looking I can not recall why they are done differently. Now I will have to look and find out ;) Ant.

                A Offline
                A Offline
                Antony M Kancidrowski
                wrote on last edited by
                #9

                From MSDN CDialog::OnOK "If you implement the OK button in a modeless dialog box, you must override the OnOK method and call DestroyWindow from within it. Do not call the base-class method, because it calls EndDialog, which makes the dialog box invisible but does not destroy it." Had to look this up so here for your benefit too. :) Ant.

                T 1 Reply Last reply
                0
                • A Antony M Kancidrowski

                  From MSDN CDialog::OnOK "If you implement the OK button in a modeless dialog box, you must override the OnOK method and call DestroyWindow from within it. Do not call the base-class method, because it calls EndDialog, which makes the dialog box invisible but does not destroy it." Had to look this up so here for your benefit too. :) Ant.

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

                  :-D thx very much :cool:


                  TOXCCT >>> GEII power

                  1 Reply Last reply
                  0
                  • T toxcct

                    hi everybody, i designed a dialog which i'd like to close by right-click anywhere inside it. For that, i overrided the WM_RBUTTONDOWN an i associated to it the following code :

                    void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
                    this->OnClose();
                    CDialog::OnRButtonDown(nFlags, point);
                    }

                    Unfortunately, it doesn't work :( i've been obliged to create a "OK" button which i hide, and instead of calling OnClose(), i call OnOk() :

                    void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
                    this->OnOk();
                    CDialog::OnRButtonDown(nFlags, point);
                    }

                    It now works, but i don't like this way of contourning the problem. can anybody tell me why my first code doesn't work, and what i could do do resolve th pb ...?


                    TOXCCT >>> GEII power

                    N Offline
                    N Offline
                    Naren Neelamegam
                    wrote on last edited by
                    #11

                    [Message Deleted]

                    T 1 Reply Last reply
                    0
                    • N Naren Neelamegam

                      [Message Deleted]

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

                      thank you but repost. no need to overload the servers...


                      TOXCCT >>> GEII power

                      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