I am trying to get the mouse cords after using a WndProc hook to get messages from Win32 API..
Below is my code.. Its not long, and should be easy enough to understand..
I am learning all this as I go and just can’t figure out how to change the lParam to points x and y..
Any help would be nice, Thanks 🙂
private const int WM_LEFTBUTTONDOWN = 0x0201;
private const int WM_LEFTBUTTONUP = 0x0202;
private const int WM_MOUSEMOVE = 0x0200;
private const int WM_MOUSEWHEEL = 0x020A;
private const int WM_RIGHTBUTTONDOWN = 0x0204;
private const int WM_RIGHTBUTTONUP = 0x0205;
public MainWindow()
{
InitializeComponent();
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(WndProc);
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_MOUSEMOVE)
{
label1.Content = "Msg: " + msg + " wParam: " + wParam + " lParam: " + lParam;
}
return IntPtr.Zero;
}
The x coordinate is in the low 16 bits, the y in the next 16 bits. Crack it like this: