Stuart_Johnson
asked on
Getting Mouse Coordinates
Hi,
I need a way of detecting the mouse position globally - regardless of what is under the mouse. At present, I use this code:
function MouseProc(nCode: Integer; wParam: Longint; var MouseHookStruct:
TMouseHookStruct): Longint; stdcall;
begin
Result := CallNextHookEx(MouseHook, nCode, wParam, Longint(@MouseHookStruct)) ;
{
code
}
end;
procedure TMainForm.FormShow(Sender: TObject);
begin
MouseHook := SetWindowsHookEx(WH_Mouse, @MouseProc, 0, GetCurrentThreadId);
end;
It works fine, except for if I drop a TMediaPlayer on the form and link it too a panel. When the mouse cursor moves over the area that is playing the video, I no longer recieve mouse events.
Can anyone tell me how I can get this working?
Many thanks,
Stuart.
I need a way of detecting the mouse position globally - regardless of what is under the mouse. At present, I use this code:
function MouseProc(nCode: Integer; wParam: Longint; var MouseHookStruct:
TMouseHookStruct): Longint; stdcall;
begin
Result := CallNextHookEx(MouseHook, nCode, wParam, Longint(@MouseHookStruct))
{
code
}
end;
procedure TMainForm.FormShow(Sender:
begin
MouseHook := SetWindowsHookEx(WH_Mouse,
end;
It works fine, except for if I drop a TMediaPlayer on the form and link it too a panel. When the mouse cursor moves over the area that is playing the video, I no longer recieve mouse events.
Can anyone tell me how I can get this working?
Many thanks,
Stuart.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dammit! You know, I've known about the Mouse object - I've used it so many times. But for some reason, I used the mouse hook (it was suggested by someone else in another Experts Exchange question I asked) because in the past, the mouse object wasn't good enough for what I was doing.
Thanks :)
Stu
Thanks :)
Stu
>You know, I've known about the Mouse object
do you graded the right one, stu?
do you graded the right one, stu?
ASKER
Yep. I used your code, Meikl.
...
a:=mouse.CursorPos.X;
b:=mouse.CursorPos.Y;
.....
Hope it helps!