关于子线程中销毁主线程窗口的问题
通常销毁或者关闭窗口会用如下函数:
[1] CWnd::DestroyWindow()
[2] CFrameWnd::OnClose()
[3] ::SendMessage(hWnd,WM_SYSCOMMAND,SC_CLOSE,0);
或者::SendMessage(hWnd,WM_CLOSE,NULL,NULL);
之间的关系如下:
After runing the function sendMessage(),thefunction OnClose() will be excuted;
in the function OnClose() , DestroyWindow() will be called in the end
/////////////////////////////////////////////////////////////////////////////
// CFrameWnd closing down
void CFrameWnd::OnClose()
{
if (m_lpfnCloseProc != NULL)
{
// if there is a close proc, then defer to it, and return
// after calling it so the frame itself does not close.
(*m_lpfnCloseProc)(this);
return;
}
// Note: only queries the active document
CDocument* pDocument = GetActiveDocument();
if (pDocument != NULL && !pDocument->CanCloseFrame(this))
{
// document can't close right now -- don't close it
return;
}
CWinApp* pApp = AfxGet

本文探讨了在子线程中如何正确、安全地关闭主线程创建的窗口。介绍了涉及到的多线程同步问题,以及使用适当的方法如消息机制或互斥锁来确保主线程在适当的时间被销毁,防止资源泄露和应用程序崩溃。
最低0.47元/天 解锁文章
382

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



