问题:
1)  在SDI程序中,创建一模态对话框后,点击“退出”按钮,会显示确认MessageBox。再点击“取消”按钮时,要求返回到模态对话框,怎么写代码呀?(我参考了《技术内幕》CHAPTER 7)
类似下面的样子,但不是这样的。大家替我修改一下。void CEx07bView::OnLButtonDown(UINT nFlags, CPoint point) 
{
CSpecialFileDialog dlgFile(TRUE, NULL, "*.obj");
CString strMessage;
int nModal = dlgFile.DoModal();
if (nModal == IDCANCEL) {
strMessage.Format(
"确实要退出模态对话框吗?",
dlgFile.m_strFilename);
if (AfxMessageBox(strMessage, MB_YESNO) == IDNO) {

                      .....// }
}
}2 ) 模态对话框好象只能处理“OK”“CANCEL”按钮,若出现其他按钮时,怎么处理这一事件而不退出模态对话框?[[  注:(1)若用DoModal()的返回值是EndDialog()函数的参数判断,也是要模态对话框退出时才可以判断的。所以此路不通。 (2)虽然可以用自定义自定义消息。
#define WM_USERAPPLY WM_USER+5
 我想尝试在模态对话框退出前有没有办法不定义消息而截获按钮事件?]]大家可以看我昨天发的帖子:
http://community.csdn.net/Expert/topic/3964/3964423.xml?temp=.7109796

解决方案 »

  1.   

    可以把确认MessageBox放在OnCancel中处理
      

  2.   

    TO mousubin(msb): 
       这个方法不错.
    我看了MSDN.好象不自定义消息,就没有办法在模态对话框运行时发送消息到父窗口:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cdialog.3a3a.domodal.asp
    MFC Library Reference   CDialog::DoModal
    Call this member function to invoke the modal dialog box and return the dialog-box result when done.virtual INT_PTR DoModal( );
    Return Value
    An int value that specifies the value of the nResult parameter that was passed to the CDialog::EndDialog member function, which is used to close the dialog box. The return value is –1 if the function could not create the dialog box, or IDABORT if some other error occurred, in which case the Output window will contain error information from GetLastError.Res
    This member function handles all interaction with the user while the dialog box is active. This is what makes the dialog box modal; that is, the user cannot interact with other windows until the dialog box is closed.If the user clicks one of the pushbuttons in the dialog box, such as OK or Cancel, a message-handler member function, such as OnOK or OnCancel, is called to attempt to close the dialog box. The default OnOK member function will validate and update the dialog-box data and close the dialog box with result IDOK, and the default OnCancel member function will close the dialog box with result IDCANCEL without validating or updating the dialog-box data. You can override these message-handler functions to alter their behavior.Note   PreTranslateMessage is now called for modal dialog box message processing.
      

  3.   

    在对话框dlgFile的OnCancel中弹出MessageBox询问!!!
      

  4.   

    在对话框中写你的退出按钮函数
    void CMyDlg::OnExit() 
    {
       if(IDOK==AfxMessageBox("确定退出吗",MB_OKCANCEL))
    CDialog::OnCancel(); }还有:成功后别忘了给分哦
      

  5.   

    (接上贴)
    当然你的视图类中只需要下面代码就可以啦
    void CEx07bView::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    CSpecialFileDialog dlgFile(TRUE, NULL, "*.obj");
    dlgFile.DoModal();
    }
      

  6.   

    这个问题解决了.过一会儿就给分.
    大家看看:
    http://community.csdn.net/Expert/topic/3975/3975640.xml?temp=.3363001