zoukankan      html  css  js  c++  java
  • 鼠标消息的位置获取正确方式

    今天碰到一个问题,就是在多屏的时候,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.

    Important  Do not use the LOWORD or HIWORD macros to extract the x- and y- coordinates of the cursor position because these macros return incorrect results on systems with multiple monitors. Systems with multiple monitors can have negative x- and y- coordinates, and LOWORD and HIWORD treat the coordinates as unsigned quantities.
     
    在delphi中可通过下面代码获取正确的鼠标位置:
     
    LMousePt.X := SmallInt(Msg.LParamLo);
    LMousePt.Y := SmallInt(Msg.LParamHi);
    
    //或者
    
    LMousePt.X := SmallInt(Msg.LParam);
    LMousePt.Y := (SmallInt)HiWord(Msg.LParam);
     
  • 相关阅读:
    Three.js 类的粗略总结和实现
    JavaScript方法
    JavaScript 继承和数组
    JavaScript 函数
    操作系统之堆和栈的区别
    第十二章 动态内存
    第十三章-第六小节-对象移动
    第十五章 面形对象程序设计
    动态建树和静态建树
    高斯消元整数版和浮点数版实现
  • 原文地址:https://www.cnblogs.com/igaoshang/p/HitTest.html
Copyright © 2011-2022 走看看