鼠标消息的位置获取正确方式
Posted GS
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鼠标消息的位置获取正确方式相关的知识,希望对你有一定的参考价值。
今天碰到一个问题,就是在多屏的时候,WM_NCHITTEST结果不正确,经检查发现在多屏的情况下,鼠标的位置是有可能出现负值的,但是如果还是用LoWord(Msg.LParam)和HiWORD(Msg.LParam)取鼠标的位置,就会取出不正确的值,因为这两个函数只会返回正值。
查询MSDN的WM_NCHITTEST有下面一段话。
Remarks
Use the following code to obtain the horizontal and vertical position:
xPos = GET_X_LPARAM(lParam); yPos = GET_Y_LPARAM(lParam);
As noted above, the x-coordinate is in the low-order short of the return value; the y-coordinate is in the high-order short (both represent signed values because they can take negative values on systems with multiple monitors). If the return value is assigned to a variable, you can use the MAKEPOINTS macro to obtain a POINTS structure from the return value. You can also use the GET_X_LPARAM or GET_Y_LPARAM macro to extract the x- or y-coordinate.
LMousePt.X := SmallInt(Msg.LParamLo); LMousePt.Y := SmallInt(Msg.LParamHi); //或者 LMousePt.X := SmallInt(Msg.LParam); LMousePt.Y := (SmallInt)HiWord(Msg.LParam);
以上是关于鼠标消息的位置获取正确方式的主要内容,如果未能解决你的问题,请参考以下文章
Android 使用两个不同的代码片段获取当前位置 NULL