Get a handle to the top-level form in WPF

Source: Internet
Author: User
Tags win32
IntPtr ipwnd=new Windowinterophelper (this). Handle;



Windowinterophelper class

Assists in interoperability between Windows presentation Foundation (WPF) and Win32 code.


Members of this class allow the caller to have internal access to the parent HWND of the WIN32 hwnd and the WPF Window. Property security checks are performed through these members.

Use this class when you need a more specific object based on its HWND.

The example scenario assumes that you need to host the WPF dialog box in the Win32 application. Initializes the windowinterophelper using the WPF Window object for the dialog box. You can then get the handle (HWND) of the WPF window from the Handle property, and use the Owner property to specify the owner of the WPF window. The following code example demonstrates how to use Windowinterophelper when hosting a WPF dialog box in an WIN32 application.

Windowinterophelper wih = new Windowinterophelper (mydialog);
wih. Owner = Ownerhwnd;
Mydialog.showdialog ();

Another scenario supported by this class is to get the HwndSource object from the WPF Window object.

HwndSource supports processing WIN32 messages directly through the Addhook method.

By using HwndSource and Addhook instead of windows, you can still handle messages that are not equivalent or unhandled in WPF.

Create a windowinterophelper using the Window source, and then call Handle on Windowinterophelper to get it from the HwndSource HWND.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.