title: MFC OK/Cancel Dialog Button Override?
body: <p><strong>Language:</strong> C++</p>
  
  <p><strong>Development Environment:</strong> Microsoft Visual C++</p>
  
  <p><strong>Libraries Used:</strong> MFC</p>
  
  <p>Pretty new to MFC, so bear with me. I have a dialog that is launched via DoModal(). I'm attempting to add buttons to this dialog that will replace the default "OK" and "Cancel" buttons. Right now, I can't quite figure out how to do this. I deleted the OK and Cancel buttons and added new ones with new IDs, added event handlers, and just some simple code for them to execute upon being pressed, but I couldn't get it to work.</p>
  
  <p>I suspect it has something to do with the fact that DoModal() expects responses from OK or Cancel, but nothing else. I'm not really sure though. Any help would be greatly appreciated!</p>
  
  <p>EDIT: Stripped down code added for reference.</p>
  
  <pre><code>void CPrefsDlg::Launch() {
  
  [ ... ]
  
    CSAPrefsDialog dlg;
  
    INT_PTR nRet = -1;
    nRet = dlg.DoModal();
  
    // Handle the return value from DoModal
    switch ( nRet )
    {
    case -1: 
       AfxMessageBox("Dialog box could not be created!");
       break;
    case IDABORT:
       // Do something
       break;
    case IDOK: // This works just fine.
       exit(0);
       break;
    case IDSAVEONE: // This does not work.
       MessageBox("Save One");
       break;
    default:
       break;
    };
  }
  
  void CPrefsDlg::SaveOne()
  {
  // I tried adding in my own handler for 'Save One'...this does not work.
  MessageBox("Save one");
  }
  </code></pre>