c# - Proper way of hosting an external window inside WPF using HwndHost -
i'd host window of external process inside wpf application. i'm deriving hwndhost
this:
class hwndhostex : hwndhost { [dllimport("user32.dll")] static extern intptr setparent(intptr hwndchild, intptr hwndnewparent); private intptr childhandle = intptr.zero; public hwndhostex(intptr handle) { this.childhandle = handle; } protected override system.runtime.interopservices.handleref buildwindowcore(system.runtime.interopservices.handleref hwndparent) { handleref href = new handleref(); if (childhandle != intptr.zero) { setparent(this.childhandle, hwndparent.handle); href = new handleref(this, this.childhandle); } return href; } protected override void destroywindowcore(system.runtime.interopservices.handleref hwnd) { } }
and using this:
hwndhostex host = new hwndhostex(handle); this.part_host.child = host;
where handle
handle external window i'd host , part_host
border inside wpf window:
<stackpanel uselayoutrounding="true" snapstodevicepixels="true" background="transparent"> <border name="part_host" /> ...
this gives me exception:
hosted hwnd must child window.
sorry lack of knowledge proper way of hosting external window inside wpf application?
right before calling 'setparent' this:
public const int gwl_style = (-16); public const int ws_child = 0x40000000; setwindowlong(this.childhandle, gwl_style, ws_child);
Comments
Post a Comment