if(Dialog.DoModal() == IDOK)
{
   //代码段

为什么把IDOK改成Button1的ID号就不行了呢?
我调试:
把IDOK改成Button1的ID或者Button1的函数最后加上OnOK()结果都没成功
何为????

解决方案 »

  1.   

    DoModal的返回值是退出时的id号,即IDOK或IDCancelButton1的函数最后加上OnOK()
    退出号还是IDOK
      

  2.   

    看msdn:
    Return ValueAn 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.
      

  3.   

    Example
    void CTstApp::OnAppAbout()
    {
      // Construct the dialog box by passing the 
      // identifier of the dialog template resource.
      CDialog aboutDlg(IDD_ABOUTBOX);  // Create and show the dialog box.
      int nRet = –1;
      nRet = aboutDlg.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:
        // Do something.
        break;
      case IDCANCEL:
        // Do something.
        break;
      default:
        // Do something.
        break;
      };
    }
      

  4.   

    谢谢各位的指点:
    我想我表达的不是很明确
    需求如下:
    当我新建一个对话框Dialog1时,就会默认产生两个按钮“确定”“取消”。
    现在我新建一个按钮“Button1”对应ID号“IDC_Button1”
    然后创建Dialog2,在Dialog2中想实现如下功能
    CDialog1 Dlg;
    if(Dlg.DoModal() == IDC_Button1)
    {
      //代码段
    }  
    如上却没有达到预期目的
    我知道这样是可以的
    CDialog1 Dlg;
    if(Dlg.DoModal() == IDOK)
    {
      //代码段
    }  
    我现在想用这种方法实现
    CDialog1 Dlg;
    if(Dlg.DoModal() == IDC_Button1)
    {
      //代码段
    }  
    请高手指点应该如何做???
    尽量具体点……谢谢!!!
      

  5.   

    这样足可以满足你想要的需求吧CDialog1 Dlg;
    if(Dlg.DoModal() == IDOK)
    {
      //代码段
      if(dlg.m_nType == IDC_Button1)
      {
      }
      

  6.   

    CDialog1 中定义一个
    int m_nType;
      

  7.   

    LZ不明白返回的不是IDOK就是IDCANCEL
      

  8.   

    前辈们DSMN说:
    ResCall this member function to invoke the modal dialog box and return the dialog-box result when done. 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.在这里:You can override these message-handler functions to alter their behavior.该如何理解呢???
      

  9.   

    EndDialog对适合楼主需求.
    首先在能保证对话框资源能正确释放的前提下,使用EndDialog函数即可.
    在按钮的响应函数中,调用EndDialog, 并传入按钮的ID号即可.具体过程, 如果写过 Win32 窗口程序的,应该就能明白了.
      

  10.   

    你把Domodal的 return value 和 ONCOMMAND消息搞混了
      

  11.   

    同一13楼。MFC 封装了 EndDialog,不够自由了。要是用 EndDialog 想返回什么都可以。
      

  12.   

     试试 :EndDialog(BOTTON1);
      

  13.   

    OnButton1()
    {
       EndDialog(IDC_BUTTON1);}
      

  14.   

    你想输入的这些代码都是在函数OnButton1这个响应事件里的吧,因而当你点击button1的时候其实就已经进入这个函数了,而Dlg.DoModal()的返回值只有IDOK和IDCANCLE即当你点击完button1的时候只会返回这两个值,因而需要是IDOK。
      应该很清楚了吧。。
      

  15.   

    +1
    An int value that specifies the value of the nResult parameter that is passed to the CDialog::EndDialog method, which is used to close the dialog box. The return value is –1 if the function cannot create the dialog box, or IDABORT if some other error occurs.