Board index » delphi » Getting Mouse position in OnClick handler

Getting Mouse position in OnClick handler

Maybe I'm blind and missing the obvious, but I can't figure out how to
get the mouse position
when I'm in the OnClick or OnDblClick event handlers for a TImage.

There's got to be a way to do this?  I'm in Delphi 4, Win98.

Thanks,
Tom

 

Re:Getting Mouse position in OnClick handler


Does Delphi 4 have the Mouse Object? i know 5 & 6 do, but i have never used
4... other than that - you might want to look up http://msdn.microsoft.com
for the answers...
Quote
<tomn...@erols.com> wrote in message news:3C89978F.4E39930A@erols.com...
> Maybe I'm blind and missing the obvious, but I can't figure out how to
> get the mouse position
> when I'm in the OnClick or OnDblClick event handlers for a TImage.

> There's got to be a way to do this?  I'm in Delphi 4, Win98.

> Thanks,
> Tom

Re:Getting Mouse position in OnClick handler


Thank you!  Delphi 4 does have the Mouse object, but the book I've been
using is for V3, and doesn't
mention it.

I got it working, with a little fudging to translate the screen
coordinates to the main form, and then to
the TImage I am using.  Any idea how to find out where on the form the
client rectangle is?  Form
Top and Left get screen -> form, and Image Top, Left get the form's
client rectange to the image,
but where on the form is the client rectangle?  i.e., how much space is
used by the title bar, borders,
etc?

Thanks again.

Tom Crone

Re:Getting Mouse position in OnClick handler


try the GetClientRect Window API Call - From MSDN

BOOL GetClientRect(
  HWND hWnd,      // handle to window
  LPRECT lpRect   // address of structure for client coordinates
);

use it like

var
  r : TRect;

if GetClientRect(handle, r) then
  Begin
    // do whatever
  end
else
  begin
    //error code here
  end

is that what you are after?

if you want to find the height of the title bar you might want to check out
the GetSystemMetrics API Call
Some Contstants you might need are
for window border width and height

SM_CXEDGE,SM_CYEDGE

for titlebar height
SM_CXSIZE, SM_CYSIZE

you might want to check MSDN (http://msdn.microsoft.com) for more
constants... there are a but load - to many to post here...

Quote
<tomn...@erols.com> wrote in message news:3C9009B4.52D81DE6@erols.com...
> Thank you!  Delphi 4 does have the Mouse object, but the book I've been
> using is for V3, and doesn't
> mention it.

> I got it working, with a little fudging to translate the screen
> coordinates to the main form, and then to
> the TImage I am using.  Any idea how to find out where on the form the
> client rectangle is?  Form
> Top and Left get screen -> form, and Image Top, Left get the form's
> client rectange to the image,
> but where on the form is the client rectangle?  i.e., how much space is
> used by the title bar, borders,
> etc?

> Thanks again.

> Tom Crone

Other Threads