Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Commonly Overridden Member Functions 

The following table lists the most likely member functions to override in your CDialog-derived class.

Commonly Overridden Member Functions of Class CDialog
Member function Message it responds to Purpose of the override



Initialize the dialog box's controls.


BN_CLICKED for button IDOK

Respond when the user clicks the OK button.



Respond when the user clicks the Cancel button.

OnInitDialog, OnOK, and OnCancel are virtual functions. To override them, you declare an overriding function in your derived dialog class using the Properties window.

OnInitDialog is called just before the dialog box is displayed. You must call the default OnInitDialog handler from your override — usually as the first action in the handler. By default, OnInitDialog returns TRUE to indicate that the focus should be set to the first control in the dialog box.

OnOK is typically overridden for modeless but not modal dialog boxes. If you override this handler for a modal dialog box, call the base class version from your override — to ensure that EndDialog is called — or call EndDialog yourself.

OnCancel is usually overridden for modeless dialog boxes.

For more information about these member functions, see class CDialog in the MFC Reference and the discussion on Life Cycle of a Dialog Box.

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.