MFC program to exit the program in a variety of interface functions of routing, top right "Cha Cha", "OK" (Enter key), "Cancel" to close the route (ESC key) function and other functions

 Auto-generated MFC dialog with "OK" and "Cancel" button. Respectively corresponding ID IDOK and IDCANCLE, the corresponding function of the OnOK () and OnCancle ().

MFC default Enter key to trigger a call to OnOK function, Esc key triggers calls to OnCancel function. It will cause the control to exit from the dialog box.

Disable Esc key to exit the function is very simple:

    1. Double-click the "Cancel" button, add the response function OnCancle ()

    2, the wizard generates a parent class to call commented out

       :: CEMDTTDlg the OnCancel void () {
            // the OnCancel the CDialog :: (); // call the parent class disabled
       }

  

The default dialog two buttons are used for the ID IDOK and IDCANCEL, both of which are in winuser.h predefined system standard controls ID.
For standard ID, without overloading MFC will automatically call the appropriate treatment of the parent class.
For example IDOK mapped to CDialog :: OnOK () function, IDCANCEL mapped to CDialog :: OnCancel ().

Source of these two functions as follows:
void the OnOK the CDialog :: ()
{
    IF (UpdateData (TRUE)!)
    {
        The TRACE (traceAppMsg, 0, "Dialog Termination During UpdateData failed \ n-."); 
     // Will The routine SET UpdateData Item to correct Focus
        return;
    }
    the EndDialog (IDOK);
}

the OnCancel the CDialog :: void ()
{
    the EndDialog (the IDCANCEL);
}
can be seen that two click this button, will call the EndDialog () to close the dialog, but a different return value.
EndDialog () function calls DestroyWindow () function, DestroyWindow () function WM_DESTROY has sent a message, the message handler is OnDestroy (), a function last the lifetime of the dialog is PostNcDestroy () function.

Pork on a skewer that point it is first sent to the dialog WM_CLOSE message () function is handled by the OnClose, it calls DestroyWindow (), followed the same route as above.
You can see the point of pork on a skewer when bypassed OnOK () and OnCancel ().

 

Summary about:
turn off Route 1. The device is "OK" (the Enter key), "Cancel" (ESC key) is
OnOK () or OnCancel () ---> EndDialog () ---> DestroyWindow () - -> OnDestroy () ---> the PostNcDestroy ()
2. point "close" to close the route to the title bar buttons
OnClose () ---> OnCancel () ---> EndDialog () ---> DestroyWindow () - -> OnDestroy () ---> PostNcDestroy ()


note,

These are all functions mentioned above can be overloaded by adding your own code when overloaded, you should call the function to the parent class CDialog same name correct route to go, otherwise it will not shut the dialog box.
For example, a heavy-duty off small cross
void :: CAboutDlg the OnClose ()
{
    // the TODO: this addition message handler code, and / or invoke the default value
    DoSomthing (0; // implementation of their determination, etc.

    // CDialog :: OnClose (); // parent class the wizard generates calls to the Notes, then you can not shut the dialog box.
}


Supplement,
point pork on a skewer will send WM_CLOSE message, if you need to override it should in the Properties window of the dialog box, select the WM_CLOSE message to add a message handler.
The VS IDE automatically add the following three sections:
1. of xxx.h file, the class declaration is added the OnClose () function declaration
   afx_msg void the OnClose ();
2. xxx.cpp file, a join message map macro
   ON_WM_CLOSE () // for Windows standard messages, which are short format.
3. xxx.cpp document, adding the function body
   void :: CMyDlg the OnClose ()
  {
      the CDialog :: the OnClose ();
  }

3 If the above are normal, then it is mapped to cross on the OnClose () a.
If the skewer is mapped to OnCancel () personally feel that there are two possibilities,
first, the lack of ON_WM_CLOSE () macro, but more than a ON_BN_CLICKED (IDCLOSE, & CMyDlg :: OnCancel ) macro
second, called OnCancel in OnClose () in ( )

Published 15 original articles · won praise 20 · views 10000 +

Guess you like

Origin blog.csdn.net/ZDT_zdh/article/details/103079834