vc6之dialog执行流程

本文介绍了在VC6.0环境中使用MFC AppWizard创建Dialog Based项目的过程,以及项目生成的三个核心类:CDialogtestApp、CDialogtestDlg和CAboutDlg。重点讲解了CDialogtestApp的InitInstance()函数,该函数中通过CDialogtestDlg对象的DoModal()方法来显示和控制对话框的生命周期。当对话框关闭时,根据用户点击的按钮(IDOK或IDCANCEL)进行相应处理,并决定应用是否继续运行。
在vc6.0中
选择File/New
在projects标签页选择MFC Appwizard(exe)
在接下来的对话框中选择Dialog Based...
即可建立一对话框项目
每新建一个对话框的项目,wizard都会自动生成3个类,比如新建dialogtest项目
自动生成的类是
CDialogtestApp---对应文件是dialogtest..cpp和dialogtest.h
CDialogtestDlg---对应文件是dialogtestDlg.cpp和dialogtestDlg.h
CAboutDlg---                            在dialogtestDlg.cpp中声明和实现。

程序执行流程和多文档的类似,参考http://blog.youkuaiyun.com/luck_good/article/details/6955628
主要看一下dialogtest..cpp中的InitInstance()函数
CDialogtestApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CDialogtestApp initialization

BOOL CDialogtestApp::InitInstance()
{
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	CDialogtestDlg 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
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}
可知是如下形式去创建对话框窗口
CDialogtestDlg dlg;
dlg.DoModal();

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值