如何从低级鼠标回调方法中获取lParam的鼠标光标坐标?

时间:2015-08-28 06:19:11

标签: c# windows-api-code-pack mouse-pointer

问题标题本身几乎描述了我的整体问题。以下是我到目前为止所做的工作。

    // the event is registered as following 
     mouseProc = new CallWndRetProc(MouseProc); // get keys
     MouseProcHandle = SetWindowsHookEx(WH_MOUSE_LL, mouseProc, IntPtr.Zero, 0);

     // The callback method
     public static IntPtr MouseProc(int nCode, int wParam, IntPtr lParam)
    {            
        if (wParam == WM_LBUTTONUP && MouseProcHandle != IntPtr.Zero )                
        {

        }

        if (wParam == WM_MOUSEMOVE)
        {
          // Want to get mouse position here 
        }

        return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam);
    }

是否有可靠的方法来获得鼠标位置?

代码示例将不胜感激 感谢

1 个答案:

答案 0 :(得分:1)

根据codeguru forum,特别是pinvoke.net您可能认为(pinvoke.net again):

[StructLayout(LayoutKind.Sequential)]
 public struct MSLLHOOKSTRUCT
 {
     public POINT pt;
     public int mouseData; // be careful, this must be ints, not uints (was wrong before I changed it...). regards, cmew.
     public int flags;
     public int time;
     public UIntPtr dwExtraInfo;
 }

然后,当然,你总能得到当前的坐标。这里有很多on Stackoverflow