WPF interop - HwndHost does not automatically destroy a hosted window

I am having problems with the fact that the placed window is correctly destroyed.

I have an HwndHost -derived class that I am showing in TabControl (although this probably doesn't matter). I try to destroy the hosted content when the tab closes (not when the closing window closes.)

Currently, I have code affecting myControlHost.Dispose() , which ensures that HwndHost.DestroyWindowCore is called immediately. The problem is that DestroyWindowCore does not actually destroy hosted HWND content!

I would think that this was enough to guarantee that the underlying CWnd application receives WM_CLOSE or something like that, but it does not seem to happen - Spy ++ only reports the registered message "HwndSubclass.DetachMessage", sent.

I read that you should not explicitly send your hosted window a WM_CLOSE to DestroyWindowCore , as this should happen automatically.

What is the right way to ensure that the hosted window is destroyed correctly when manually removing the HwndHost control?

+4
source share
1 answer

According to this MSDN document, they call DestroyWindow () in DestroyWindowCore: http://msdn.microsoft.com/en-us/library/ms752055.aspx

DestroyWindow () will send the WM_CLOSE message to the message queue, so you really don't need or don't need to send / send WM_CLOSE directly.

In my application, I actually call DestroyWindow () in an additional DLL that is called from C # in the DestroyWindowCore callback. Then everything works fine.

+3
source

Source: https://habr.com/ru/post/1343889/


All Articles