添加了一个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不能添加代码,请各位帮我看看。
上面除了系统给定的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不能添加代码,请各位帮我看看。
如果你要响应IDDELETE那你在资源里双击IDDELETE添加函数不是一样吗
你可以看看它的源码..以及DoModal的源码
int Rect=Mod.DoModal;
switch(Rect)
{
case IDOK:
{
//do something,正常
}
case IDCANCEL:
{
//do something 正常
}
case IDDELETE:
{
//为什么此时没有反应
EndWindow(IDELETE);//加上这句就可以实现你的功能
}
}
单击idddelete BUTTON;
的处理汉书中这样做
{
//do your other work in here
UpdateData(true);
EndDialog(IDDELETE);//这样将导致DoModal()地返回值为IDDELETE
}
只要通过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.
应该放在BUTTON按钮的消息处理函数中。谢谢指正。