Hi!

Today I was playing with Iczelion's mouse hook tutorial for the first time. I wanted to show the mouse coordinates in my program, so I replaced this:

MouseProc proc nCode:DWORD,wParam:DWORD,lParam:DWORD

invoke CallNextHookEx,hHook,nCode,wParam,lParam
mov edx,lParam
assume edx:PTR MOUSEHOOKSTRUCT
invoke WindowFromPoint,.pt.x,.pt.y
invoke PostMessage,hWnd,WM_MOUSEHOOK,eax,0
assume edx:nothing
xor eax,eax
ret

MouseProc endp


with this:

MouseProc proc nCode:DWORD,wParam:DWORD,lParam:DWORD

invoke CallNextHookEx,hHook,nCode,wParam,lParam
mov edx,lParam
assume edx:PTR MOUSEHOOKSTRUCT
invoke PostMessage,hWnd,WM_MOUSEHOOK,.pt.x,.pt.y ;wParam=x lParam=y
assume edx:nothing
xor eax,eax
ret

MouseProc endp



This code is only working when I move the mouse over my window, but as soon as I move the cursor to a non-client area, the mouse coordinates aren't changing any more.

What can I do to get the mouse coordinates all the time?:confused:

/Delight
Posted on 2002-02-20 13:55:37 by Delight
Hello

The problem is that you took away the WindowFromPoint function.

Check out the Win32 Programmer?s Reference :


The WindowFromPoint function retrieves the handle of the window that contains the specified point.

HWND WindowFromPoint(

POINT Point // structure with point
);
Posted on 2002-02-20 14:05:48 by NoException
Hejsan!

Thanks for your fast reply NoException, but I think you missunderstand my question....or maybe I wasn't clear enough....or maybe I don't understand your answer :) , but it's not a window handle I want, it's the cursor's coordinates on the screen.


/Delight
Posted on 2002-02-20 14:45:50 by Delight
Sorry, I just misunderstood!

My computer crashed when I tried to change the files.
Maybe hooking is dangerous.:eek:
Posted on 2002-02-20 17:08:40 by NoException
So...does anyone else know how to get the mouse coordinates using a mouse hook?????



/Delight
Posted on 2002-02-21 07:03:20 by Delight
you have to capture the mouse...
hm don't know the exact name of the api... i think
it was like SetCapture and ReleaseCapture...

edit: duh!... sorry, hook related... uhm i wrote a
similar prog back then... it wasn't so hard... just
play around a little bit... i will get through my
sources :)

ok... forget about hooks... just capture the mouse
at the start of your prog and wait for WM_MOUSEMOVE
msg's... don't forget to release the mouse...



.IF UMSG == WM_MOUSEMOVE
mov ecx,lParam
movzx eax,cx
shr ecx,16
;eax=x ecx=y
Posted on 2002-02-21 08:46:46 by mob
Mob, I would like my program to receive a wm_mousemove message even if it's not in focus or if it's only shown in the system tray. To do that I think I must use a mouse hook. Am I right?


/Delight
Posted on 2002-02-21 14:16:07 by Delight
yeah but if you capture the mouse all mouse
input IS directed to your app without any hooks...

wtf, whats going on with me... just create a timer
and use GetCursorPos... no hooks, no capturing
no windows_messages...
Posted on 2002-02-21 16:40:15 by mob
Hi Delight

If you need to hook the mouse and get its position then this RadASM project will show a way to do it.

KetilO
Posted on 2002-02-21 18:14:55 by KetilO
It's late, forgot the zip.
Posted on 2002-02-21 18:18:40 by KetilO