Getting a window control's handle

  • Thread starter Thread starter Thomas
  • Start date Start date
T

Thomas

How do I go about getting the handle of a windows form
control in C# so that I can use it in a PInvoke call to
SendMessage?
 
Thomas said:
How do I go about getting the handle of a windows form
control in C# so that I can use it in a PInvoke call to
SendMessage?

Very simple.


using System.Runtime.InteropServices;

[DllImport("coredll")]
public static extern IntPtr GetFocus();


public IntPtr GetHandle(Control c)
{
c.Focus();
IntPtr hWnd = GetFocus();
return hWnd;
}





Mark Erikson
 
Back
Top