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. Processing the 'X' button in a SDI

Processing the 'X' button in a SDI

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
14 Posts 4 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.
  • T Offline
    T Offline
    Tara14
    wrote on last edited by
    #1

    Hello, I have created a SDI with CFormView as the view (VC++6). I would like to add some code to do something when the 'X' button of the document is pressed. In a Dialog box we process the WM_CLOSE message. Please can you tell me how to do it in a SDI document? Thanks.

    _


    Fortitudine Vincimus!_

    G D 2 Replies Last reply
    0
    • T Tara14

      Hello, I have created a SDI with CFormView as the view (VC++6). I would like to add some code to do something when the 'X' button of the document is pressed. In a Dialog box we process the WM_CLOSE message. Please can you tell me how to do it in a SDI document? Thanks.

      _


      Fortitudine Vincimus!_

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

      Process the WM_SYSCOMMAND[^] notification; look for wParam set to SC_CLOSE.


      Software Zen: delete this;

      Fold With Us![^]

      T 1 Reply Last reply
      0
      • G Gary R Wheeler

        Process the WM_SYSCOMMAND[^] notification; look for wParam set to SC_CLOSE.


        Software Zen: delete this;

        Fold With Us![^]

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

        Thank you for your reply. I tried to process the WM_SYSCOMMAND in MyAppDoc.cpp and then in MyAppView.cpp, but it is not working. The command is not even listed in the class wizard. What do i do?

        _


        Fortitudine Vincimus!_

        G 1 Reply Last reply
        0
        • T Tara14

          Thank you for your reply. I tried to process the WM_SYSCOMMAND in MyAppDoc.cpp and then in MyAppView.cpp, but it is not working. The command is not even listed in the class wizard. What do i do?

          _


          Fortitudine Vincimus!_

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

          You'll need to add an OnSysCommand()[^] handler to your view class, and look for the nID value to be set to SC_CLOSE. If you're writing an SDI application, you can also process this command in your CFrameWnd-derived[^] class.


          Software Zen: delete this;

          Fold With Us![^]

          T 1 Reply Last reply
          0
          • G Gary R Wheeler

            You'll need to add an OnSysCommand()[^] handler to your view class, and look for the nID value to be set to SC_CLOSE. If you're writing an SDI application, you can also process this command in your CFrameWnd-derived[^] class.


            Software Zen: delete this;

            Fold With Us![^]

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

            The view is a CFormView. Would that be any problem. I added OnSysCommand() in my CFomView class. I put a message box there. But it seems like the control just does not go there. Sigh!!

            _


            Fortitudine Vincimus!_

            M 1 Reply Last reply
            0
            • T Tara14

              The view is a CFormView. Would that be any problem. I added OnSysCommand() in my CFomView class. I put a message box there. But it seems like the control just does not go there. Sigh!!

              _


              Fortitudine Vincimus!_

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

              The 'X' button is on the frame window not the form window. Try handling it in the frame window class instead. Mark

              T 1 Reply Last reply
              0
              • M Mark Salsbery

                The 'X' button is on the frame window not the form window. Try handling it in the frame window class instead. Mark

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

                I added the WM_CLOSE command in my MainFrame class. But now the problem is that I am not able to retrive data from the input boxes of my CMyFormView. The program Asserts when GetWindowText is called.

                void CMainFrame::OnClose()
                {
                CMyFormView pFV;
                pFV.OnAppExit();
                // the function OnAppExit in the CFormView derived class, CMyFormView
                // has the codes for taking and saving in data form many input boxes using GetWindowText
                // the program Asserts when GetWindowText is called in CMyFormView
                CFrameWnd::OnClose();
                }

                _


                Fortitudine Vincimus!_

                M 1 Reply Last reply
                0
                • T Tara14

                  I added the WM_CLOSE command in my MainFrame class. But now the problem is that I am not able to retrive data from the input boxes of my CMyFormView. The program Asserts when GetWindowText is called.

                  void CMainFrame::OnClose()
                  {
                  CMyFormView pFV;
                  pFV.OnAppExit();
                  // the function OnAppExit in the CFormView derived class, CMyFormView
                  // has the codes for taking and saving in data form many input boxes using GetWindowText
                  // the program Asserts when GetWindowText is called in CMyFormView
                  CFrameWnd::OnClose();
                  }

                  _


                  Fortitudine Vincimus!_

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

                  How about this...

                  void CMainFrame::OnClose()
                  {
                  CMyFormView *pFV = (CMyFormView *)GetActiveView();
                  pFV->OnAppExit();
                  CFrameWnd::OnClose();
                  }

                  T 1 Reply Last reply
                  0
                  • M Mark Salsbery

                    How about this...

                    void CMainFrame::OnClose()
                    {
                    CMyFormView *pFV = (CMyFormView *)GetActiveView();
                    pFV->OnAppExit();
                    CFrameWnd::OnClose();
                    }

                    T Offline
                    T Offline
                    Tara14
                    wrote on last edited by
                    #9

                    Yipee!! It worked!! Thanks a billion!! GetActiveView() - so thats the way. Create an object of the view and then set the focus on it. Thank you once again.

                    _


                    Fortitudine Vincimus!_

                    M 2 Replies Last reply
                    0
                    • T Tara14

                      Hello, I have created a SDI with CFormView as the view (VC++6). I would like to add some code to do something when the 'X' button of the document is pressed. In a Dialog box we process the WM_CLOSE message. Please can you tell me how to do it in a SDI document? Thanks.

                      _


                      Fortitudine Vincimus!_

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

                      Tara14 wrote:

                      I have created a SDI with CFormView as the view (VC++6). I would like to add some code to do something when the 'X' button of the document is pressed.

                      What's wrong with the app's ExitInstance() method? You could also handle it in the frame's DestroyWindow() method.


                      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                      "Judge not by the eye but by the heart." - Native American Proverb

                      T 1 Reply Last reply
                      0
                      • D David Crow

                        Tara14 wrote:

                        I have created a SDI with CFormView as the view (VC++6). I would like to add some code to do something when the 'X' button of the document is pressed.

                        What's wrong with the app's ExitInstance() method? You could also handle it in the frame's DestroyWindow() method.


                        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                        "Judge not by the eye but by the heart." - Native American Proverb

                        T Offline
                        T Offline
                        Tara14
                        wrote on last edited by
                        #11

                        DavidCrow wrote:

                        What's wrong with the app's ExitInstance() method?

                        Dont know about that.

                        DavidCrow wrote:

                        You could also handle it in the frame's DestroyWindow() method.

                        The problem with DestroyWindow is that it closes off the application. I put a MessageBox there and checked how it worked. The application closes and then the MessageBox is displayed. Whereas I need to give the user some choises before the application closes.

                        _


                        Fortitudine Vincimus!_

                        1 Reply Last reply
                        0
                        • T Tara14

                          Yipee!! It worked!! Thanks a billion!! GetActiveView() - so thats the way. Create an object of the view and then set the focus on it. Thank you once again.

                          _


                          Fortitudine Vincimus!_

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

                          Tara14 wrote:

                          Yipee!! It worked!! Thanks a billion!!

                          Cool! :)

                          Tara14 wrote:

                          GetActiveView() - so thats the way. Create an object of the view and then set the focus on it.

                          The view object already existed. You just needed a pointer to the one in existence, not a new object. The assertion was from the uncreated new object (no HWNDs). Glad it's working! Mark

                          1 Reply Last reply
                          0
                          • T Tara14

                            Yipee!! It worked!! Thanks a billion!! GetActiveView() - so thats the way. Create an object of the view and then set the focus on it. Thank you once again.

                            _


                            Fortitudine Vincimus!_

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

                            By the way, if you want to give the user choices before closing then give the user the choices BEFORE calling CFrameWnd::OnClose(). Only call the base class if the user chooses to exit the app. If the user cancels or chooses to continue, just return from your OnClose() method. Mark

                            T 1 Reply Last reply
                            0
                            • M Mark Salsbery

                              By the way, if you want to give the user choices before closing then give the user the choices BEFORE calling CFrameWnd::OnClose(). Only call the base class if the user chooses to exit the app. If the user cancels or chooses to continue, just return from your OnClose() method. Mark

                              T Offline
                              T Offline
                              Tara14
                              wrote on last edited by
                              #14

                              OK. Thank you.

                              _


                              Fortitudine Vincimus!_

                              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