Get mouse handle

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.