The dialog box without mode is different from the dialog box with mode. After creation, other windows can continue to receive user input. Therefore, the dialog box without mode is similar to a pop-up window. The create mode dialog box needs to be called.
BOOL CDialog: Create (UINT nIDTemplate, CWnd * pParentWnd = NULL); call
BOOL CDialog: ShowWindow (SW_SHOW);. Otherwise, the dialog box without mode is invisible. The related code is as follows:
Void CYourView: OnOpenDlg (void)
{
/* Assume that IDD_TEST_DLG is the ID of the defined dialog box resource */
CTestDlg * dlg = new CTestDlg;
Dlg-> Create (IDD_TEST_DLG, NULL );
Dlg-> ShowWindows (SW_SHOW );
/* Do Not Call delete dlg ;*/
}
In the above Code, a dialog box object is generated, and the object is not destroyed when the function is exited. If the object is destroyed at this time (when the object is destroyed, the window is destroyed at the same time), and the dialog box is displayed, an error occurs. This raises the question: when to destroy the object. I often use two methods:
- Destroy yourself when exiting the dialog box:Reload in the dialog boxOnOK and OnCancel call the function with the same name as the parent class in the function, then call DestroyWindow () to force destroy the window, map the WM_DESTROY message in the dialog box, and call delete this in the message processing function; forcibly delete an object. The related code is as follows:
·Void CTestDlg1: OnOK ()
·{
·CDialog: OnOK ();
·DestroyWindow ();
·}
·
·Void CTestDlg1: OnCancel ()
·{
·