Questions about mouse coordinates

Source: Internet
Author: User

There are two methods to express the position of a point on the screen.

One is the screen coordinates, that is, the coordinates in the upper left corner of the screen are fixed to 0 and 0. Therefore, the screen coordinates can be regarded as absolute coordinates. The coordinates of the same point will not change because of the position of the window.
One is the customer coordinate, that is, it is relative to the form, and the coordinates of the form as the form is 0, 0. therefore, the two points with the same customer coordinates do not necessarily overlap with the positions of the form.
In fact, the point with the same screen coordinate must be the same, and the point with the same client coordinate is not necessarily the same.
What you need is actually the customer coordinate. Therefore, use getcursorpos (ptnow) to first obtain the current mouse position (stored in ptnow), but get the screen coordinate. so we need to use screentoclient () to convert screen coordinates into customer coordinates. The returned value is the value you want.

 

 

 

Get the mouse coordinates:

In the onmousemove (uint nflags, cpoint point) event

Cstring STR;
Str. Format ("mouse position X = % d: Y = % d", point. X, point. y );
Setwindowtext (STR); // display the mouse coordinates in the title bar
Getdlgitem (idc_static1)-> setwindowtext (STR );

 

 

the method for responding to a mouse event contains the parameter point at the mouse position.
point. X current horizontal coordinate
point. Y current vertical coordinates
to determine whether the mouse is within a certain range of the screen, you can also use the ptinrect method:
void cgraphicview :: onlbuttondown (uint nflags, cpoint point)
{< br> If (rect. ptinrect (point)
{< br>...
}< BR >}

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.