Note that there are some explanatory texts on larger screens.

plurals
  1. POForcing initialization of a HwndHost
    primarykey
    data
    text
    <p>In my WPF application, I host Win32 content using HwndHost. However, creating a HwndHost does not create the native window. Rather, this is done in the overridden <code>BuildWindowCore()</code> method which is called sometime later by WPF.</p> <p>My hosted content needs the window handle of the native window for its own initialization. Unfortunately, there is no way I can force the creation of the window (i.e. having WPF call the BuildWindowCore), so I have a second thread which polls the HwndHost until it has been initialized.</p> <p>In .NET 4.0 / WPF 4.0, a new method <code>WindowInteropHelper.EnsureHandle()</code> was added. I had hoped this would resolve the situation, but it only works for a Window, not a HwndHost (which doesn't derive from Window). Do you have a suggestion what I could do instead?</p> <p>EDIT:</p> <p>I forgot to add some more constraints for a possible solution:</p> <ol> <li>The HwndHost is placed in a control which, depending on user settings, can be a child of the application's main window or can be placed in a new Window (via a third-party docking manager). This means that during creation of the window I do not know for sure what the parent Window (and thus its hWnd) will be.</li> <li>While the native code needs the hWnd during its initialization, the window is only displayed when the user requests it to be shown (i.e. it is invisible at first). Needing to show the window, only to hide it immediately again, should be avoided, if possible.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload