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. How to get close event of form view in MFC

How to get close event of form view in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structurestutorial
6 Posts 3 Posters 1 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 Offline
    A Offline
    Amrit Agr
    wrote on last edited by
    #1

    Hi developers, I requires to handle OnClose handle of a form view. I am building a heavy tree on it( based on thread ), and while doing that if i closed that form, application was getting crash, because that tree control has been destroyed. So that I have to capture it's close event so that I can prevent this event to proceed, i.e. to close that form. Thanks In Advance. Amrit Agrawal Software Developer

    S S 2 Replies Last reply
    0
    • A Amrit Agr

      Hi developers, I requires to handle OnClose handle of a form view. I am building a heavy tree on it( based on thread ), and while doing that if i closed that form, application was getting crash, because that tree control has been destroyed. So that I have to capture it's close event so that I can prevent this event to proceed, i.e. to close that form. Thanks In Advance. Amrit Agrawal Software Developer

      S Offline
      S Offline
      Schehaider_Aymen
      wrote on last edited by
      #2

      When you close that form, the syst will call its destructor so if you wanna handle the prob go to the

      YourFormClass()::~YourFormClass( )
      {
      //Type Code Here
      }

      "The Ultimate Limit Is Only Your Imagination."

      1 Reply Last reply
      0
      • A Amrit Agr

        Hi developers, I requires to handle OnClose handle of a form view. I am building a heavy tree on it( based on thread ), and while doing that if i closed that form, application was getting crash, because that tree control has been destroyed. So that I have to capture it's close event so that I can prevent this event to proceed, i.e. to close that form. Thanks In Advance. Amrit Agrawal Software Developer

        S Offline
        S Offline
        Software_Developer
        wrote on last edited by
        #3

        Use OnClose();

        void CmyApp::OnClose()
        {
        DestroyWindow();
        }

        Article containing an example of [ OnClose()] MSDN Docs:[CWnd::OnClose ] MSDN Docs:[CWnd::DestroyWindow ]

        S 1 Reply Last reply
        0
        • S Software_Developer

          Use OnClose();

          void CmyApp::OnClose()
          {
          DestroyWindow();
          }

          Article containing an example of [ OnClose()] MSDN Docs:[CWnd::OnClose ] MSDN Docs:[CWnd::DestroyWindow ]

          S Offline
          S Offline
          Schehaider_Aymen
          wrote on last edited by
          #4

          I totaly agree with u in case the user is running an SDI application but what if it is a MDI application ?

          "The Ultimate Limit Is Only Your Imagination."

          S 1 Reply Last reply
          0
          • S Schehaider_Aymen

            I totaly agree with u in case the user is running an SDI application but what if it is a MDI application ?

            "The Ultimate Limit Is Only Your Imagination."

            S Offline
            S Offline
            Software_Developer
            wrote on last edited by
            #5

            Yes, [MSDN] says: "To destroy an MDI Child window; use the virtual member function CWnd::DestroyWindow. Do not call the global ::DestroyWindow API to destroy an MDI Child window." It goes on to say: "In the case of C++ Windows objects that do perform auto-cleanup, you must call DestroyWindow. If you use operator delete directly, the MFC diagnostic memory allocator will alert you that you are freeing memory twice (the first call to delete as well as the indirect call to "delete this" in the auto-cleanup implementation of PostNcDestroy)."

            S 1 Reply Last reply
            0
            • S Software_Developer

              Yes, [MSDN] says: "To destroy an MDI Child window; use the virtual member function CWnd::DestroyWindow. Do not call the global ::DestroyWindow API to destroy an MDI Child window." It goes on to say: "In the case of C++ Windows objects that do perform auto-cleanup, you must call DestroyWindow. If you use operator delete directly, the MFC diagnostic memory allocator will alert you that you are freeing memory twice (the first call to delete as well as the indirect call to "delete this" in the auto-cleanup implementation of PostNcDestroy)."

              S Offline
              S Offline
              Schehaider_Aymen
              wrote on last edited by
              #6

              You scored Hight :thumbsup: .

              "The Ultimate Limit Is Only Your Imagination."

              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