By sending messages to the father window, you need to destroy them: First, you need to define a message for notification, then map the WM_DESTROY message in the dialog box, and call the message send function in the message processing function to notify other windows. Use the ON_MESSAGE mapping to process the function in the window to remove the dialog object in the message processing function. The relevant code is as follows: / * Change the relevant files of the dialog * /
Ctestdlg2 :: Ctestdlg2 (CWND * PParent / * = null * /)
: Cdialog (ctestdlg2 :: IDd, pparent)
{/ * m_pparent is a member variable for saving the pointer to the notification window.
So the pointer cannot be a temporary pointer * /
Assert (pparent);
m_pparent = pParent;
// {{AFX_DATA_INIT (ctestdlg2)
// Note: The classwizard will add member initialization here
//}} AFX_DATA_INIT
}
Void ctestdlg2 :: onok ()
{
CDIALOG :: Onok ();
DESTROYWINDOW ();
}
Void ctestdlg2 :: oncancel ()
{
CDIALOG :: oncancel ();
DESTROYWINDOW ();
}
Void ctestdlg2 :: ONDESTROY ()
{
CDIALOG :: ONDESTROY ();
/ * Send a message to other windows, send your own pointer as a parameter * /
m_pparent-> Postmessage (WM_DELETE_DLG, (WPARAM) THIS);
}
/ * Add a message mapping in the message receiving window * /
/ * Add a function definition in the header file * /
AFX_MSG Long OnDeldlgmsg (WPARAM WP, LPARAM LP);
/ * Add message mapping code * /
ON_MESSAGE (WM_DELETE_DLG, ONDLDLGMSG)
END_MESSAGE_MAP ()
/ * Implement message processing function * /
Long CMY53_S1View :: Ondeldlgmsg (WPARAM WP, LPARAM LP)
{
Delete (ctestdlg2 *) wp;
Return 0;
}
/ * Create a dialog * /
Void CMY53_S1View :: ontest2 ()
{
CTESTDLG2 * DLG = New ctestdlg2 (this);
DLG-> CREATE (IDD_TEST_DLG_2);
DLG-> ShowWindow (sw_show);
}
In this method, we use a message to notify, and use messages in the Window system to notify and deliver data.
Another role of the same non-Mode dialog can also be used to reflect other windows in time when the user changes in the dialog box. The following code demonstrates the input of a paragraph in the dialog, and then updates it to the display area of the view, the same also utilizes messages to notify and data delivery.
/ * Remove the data in the dialog, send messages and data to other windows, send the data pointer as a parameter * /
Void ctestdlg2 :: oncommbtn ()
{
Char Szout [30];
Getdlgitemtext (IDC_OUT, SZOUT, 30);
m_pparent-> sendMessage (WM_DLG_NOTIFY, (WPARAM) SZOUT;
}
/ * In the message receiving window * /
/ * Mapping message processing function * /
ON_MESSAGE (WM_DLG_NOTIFY, ONDLGNOTIFYMSG)
/ * Draw a string m_szout * /
Void CMY53_S1View :: Ondraw (CDC * PDC)
{
CMY53_S1DOC * PDOC = getDocument (); assert_valid (pdoc);
// Todo: Add Draw Code for Native Data HERE
PDC-> TextOut (0,0, "display string");
PDC-> Textout (0, 20, m_szout);
}
/ * Process the notification message, save the information and update the display * /
Long CMY53_S1View :: OndlGnotifyMSG (WPARAM WP, LPARAM LP)
{
m_szout = (char *) WP;
Invalidate ();
Return 0;
}