vc中基于对话框的程序中,怎么实现按一个按钮,之后打开一个新对话框并关闭原来的,把代码写在哪?

2025-01-06 05:24:33
推荐回答(1个)
回答1:

最简便的方法就是:
定义一全局变量int flag;
然后在InitInstance()里(即在主对话框没显示之前的函数里)

flag=0;

while(flag>=0)
{

if(flag==0)
{
CIceDispImgDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
}
else if(flag ==1)
{
CIceNewDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
}
else
{
break;
}

}

在互相调用前,设置flag=0或=1,然后退出本身对话框即可