I'm looking for getting window handle of a WPF control (known as hWnd in Win32).
In WinForm. we can get by "core.Init(panel1.Handle.ToInt32());"
but it is impossible to do this in WPF.
//C# in WinForm panel1.Handle.ToInt32();
//C# in WPF???????????
Only the window in WPF maps to a HWND.
All other element types (such as the panel) are not HWNDs internally, so you cannot get a HWND for them.
One possible solution for you would be to use a WindowsFormsHost for the part of the application you need the HWND for.
You can access to Window
handler by using WindowsInteropHelper
class like this:
IntPtr windowHandle = new WindowInteropHelper(sampleWindow).EnsureHandle();
EnsureHandle()
method description:
Creates the HWND of the window if the HWND has not been created yet.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.