在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()函数
CDialogtestDlg dlg;
dlg.DoModal();
选择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();
本文介绍了在VC6.0环境中使用MFC AppWizard创建Dialog Based项目的过程,以及项目生成的三个核心类:CDialogtestApp、CDialogtestDlg和CAboutDlg。重点讲解了CDialogtestApp的InitInstance()函数,该函数中通过CDialogtestDlg对象的DoModal()方法来显示和控制对话框的生命周期。当对话框关闭时,根据用户点击的按钮(IDOK或IDCANCEL)进行相应处理,并决定应用是否继续运行。
329

被折叠的 条评论
为什么被折叠?



