关于子线程中销毁主线程窗口的问题

本文探讨了在子线程中如何正确、安全地关闭主线程创建的窗口。介绍了涉及到的多线程同步问题,以及使用适当的方法如消息机制或互斥锁来确保主线程在适当的时间被销毁,防止资源泄露和应用程序崩溃。
摘要由CSDN通过智能技术生成



关于子线程中销毁主线程窗口的问题

通常销毁或者关闭窗口会用如下函数:
[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 = AfxGetApp();
	if (pApp != NULL &
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值