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 >}