MFC 窗口关闭消息函数

MSDN原文与翻译

1. OnNcDestroy()函数

Called by the framework when the nonclient area is being destroyed, and is the last member function called when the Windows window is destroyed.

 

afx_msg void OnNcDestroy( );  //nonclient Destroyed

Remarks

The default implementation performs some cleanup, then calls the virtual member function PostNcDestroy.

Override PostNcDestroy if you want to perform your own cleanup,such as a delete this operation. If you override OnNcDestroy, you must call OnNcDestroy in your base class to ensure that any memory internally allocated for the window is freed.

翻译:

当非客户区即将被销毁时,框架调用这个函数,这是Windows的窗口被销毁时调用的最后一个成员函数。

缺省的实现执行一些清除工作,然后调用虚成员函数PostNcDestroy。

如果你希望执行自己的清除操作,例如删除,则应重载PostNcDestroy。如果你重载了OnNcDestroy,则必须调用基类的OnNcDestroy以确保内部为窗口分配的内存都被释放。

 

 2.PostNcDestroy()函数

Called by the default OnNcDestroy member function after the window has been destroyed.

virtual void PostNcDestroy( );

Remarks

Derived classes can use this function for custom cleanup such as the deletion of the this pointer.

翻译:

在窗口被销毁以后,缺省的OnNcDestroy成员函数调用这个函数。

派生类可以利用这个函数来执行自定义的清除工作,比如删除指针。

 

3.DestroyWindow()函数

Call this method to destroy a modeless dialog box.

BOOL DestroyWindow( );

Return Value

TRUE if the window is successfully destroyed; otherwise FALSE.

Remarks

Do not call DestroyWindow to destroy a modal dialog box. Call EndDialog instead.

翻译:

调用该函数销毁非模态对话框

返回值:如果销毁了窗口返回TRUE,否则返回FALSE

不要调用此函数销毁模态对话框,应该调用EndDialog来销毁模态对话框。


4.OnDestroy()函数

The framework calls this member function to inform the CWnd object that it is being destroyed.

afx_msg void OnDestroy( );

Remarks

OnDestroy is called after the CWnd object is removed from the screen.

OnDestroy is called first for the CWnd being destroyed,  then for the child windows of CWnd as they are destroyed. It can be assumed that all child windows still exist while OnDestroy runs.

If the CWnd object being destroyed is part of the Clipboard-viewer chain (set by calling the SetClipboardViewer member function), the CWnd must remove itself from the Clipboard-viewer chain by calling the ChangeClipboardChain member function before returning from the OnDestroy function.

翻译:

框架调用这个成员函数以通知将要销毁CWnd对象。

OnDestroy是在CWnd对象已经从屏幕上清除以后被调用的。

首先为被销毁的CWnd调用OnDestroy,然后当CWnd的子窗口被销毁时为它们调用OnDestroy。可以假定当OnDestroy运行的时候,所有的子窗口依然存在。

 如果被销毁的CWnd对象是剪贴板查看器链的一部分(通过调用SetClipBoardViewer成员函数设定),那么在OnDestroy函数返回前必须通过调用ChangeClipboardChain成员函数将CWnd对象从中删除。



综合以上:先调用DestroyWindow,在此间会有OnDestroy消息,接着窗口被销毁,于是DestroyWindow返回TRUE,然后是OnNcDestroy消息,之后再调用PostNcDestroy。

 

此外涉及两个消息WM_DESTROY和WM_NCDESTROY。

WM_DESTROY 消息是在窗口销毁动作序列中的开始被发送的 WM_NCDESTROY 消息是在窗口销毁动作序列中结尾发送的


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值