首页
社区
课程
招聘
MFC下面如何依次弹出对话框
发表于: 2011-4-1 18:52 3413

MFC下面如何依次弹出对话框

2011-4-1 18:52
3413
BOOL CAppicationApp::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

        CAppicationDlg dlg;
        m_pMainWnd = &dlg;
        int nResponse = dlg.DoModal();

        CAppDialog app;
        app.DoModal(); //请问一下此处为什么不弹出对话框,谢谢各位了

        // Since the dialog has been closed, return FALSE so that we exit the
        //  application, rather than start the application's message pump.
        return FALSE;
}

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 91
活跃值: (57)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
2
这个问题很容易解决,

  m_pMainWnd = &dlg;
  int nResponse = dlg.DoModal();

  CAppDialog app;
  app.DoModal(); //请问一下此处为什么不弹出对话框,谢谢各位了

  改成

  CAppDialog app;
  app.DoModal(); //这时它会弹出来

  m_pMainWnd = &dlg;
  int nResponse = dlg.DoModal();

原因是这一句"m_pMainWnd = &dlg;"这个CWnd*类型的指针是存储你的线程主窗口对象。当和m_pMainWnd 相关的窗口被关闭后(m_pMainWnd = &dlg),MFC会自动终止你的线程。如果该线程是应用程序主线程,程序也将会被终止。(如果该数据成员为NULL,应用程序CWinApp对象的主窗口将用来决定什么时候去终止线程。)跟进去后发现是程序接到WM_QUIT消息(本人测试大约第十个消息就是WM_QUIT消息...)
2011-4-1 22:03
0
游客
登录 | 注册 方可回帖
返回
//