您的位置:首页 > 其它

不用属性页方法实现 上一步 下一步 对话框功能

2012-04-20 10:47 162 查看
1. 新建VS2010 MFC dlg工程 Test, 会自动生成 Test.cpp TestDlg.cpp

2. 在资源管理器里新建对话框 Dlg2, 为其添加类Dlg2

3. 在StdAfx.h添加

const int ID_END_DLG_PRE  = 100; //打开起始对话框
const int ID_END_DLG_NEXT = 101; //信号源对话框


3. 在TestDlg对话框按钮添加 下一步按钮, 添加代码

EndModalLoop(ID_END_DLG_NEXT);


4. 在Dlg2添加 "上一步"按钮, 添加代码

EndModalLoop(ID_END_DLG_PRE);


5. 在Test.cpp的 BOOL CTestApp::InitInstance() 添加

SetRegistryKey(_T("Local AppWizard-Generated Applications"));

//下面是添加的
CTestDlg  dlg1;
CDlg2 dlg2;
CDialogEx *dlg = &dlg1;
tagMSG msg;

m_pMainWnd = &dlg1;
bool end_loop = false;

while ( !end_loop )
{

INT_PTR nResponse = dlg->DoModal();

//dlg 关闭后,  会发诸如 WM_QUIT的消息
//用PeekMsg可以拦截此消息, 防止程序退出
PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
switch ( nResponse )
{
case IDOK:
case IDCANCEL:
end_loop = true;
break;
case ID_END_DLG_PRE:
m_pMainWnd = &dlg1;
dlg = &dlg1;
break;
case ID_END_DLG_NEXT:
m_pMainWnd = &dlg2;
dlg = &dlg2;
break;
default:
end_loop = true;
break;
}
}

//上面是添加的
// Delete the shell manager created above.
if (pShellManager != NULL)
{
delete pShellManager;
}


原理大概就是 开 下一个对话框要先关闭当前对话框,

关闭对话框时若直接调用 EndDialog, 只能调用1次, 下一次 domodal就返回-1了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: