0

The question heading itself pretty much describes my overall problem. Following is what I have done so far.

    // 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);
    }

Is there a reliable way to get the mouse position ?

Code examples will be appreciated Thanks

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Nilaksha Perera
  • 715
  • 2
  • 12
  • 36
  • Marshal.PtrToStructure() to convert the lParam to a MSLLHOOKSTRUCT. This has been done thousands of times before, don't reinvent that wheel. – Hans Passant Aug 28 '15 at 09:51

1 Answers1

1

According to codeguru forum and especially pinvoke.net you are looking probably for (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;
 }

Then of course, you could always get current coordinates. Lots of this here on Stackoverflow.

Community
  • 1
  • 1
Andreas Reiff
  • 7,961
  • 10
  • 50
  • 104
  • Thank you very much. i used MSLLHOOKSTRUCT with Uint variables. maybe that is where it is failing. I will try this and let you know :) – Nilaksha Perera Aug 28 '15 at 08:14
  • uint/int should not make much of a difference. What you probably want is the POINT pt though. And.. if you do not care to have the exact coordinates at the time the event was fired, you can also get the current coordinates, which perhaps is easier (though those might be slightly different from the ones you get in the message). – Andreas Reiff Aug 28 '15 at 08:29