Link to home
Start Free TrialLog in
Avatar of Stuart_Johnson
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.
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rayek007
rayek007

var a,b:integer;
...
a:=mouse.CursorPos.X;
b:=mouse.CursorPos.Y;
.....


Hope it helps!
Avatar of Stuart_Johnson

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
>You know, I've known about the Mouse object
do you graded the right one, stu?
Yep.  I used your code, Meikl.