The difference between GetCursorPos () and Getmessagepos ()

Source: Internet
Author: User
Tags function prototype

1. GetCursorPos ()
Function prototype: BOOL GetCursorPos (Lppoint lppoint);
function function: The function checks the position of the cursor,expressed in screen coordinates.
Parameters: Ippoint:point The structure pointer, which receives the screen coordinates of the cursor.
Return value: If successful, the return value is not 0; If it fails, the return value is 0. To get more error information, call the GetLastError function.

2. Getmessagepos ()
Function prototype: DWORD Getmessagepos (VOID)
function function: This function returns the expressionunder screen coordinatesThe long integer value of the cursor position. This position represents the point the mouse occupies when the previous message was taken by GetMessage.
Return value: The return value gives the x, y coordinate of the cursor position. The x-coordinate is in the low-level integer, and the y-coordinate is high.

remark:
(1) As mentioned above, the x-coordinate in the return value of the low-level integer, y-coordinate in the high-level integer (both represent a signed value, because in a multi-monitor system can obtain a negative value).
(2) If the return value is assigned to a variable, the Makepoint macro can be used to get the point structure from the return value.
(3) You can also use Get_x_lparam or Get_y_lparam macros to extract the x, y coordinates, the coordinates are screen coordinates, not client coordinates.

Note:
Do not use the LoWord or HIWORD macro to extract the x, y coordinates of the mouse position because incorrect results will be returned in a multi-monitor system.
Negative x, Y coordinates can be obtained in a multi-monitor system, but LoWord and hiword use coordinates as unsigned quantities.


The difference:

To get the current position of the cursor instead of where the previous message occurred, call the function GetCursorPos.



to determine how the mouse hits a rect area:
First GetWindowRect () gets the screen coordinates.
Re-screentoclient () converted to customer area coordinates

Then PtInRect () judged


For example: There is a WebBrowser control in the dialog box, how to determine whether the position of the mouse click falls within the WebBrowser control?

Method I:getwindowrect () screentoclient () PtInRect () method 2:cpoint pntcursor;if (GetCursorPos (&pntcursor)) {if (this = Windowfrompoint (Pntcursor)) {   int flag = 1;}} Method 3: Hook the "Notify" in the control's properties, and then in PreTranslateMessage if (Pmsg->hwnd==getdlgite (idc_webbrower1)->m_hwnd) {...}

The difference between GetCursorPos () and Getmessagepos ()

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.