为什么在MFC程序代码中到不到Run()和ExitInstance()两个函数?

 我来答
浪花飘零2000
推荐于2016-09-29 · TA获得超过630个赞
知道小有建树答主
回答量:579
采纳率:0%
帮助的人:521万
展开全部

懂你得意思了,run()函数MFC里没有,功能类似的是InitInstance( )函数,工程创建的时候被自动创建在CxxxxApp类中,代码如下

BOOL CMy3DApp::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

 CMy3DDlg 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;
}

 

ExitInstance()函数在工程创建的时候并没有创建,需要自己使用类向导创建在CxxxxAPP类中

创建后的代码为

int CMy3DApp::ExitInstance()
{
 // TODO: Add your specialized code here and/or call the base class
 
 return CWinApp::ExitInstance();
}
若满意请及时采纳,谢谢

更多追问追答
追问
MFC的运行机制不就是:   InitInstance()——Run()——ExitInstance() 吗?怎么会没有呢?
追答
你指的运行不是InitInstance()?app之后就是窗体的创建了,没有运行这个函数,创建窗体时有个InitDialog函数,你指的是它?它是创建窗体时首先要执行的函数
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式