HwndSource.FromHwnd(IntPtr) 方法

定義

傳回指定之視窗的 HwndSource 物件。

public:
 static System::Windows::Interop::HwndSource ^ FromHwnd(IntPtr hwnd);
[System.Security.SecurityCritical]
public static System.Windows.Interop.HwndSource FromHwnd (IntPtr hwnd);
public static System.Windows.Interop.HwndSource FromHwnd (IntPtr hwnd);
[<System.Security.SecurityCritical>]
static member FromHwnd : nativeint -> System.Windows.Interop.HwndSource
static member FromHwnd : nativeint -> System.Windows.Interop.HwndSource
Public Shared Function FromHwnd (hwnd As IntPtr) As HwndSource

參數

hwnd
IntPtr

nativeint

提供的視窗控制代碼。

傳回

hwnd 視窗控制代碼指定之視窗的 HwndSource 物件。

屬性

備註

重要

此方法不適用於網際網路安全性區域,或一般為部分信任。

您可以使用這個方法來傳回 HwndSource 不是明確交互操作視窗之視窗的 。 此程式如下:

  1. 建立 WindowInteropHelper 實例 (提供 main Window 作為建構函式參數) 。

  2. 從該 WindowInteropHelper 實例取得 屬性的值 Handle

  3. 將該 HWND 值當做參數傳遞至 FromHwnd

如果您接著想要將一般 AddHook 訊息處理新增至視窗,這項技術會很有用。 不過,每當您建立 HwndSource 時,您也會負責終結它。 即使 Application 處置應用程式的 HwndSource 物件,也是如此。 如需詳細資訊,請參閱 上的 HwndSource

適用於

另請參閱