Create and close the VC ++ MFC subdialog box.

Source: Internet
Author: User

Create and close the VC ++ MFC subdialog box.

Main form

void CMoshiwindowDlg::OnButton1() {    // TODO: Add your control notification handler code here    CDialogproty dlg;     dlg.DoModal();     m_text.SetWindowText(dlg.text);}

Subform:

1. header file declaration Variables

2.

Void CDialogproty: OnButton1 () {// TODO: Add your control notification handler code here m_text.GetWindowText (text); CDialog: EndDialog (0); // end dialog box}

1. Display Mode dialog box:

CDialogDemo dlg;dlg.DoModal();

2. Show the non-mode dialog box:

CDialogDemo *dlg=new CDialogDemo(this); dlg->Create(IDD_GENERAL_CONTROL); dlg->ShowWindow(SW_SHOW);

Ii. Close the dialog box:

1. CDialog: OnOK (); // press the OK button to press cdicel: OnCancel (); // The cancel button is pressed.

2. CDialog: DestoryWindow ();

3. CDialog: EndDialog (0 );

Note: CDialog: CloseWindow (); only minimizes the dialog box.
PostMessage (WM_CLOSE)

Function details:

CloseWindow

Function: This function minimizes the specified window but does not destroy it. Function prototype: BOOL CloseWindow (HWND hWnd); parameter: hWnd: handle of the window to be minimized. Return Value: If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To obtain more error information, call the GetLastError function. Note: The window size is minimized into an icon and moved to the icon area of the screen. The system displays the window icon instead of the window, and the window title is displayed under the icon. The application must use
The destroy window of the DestroyWindow function.

DestroyWindow

Function: destroys a 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 menu, clears the thread message queue, destroys the timer related to the window process, removes 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: handle of the window to be destroyed. Return Value: If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To obtain more error information, call the GetLastError function. Note: A thread cannot use this function to destroy windows created by other threads. If the window is a child window that does not have the WS_EX_NOPARENTNOTIFY style
The WM_PARENTNOTIFY message is sent to its parent window. Windows CE: this function will not send the WM_NCDESTROY message.

EndDialog

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: indicates the dialog box window to be cleared. NResult: Specifies the value returned by the function in the create dialog box to the application. Return Value: If the function call is successful, the returned value is a non-zero value. If the function call fails, the returned value is zero. To obtain the error message, call the GetLastError function. Note: The EndDialog function must be used to clear the dialog box created by DialogBox, DialogBoxParam, DialogBoxlndirect, and DialogBoxlndirectParam. The application calls the EndDialog function from within the dialog box application. This function cannot be used for other purposes. The dialog box application can call the EndDialog function at any time, even during WM_INITDIALOG message processing. If the application calls this function during WM_INTDIALOG message processing, the dialog box is cleared before the display and input focus are set. The EndDialog function does not immediately clear the dialog box. Instead, it sets a flag and allows the dialog box to apply the procedure to return control to the system. The system detects the flag before attempting to retrieve the next message from the application queue. If a flag has been set, the system suspends the message loop, clears the dialog box, and uses the value in nResUlt as the value returned from the function in the create 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.