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 ()