Create mode-free dialog box

Source: Internet
Author: User

 

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 ()
  
·{
  
·

Related Article

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.