添加了一个Dialog的资源,为其创建了一个基于CDialog类的CModifyDialog类,
上面除了系统给定的IDOK和IDCANCEL的两个BUTTON外,我自己添加了一个BUTTON,
设置其ID为IDDELETE,准备做删除的功能。可是我遇到了下面的问题。
我在程序设计时,程序如下
CModifyDialog Mod;
int Rect=Mod.DoModal;
switch(Rect)
{
 case IDOK: 
          {
            //do something,正常
          }
 case IDCANCEL:
          {
            //do something 正常
          }
 case IDDELETE:
         {
            //为什么此时没有反应
         }
}
我不知道为什么我自己添加的那个BUTTON不能添加代码,请各位帮我看看。

解决方案 »

  1.   

    IDOK,IDCANCEL那是系统定义的呀,
    如果你要响应IDDELETE那你在资源里双击IDDELETE添加函数不是一样吗
      

  2.   

    可能基类CDialog中对idok和idcancel做了特殊处理...
    你可以看看它的源码..以及DoModal的源码
      

  3.   

    CModifyDialog Mod;
    int Rect=Mod.DoModal;
    switch(Rect)
    {
     case IDOK: 
              {
                //do something,正常
              }
     case IDCANCEL:
              {
                //do something 正常
              }
     case IDDELETE:
             {
                //为什么此时没有反应
               EndWindow(IDELETE);//加上这句就可以实现你的功能
             }
    }
      

  4.   

    楼上的...别忘了在对话框没销毁之前是不会执行switch(Rect)这一句的...
      

  5.   

    在你的相应代码中
    单击idddelete BUTTON;
    的处理汉书中这样做
    {
    //do your other work in here
    UpdateData(true);
     EndDialog(IDDELETE);//这样将导致DoModal()地返回值为IDDELETE
    }
      

  6.   

    否则默认的返回至不是IDOK就是IDCANCEL
    只要通过EndDialog(int retValue)才能改变返回志
    ----------------------------
    CDialog::EndDialog
    void EndDialog( int nResult );ParametersnResultContains the value to be returned from the dialog box to the caller of DoModal.ResCall this member function to terminate a modal dialog box. This member function returns nResult as the return value of DoModal. You must use the EndDialog function to complete processing whenever a modal dialog box is created.You can call EndDialog at any time, even in OnInitDialog, in which case you should close the dialog box before it is shown or before the input focus is set.EndDialog does not close the dialog box immediately. Instead, it sets a flag that directs the dialog box to close as soon as the current message handler returns.
      

  7.   

    kingcom_xu(刀是用来杀人的!) 说的对,我一急把代码放错地方了。
    应该放在BUTTON按钮的消息处理函数中。谢谢指正。