Export (0) Print
Expand All

HwndSource.FromHwnd Method

Returns the HwndSource object of the specified window.

Namespace: System.Windows.Interop
Assembly: PresentationCore (in presentationcore.dll)

public static HwndSource FromHwnd (
	IntPtr hwnd
)
public static HwndSource FromHwnd (
	IntPtr hwnd
)
public static function FromHwnd (
	hwnd : IntPtr
) : HwndSource
You cannot use methods in XAML.

Parameters

hwnd

The provided window handle.

Return Value

The HwndSource object for the window that is specified by the hwnd window handle.

Security noteSecurity Note:

This method is not available in the Internet security zone, or for partial trust in general.

You can use this method to return an HwndSource for a window that is not explicitly an interoperation window. The procedure for this is:

  1. Create a WindowInteropHelper instance (providing the main Window as a constructor parameter).

  2. Get the value of the Handle property from that WindowInteropHelper instance.

  3. Pass that HWND value as a parameter to FromHwnd.

This technique can be useful if you then want to add general AddHook message processing to the window. However, whenever you create a HwndSource, you are also responsible for destroying it. This is true even if the Application object for an application is HwndSource is disposed. For more information, see Remarks on HwndSource.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft