Creation and destruction of child dialog boxes

Source: Internet
Author: User

1. Show dialog box

1.1 Display Mode dialog box:

Cdialogdemo Dlg;dlg. DoModal ();

1.2 Show non-modal dialog box:

Cdialogdemo *dlg=new Cdialogdemo (this); Dlg->create (Idd_general_control); Dlg->showwindow (Sw_show);

2. Destroy dialog box

1.cdialog::onok (); OK Button press Cdialog::oncancel (); The Cancel button is pressed

2.CDialog::D Estorywindow ();

3.cdialog::enddialog (IDD);

3. Close the dialog box in the modal dialog class

You can close the dialog box by PostMessage (Wm_close) in the modal dialog class. Close the MessageBox dialog box with the modal dialog box closed.

The reference code is as follows:

<span style= "FONT-SIZE:18PX;"     >bool Cimportdatapromptdialog::oninitdialog () {cdialog::oninitdialog ();     Todo:add Extra initialization here HANDLE hthread = Startimportdatathread ();  if (!hthread) {LOG ("Boot Import data thread failed")} return TRUE; Return TRUE unless you set the focus to a control//Exception:ocx property Pages should return FALSE} DWORD winap I Cimportdatapromptdialog::importdatathread (lpvoid Param) {cimportdatapromptdialog* Importdlg = (     cimportdatapromptdialog*) Param; if (Cimportlog::extractionxmldata (Importdlg->m_sxmlfilepath, Importdlg->m_sdbpath)) {ImportDlg->Messa         Gebox ("Import data Success", "platform", mb_iconinformation);     Importdlg->postmessage (WM_CLOSE);         } else {Importdlg->messagebox ("Failed to import data", "platform", mb_iconexclamation);     Importdlg->postmessage (WM_CLOSE); } return 0;     } HANDLE Cimportdatapromptdialog::startimportdatathread () {LOG ("Start import data Thread"); cwinthread*Hthread = AfxBeginThread ((afx_threadproc) Cimportdatapromptdialog::importdatathread, (LPVOID) this); return (Hthread->m_hthread); }</span>

4. A detailed explanation of several related important functions

4.1 CloseWindow

function function: The function minimizes the specified window, but does not destroy the window.
Function prototype: BOOL CloseWindow (HWND hwnd);

Parameter: hWnd: The handle of the window that will be minimized.
Return value: If the function succeeds, the return value is not 0, and if the function fails, the return value is zero. To get more error information, call the GetLastError function.
Note: The window size is minimized to an icon and moved to the icon area of the screen. The system displays the window's icon without displaying the window and displays the window caption under the icon. The application must use the DestroyWindow function to destroy the window.

4.2 DestroyWindow

function function: destroys the specified window. This function invalidates the window and removes its keyboard focus by sending Wm_destroy messages and Wm_ncdestroy messages. This function also destroys the window's menu, empties the thread's message queue, destroys the timer associated with the window procedure, unlocks the window's ownership of the Clipboard, and interrupts the view chain of the Clipboard.
Function prototype: BOOL DestroyWindow (HWND hwnd//Handle to Window to destroy);
HWnd: The handle of the window that will be destroyed.
Return value: If the function succeeds, the return value is not 0: If the function fails, the return value is zero. To get more error information, call the GetLastError function.
Note: A thread cannot use this function to destroy a window created by another thread. If this window is a child window that does not have a ws_ex_noparentnotify style, the window is destroyed and the wm_parentnotify message is sent to its parent window. Windows CE: This function will not send a Wm_ncdestroy message.

4.3 enddialog

function function: This function clears a modal dialog box and causes the system to abort any processing of the dialog box.
Function prototype: BOOL enddialog (HWND hdlg,int nresult);
Parameter: Hdlg: Represents the dialog window to be cleared. Nresult: Specifies the value to return to the application from the Create dialog box function.
Return value: If the function call succeeds, the return value is not 0, and the return value is zero if the function call fails. To get the error message, call the GetLastError function.
Note: dialog boxes created by the Dialogbox,dialogboxparam, Dialogboxlndirect, and Dialogboxlndirectparam functions must be cleared with the EndDialog function. The application calls the EndDialog function from within the dialog application, and the function cannot be used for other purposes. The dialog application can call the EndDialog function at any time, even during WM_INITDIALOG message processing. If the application calls the function during Wm_intdialog message processing, the dialog box is cleared before the display and input focus is set. The EndDialog function does not immediately clear the dialog box. Instead, it sets a flag and allows the dialog box application to return control to the system. The system detects flags before attempting to retrieve the next message from the application queue. If the flag is already set, the system aborts the message loop, clears the dialog box, and uses the value in Nresult as the value returned from the function that created the dialog box.

  • 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.