开发者

how to hook control closing in an MFC custom control class

I am interested in allocating pointers, storing those in the LPARAM data of a comboboxex control, and making that control responsible for deleting those pointers when it is destroyed.

Since I am working开发者_运维知识库 in MFC, I can subclass a CComboBoxEx, and add either a message handler or a virtual member function.

The question is: Is this pattern possible with Win32 / MFC?

Basically, how does a control get notified that its corresponding HWND is being destroyed?

The documentation for WM_DESTROY:

The WM_DESTROY message is sent when a window is being destroyed. It is sent to the window procedure of the window being destroyed after the window is removed from the screen. (Emphasis Mine)

Unfortunately, my vague recollection is that this means that OnDestroy() is too late for handling anything that requires interacting with the associated HWND, no?

Can I query the elements in the comboboxex during OnDestroy()? Is there another hook I can use that occurs "Just before my window / control is destroyed (instead of after!)?"

I wonder if I overrode CBEM_DELETEITEM for my subclass and forced it to delete the LPARAM data. Are all items explicitly deleted when a comboboxex is destroyed? If so, are they all destroyed via that message (does the control send that message to itself?)


During OnDestroy() your window will still be valid -- if it weren't, your window wouldn't have gotten the message at all, since it's sent via the standard Windows messaging system.

You are on the right track -- this type of scenario is what OnDestroy() is for.


From MSDN:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜