MFC的CDialog多次创建关闭后导致进程无法退出问题
- 消息循环判断 WM_QUIT 来退出
- CDialog关闭时 在CWnd::OnNcDestroy 时发送WM_QUIT 消息
- 发送WM_QUIT 消息时有条件的, 只有当 theApp.m_pMainWnd的 OnNcDestroy触发才会发送
- 发送WM_QUIT 消息后, theApp.m_pMainWnd会被清0
所以当第一次窗体销毁后 发送WM_QUIT 消息后, theApp.m_pMainWnd被清0
再次创建关闭后, 因为theApp.m_pMainWnd 是0. 导致无法触发WM_QUIT 消息, 这样消息循环无法退出
int i, n;
n = 16;
for(i=0; i<n; i++)
{
NLog::LogTime(NULL);
bRetVal = Create(IDD, NULL);
NLog::LogTime("CDialog.Create");
// this->SendMessage(WM_CLOSE, 0, 0);
this->DestroyWindow();
theApp.m_pMainWnd = this; // 消息循环 需要m_pMainWnd判断退出, 以发送WM_QUIT
}

浙公网安备 33010602011771号