This documentation is archived and is not being maintained.


Called when the user clicks the OK button (the button with an ID of IDOK).

virtual void OnOK( );

Override this member function to perform the OK button action. If the dialog box includes automatic data validation and exchange, the default implementation of this member function validates the dialog-box data and updates the appropriate variables in your application.

If you implement the OK button in a modeless dialog box, you must override the OnOK member function and call DestroyWindow from within it. Don't call the base-class member function, because it calls EndDialog, which makes the dialog box invisible but does not destroy it.

/* MyDialog.cpp */
#include "MyDialog.h"

void CMyDialog::OnOK() 
   // TODO: Add extra validation here
   // Ensure that your UI got the necessary input 
   // from the user before closing the dialog. The 
   // default OnOK will close this.
   if ( m_nMyValue == 0 ) // Is a particular field still empty?
      AfxMessageBox("Please enter a value for MyValue");
      return; // Inform the user that he can't close the dialog without
              // entering the necessary values and don't close the 
              // dialog.

   CDialog::OnOK(); // This will close the dialog and DoModal will return.