Is it possible to get the HWND of a Form?

  • Thread starter Thread starter ZhangZQ
  • Start date Start date
Yes, here is a way to do it. First make sure to capture mouse / stylus input
on the form by setting the Capture property true. After that you can
P/Invoke to the Win32 API GetCapture, which returns a window handle.

this.Capture = true;
IntPtr hWnd = GetCapture();
this.Capture = false;

The following code shows you how to P/Invoke GetCapture

[DllImport("coredll")]
extern static IntPtr GetCapture();



--
Regards,

Maarten Struys, eMVP
PTS Software bv

www.opennetcf.org | www.dotnetfordevices.com
 
Imports System.Runtime.InteropServices

<DllImport("coredll")> _
Private Shared Function GetCapture() As IntPtr
End Function

' Get the handle of the Form when called from inside the Form's scope.
Dim hWnd As IntPtr
Me.Capture = True
hWnd = GetCapture()
Me.Capture = False
 
Yes, very good, it is OK, thank you very much!


Regards,
ZhangZQ


Maarten Struys said:
Yes, here is a way to do it. First make sure to capture mouse / stylus input
on the form by setting the Capture property true. After that you can
P/Invoke to the Win32 API GetCapture, which returns a window handle.

this.Capture = true;
IntPtr hWnd = GetCapture();
this.Capture = false;

The following code shows you how to P/Invoke GetCapture

[DllImport("coredll")]
extern static IntPtr GetCapture();



--
Regards,

Maarten Struys, eMVP
PTS Software bv

www.opennetcf.org | www.dotnetfordevices.com

ZhangZQ said:
Is it possible to get the HWND of a Form?

Thanks.
 
Back
Top