设为首页 加入收藏

TOP

不用属性页方法实现上一步,下一步,对话框功能
2014-11-23 20:17:23 】 浏览:291
Tags:不用 属性 方法 实现 对话 功能

1. 新建VS2010 MFC dlg工程 Test, 会自动生成 Test.cpp TestDlg.cpp

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

3. 在StdAfx.h添加

[cpp]

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

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

[cpp]
EndModalLoop(ID_END_DLG_NEXT);

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

[cpp]
EndModalLoop(ID_END_DLG_PRE);

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

[cpp]
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了



摘自 ma100的专栏

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇VC++----为CListBox加上智能水平.. 下一篇VC解决绘图闪烁问题

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目