MFC dialog Box Project. The main dialog box is an instance of Class A
A contains a member variable pointer *b B is also a dialog box class
Let's use this pointer to enable the turn off and destroy of the child dialog box.
The first is the structure of the preparatory work, so that two classes can call each other
Add DIALOG_EX Class B
A
Include "B.h"
Public:
*b M_son;
Init ()
{
this->m_son-=null;
}
B
Class A;
Public
*a M_father;
B.cpp
#include "A.h"
The first section creates (and displays) a child dialog box
A.cpp
if (this->m_son!=null)
{
:: AfxMessageBox ("M_son not equal to NULL, no need to create");
}
Else
{
:: AfxMessageBox ("M_son null is being created");
This->m_son=new B; //Create in Heap
This->m_son->create (Idd_son);
this->m_son->m_father=this; //Establish contact
}
this->m_son->showwindow (sw_show);
The second part closes the Do not destroy child dialog box
B.cpp
void B::oncancel ()
{
This->m_father->delete_son ();
Cdialogex::oncancel ();
}
The third part closes and destroys the child dialog box
B.cpp
void B::oncancel ()
{
This->m_father->delete_son ();
Cdialogex::oncancel ();
}
A.cpp
void A::d Elete_son ()
{
Delete this->m_son;
this->m_son=null;
}
Use the dialog pointer to control the create close and Clear Child dialog box