WindowInteropHelper 类

定义

协助在 Windows Presentation Foundation (WPF) 和 Win32 代码之间进行互操作。

public ref class WindowInteropHelper sealed
public sealed class WindowInteropHelper
type WindowInteropHelper = class
Public NotInheritable Class WindowInteropHelper
继承
WindowInteropHelper

注解

此类的成员允许调用方对 WIN32 HWND 和 WPF Window的父 HWND 具有内部访问权限。 这些成员执行适当的安全检查。

每当需要基于其 HWND 的更具体的对象时,请使用此类。

例如,如果需要在 Win32 应用程序中托管 WPF 对话框。 使用 WindowInteropHelper 对话框的 WPF 窗口对象初始化。 然后,可以从属性获取 WPF 窗口的句柄 (HWND) Handle ,并使用该属性指定 WPF 窗口 Owner 的所有者。 下面的代码示例演示如何在 Win32 应用程序中托管 WPF 对话框时使用 WindowInteropHelper

WindowInteropHelper wih = new WindowInteropHelper(myDialog);
wih.Owner = ownerHwnd;
myDialog.ShowDialog();
Dim wih As New WindowInteropHelper(myDialog)
wih.Owner = ownerHwnd
myDialog.ShowDialog()

此类支持的另一 HwndSource 种方案是从 WPF Window 对象获取对象。 通过 HwndSource 该方法可以直接处理 Win32 消息 AddHook 。 通过使用 HwndSourceAddHook 代替 Window 方法,你仍然可以处理在 WPF 中没有等效或处理的消息。 使用源创建一个WindowInteropHelper,然后调用HandleWindowInteropHelper从 HWND 获取到 HwndSourceWindow

构造函数

WindowInteropHelper(Window)

为指定的WINDOWS PRESENTATION FOUNDATION (WPF) 窗口初始化类的新实例WindowInteropHelper

属性

Handle

获取用于创建此WindowInteropHelperWindows Presentation Foundation (WPF) 窗口的窗口句柄。

Owner

获取或设置Windows Presentation Foundation (WPF) 所有者窗口的句柄。

方法

EnsureHandle()

如果尚未创建窗口的 HWND,则创建 HWND。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅