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 close a form?

how to close a form?

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
5 Posts 3 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.
  • P Offline
    P Offline
    panthal
    wrote on last edited by
    #1

    hi all, I'am having a new tool bar with 5 buttons in my appication. Each button opens a form. Now i should like to know how to automatically close the first form, when second form is opening ? like wise for all forms. so at present time only one form should be visible. can u please answer this question. thanks panthal

    H N 2 Replies Last reply
    0
    • P panthal

      hi all, I'am having a new tool bar with 5 buttons in my appication. Each button opens a form. Now i should like to know how to automatically close the first form, when second form is opening ? like wise for all forms. so at present time only one form should be visible. can u please answer this question. thanks panthal

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      You can send WM_CLOSE to them,how did you make them?

      P 1 Reply Last reply
      0
      • H Hamid Taebi

        You can send WM_CLOSE to them,how did you make them?

        P Offline
        P Offline
        panthal
        wrote on last edited by
        #3

        thanks for your reply, i'll try this. but How to send WM_CLOSE can u explain clearly please R u asking about that tool bar buttons?

        H 1 Reply Last reply
        0
        • P panthal

          thanks for your reply, i'll try this. but How to send WM_CLOSE can u explain clearly please R u asking about that tool bar buttons?

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          You must use of SendMessage.

          1 Reply Last reply
          0
          • P panthal

            hi all, I'am having a new tool bar with 5 buttons in my appication. Each button opens a form. Now i should like to know how to automatically close the first form, when second form is opening ? like wise for all forms. so at present time only one form should be visible. can u please answer this question. thanks panthal

            N Offline
            N Offline
            Nelek
            wrote on last edited by
            #5

            There is more than a solution. I make it like this.

            void CMainFrame::CloseMyFrame ()
            { //Get necessary connections
            CMDIChildWnd* pMDIActive = MDIGetActive();
            CDocument* pDoc = pMDIActive->GetActiveDocument();
            CMyView* pMyView;

            POSITION pos = pDoc->GetFirstViewPosition();
            while (pos)
            {	pMyView = (CMyView\*) pDoc->GetNextView(pos);
            	if (pMyView->IsKindOf(RUNTIME\_CLASS(CMyView)))
            	{	CFrameWnd\* pTempFrame = pMyView->GetParentFrame ();
            		pTempFrame->DestroyWindow ();
            		return;
            	}
            }
            return;
            

            }

            And, when I want to use it...

            extern CFPSApp theApp;
            CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
            pFrame->CloseMyFrame ();

            I forgot... I make it to close a specific Frame (that may be only ONCE at a time) For other that I may be more times at once opened, I like follows

            void CMainFrame::CloseMyFrame (CString szName)
            //....
            if ((pMyView->IsKindOf(RUNTIME_CLASS(CMyOtherView))) && (pMyView->m_pParent->m_szName == szName))
            //...

            This is because I use that views to modifify the parameters of an element. So I hold a pointer to the element that is being shown as a member variable in every window. So I get easy access to the data I have to show/modify and use it to differenciate between the 48 possible CFormViews that can be opened at once.

            Greetings. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

            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