Use the dialog pointer to control the create close and Clear Child dialog box

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.