HwndSource.FromHwnd(IntPtr) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the HwndSource object of the specified window.
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
Parameters
- hwnd
-
IntPtr
nativeint
The provided window handle.
Returns
The HwndSource object for the window that is specified by the hwnd
window handle.
- Attributes
Remarks
Important
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:
Create a WindowInteropHelper instance (providing the main Window as a constructor parameter).
Get the value of the Handle property from that WindowInteropHelper instance.
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 an HwndSource, you are also responsible for destroying it. This is true even if the Application object for an application HwndSource is disposed. For more information, see Remarks on HwndSource.