1. Call user32.dll
(1) Reference
Using system. runtime. interopservices;
(2) Call Method
1. Obtain the window title
[Dllimport ("user32.dll")]
Public static extern int getwindowtext (intptr hwnd, stringbuilder lpstring, int nmaxcount );
Note: hwnd window handle lpstring window title nmaxcount maximum value
2. Get the class name
[Dllimport ("user32.dll")]
Public static extern int getclassname (intptr hwnd, stringbuilder lpstring, int nmaxcount );
Note: hwnd handle lpstring class name nmaxcount maximum value
3. Obtain the window Handle Based on coordinates
[Dllimport ("user32.dll")]
Public static extern intptr windowfrompoint (point );
Note: Point Coordinates
Ii. Display Data
(1) Get the mouse coordinates
Int x = cursor. position. X;
Int y = cursor. position. Y;
This. textbox4.text = string. Format ("({0}, {1})", x, y );
(2) obtain the handle
Point P = new point (x, y );
Intptr formhandle = windowfrompoint (P );
This. textbox1.text = formhandle. tostring ();
(3) obtain the window title.
Getwindowtext (formhandle, title, title. capacity );
This. textbox2.text = title. tostring ();
(4) obtain the Class Name of the form.
Stringbuilder cllassname = new stringbuilder ();
Getclassname (formhandle, cllassname, cllassname. capacity );
This. textbox3.text = cllassname. tostring ();
(5) Load event
This. timer1.enabled =! This. timer1.enabled;
Note: dynamic display of information
Iii. Results
Three, source code download: http://pan.baidu.com/s/1qWNTe4s
Get mouse handle