How to trap default buttons of a dialog box without  writing handler?

Let's say you have a dialog box with its default buttons IDOK, IDCANCEL, and IDABORT. You can trap these buttons without writing corresponding handler. 

void CMyApp::OnDlg()

{

   

   CMyDialog dlg; 

   int nRet = dlg.DoModal();

   switch ( nRet )

   {

   case -1: 

      break;

   case IDOK:

      // Write your code here

      break;

   case IDCANCEL:

      // Write your code here

      break;

   case IDABORT:

      // Write your code here

      break;

   default:

      break;

   };

}