• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

Closing a Window From Another Window

I have Developed an MDI Application using AppWiz. I have created two views which are inherited frim CFormView. Now I want to close First view from Second view (I mean in the code of second view) How it is Possible.
0
kakamna
Asked:
kakamna
1 Solution
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

Assume two views class  as CMyView1 and CMyView2. U want to close the view1 from view2. The app class is CMyApp

Then follow the steps.
1. Open MyApp.h and include MyView1.h
2. Then add a pointer as public as
    CMyView1 *m_MyView1;
3. open MyApp.cpp and in the constructor
     m_MyView1 = NULL;
4. open the MyView1.cpp in OnInitialUpdate() do
    CMyApp *pApp = (CMyApp *)AfxGetApp();
    pApp->m_MyView1 = this;
5. In MyView2.cpp whenever u want to destroy the view1 do
    CMyApp *pApp = (CMyApp *)AfxGetApp();
    if(pApp->m_MyView1)
    pApp->m_MyView1->SendMessage(WM_CLOSE,0,0);
    or
    if(pApp->m_MyView1)
    pApp->m_MyView1->DestroyWindow(..);
    or call the function of MyView1 which closes the view and cleans up the memory. the set the pointer to null.

Thats it. Hope this helps.
VinExpert
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now