DoModal()问题

好人吗 2012-09-07 03:58:17
下面的代码是CWinApp的InitInstance函数的代码
CTxtDlg dlg; //系统生成的Dialog
CSQLITE3 sqlite;
CString strPath;
strPath.LoadString(IDS_SQLITEPATH);
sqlite.OpenDB(strPath);
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
CMainDlg maindlg; //自己添加的Dialog
m_pMainWnd=&maindlg;
int nMain=maindlg.DoModal(); //为什么DoModal()不起作用?
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
...全文
104 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
好人吗 2012-09-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

The Microsoft Foundation Class Library will automatically terminate your thread when the window referred to by m_pMainWnd is closed. If this thread is the primary thread for an application, the appli……
[/Quote]

我英语水平差,我说下理解看正确吗?
意思是说 m_pMainWnd若是为NULL,则关闭主窗口的时候,会同时关闭UI线程的消息循环。若是 m_pMainWnd不为NULL,则由WinApp类来决定什么时候关闭UI线程的消息循环。
附带问一下:这些工作都是在DoModal中完成的吗?
Eleven 2012-09-07
  • 打赏
  • 举报
回复
The Microsoft Foundation Class Library will automatically terminate your thread when the window referred to by m_pMainWnd is closed. If this thread is the primary thread for an application, the application will also be terminated. If this data member is NULL, the main window for the application's CWinApp object will be used to determine when to terminate the thread. m_pMainWnd is a public variable of type CWnd*.

Typically, you set this member variable when you override InitInstance. In a worker thread, the value of this data member is inherited from its parent thread.

请认真看这一段~
Eleven 2012-09-07
  • 打赏
  • 举报
回复
sqlite.OpenDB(strPath);
m_pMainWnd = &dlg; // 把这句给注释掉

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧