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?)