12

I'm trying to do some P/Invoke stuff and need the handle of the current window.

I found Getting the handle of window in C#

But it appears that only works in WPF. Is there a winForms equivalent?

StayOnTarget
  • 9,925
  • 10
  • 45
  • 68
Joel Barsotti
  • 3,001
  • 7
  • 34
  • 59

2 Answers2

25

Control.Handle

An IntPtr that contains the window handle (HWND) of the control.

dtb
  • 206,299
  • 34
  • 391
  • 426
6

Try this in your form:

IntPtr myHandle = this.Handle;

It will return the handle of the form.

ZokiManas
  • 732
  • 5
  • 8