有一事不明!
单线程的程序,是在执行了CWinApp类的Run()函数后,才开始进行消息循环,进而响应Windows消息、命令消息和控件通知的吧!?
但是用向导生成的基于对话框的应用程序,很明显没有执行Run()函数,可是它是根据什么机制来响应各种消息和控件通知的呢??
问题点数:60、回复次数:5Top
1 楼kenny_yuan(程序员)回复于 2001-07-05 10:47:12 得分 10
对话框自己有消息处理。Top
2 楼nustchen(壁虎)回复于 2001-07-05 10:47:49 得分 10
咋没有,有啊,都有。Top
3 楼leky2000(懒客)回复于 2001-07-05 10:48:17 得分 10
你有深入浅出mfc吗,如没有到pcbook.51soft.com 下载
那里有特别详细的解释Top
4 楼thaliahujie(thaliahujie)回复于 2001-07-05 10:58:13 得分 10
基于对话框的应用程序, 也有CWinApp类的Run()函数Top
5 楼WhiteWaterBlueSky(花之雨)回复于 2001-07-05 11:11:57 得分 20
实际上基于对话框的应用程序并没有进入CWinApp类的Run()函数,原因如下:
我们先看看CMyWinApp的InitInstance方法片段
BOOL CMyWinApp::InitInstance()
{
// ......略
CPackagePictureDlg 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;
}
我们发现主线程执行到dlg.DoModal()时,就不返回,直到该对话框关闭,显然dlg.DoModal()实际上启动的是对话框的窗口过程!
当对话框关闭后(程序结束),InitInstance直接返回FALSE,自然就不会进入Run方法了!
仔细看看最后的英文注释!!!
Top





