Confused: The postmessage function simulates the mouse and clicks the specified coordinate.

Source: Internet
Author: User

First of all, I did not deliberately learn the postmessage function, nor did I want to spend a lot of time studying APIs. However, in order to improve your knowledge and reflect the domain learning method, I studied this function by the way.

There are many questions on the Internet about invalid postmessage message sending, but no one answered. Here I will give a superficial explanation of the problem.

First, eliminate the possibility of message sending failure and recipient. Most problems are caused by sending the mouse-clicked message, but it does not work, and the function return value is correct. The cause of this problem is that the handle is not correct. For example, if we want to operate a button on a form, the handle will directly write the handle of the button. Do not write the handle of the form, even if you use coordinates to click, it turns out that this click message cannot be accepted by the button layer. Only specific to the class, the more specific the better, specific to a class, and then send messages.

In fact, I learned that it is mainly applied to webpage operations. Because some web pages use flash buttons, it is difficult to simulate clicks using conventional methods, but postmessage is different! We can use the absolute position (either absolute or troublesome) of the button in the form to click. Let's take a look at the call of postmessage:

Postmessage (hwnd, wm_lbuttondown, 0,Mx + my * 65536).

Each parameter is described in detail:

Hwnd: instance handle. When you click a webpage, you must note that this handle is the handle of the window that displays the webpage (that is, the handle of the tab instance), rather than the handle of the entire browser! This class is in the IE kernel Browser: Internet assumer_server.

Wm_lbuttondown: a symbolic constant, representing the constant & h201. Indicates that the left mouse button is pressed.

0: don't worry ....

Mx + my * 65536: MX is the horizontal coordinate of the vertex relative to the client area (that is, the interface of the entire class instance), that is, the coordinate in the upper left corner of the class instance handle is ), of course, my is an ordinate. This operation turns the abscissa into a number. The ordinate is placed at 16 bits in height, and the abscissa is placed at 16 bits in height (you can also use the makelong function, makelong (My, MX )). Pass the calculation result to the function to identify the coordinate and click it based on the coordinate.Note:The coordinate unit here is pixel! The conversion relationship between a TDE and a pixel is 1 pixel = 15 TDE. You can use the screenshot tool to obtain the specific coordinates. The screenshot tool is just the coordinates in pixels.

With this function, it is a huge addition to computer control! Here is a simple example! Go to msdn for detailed parameters.

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.