 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Sreekanth Reddy Bandi Guest
|
Posted: Wed Apr 28, 2004 10:37 am Post subject: how to detech mouse coordinates X and Y in dblclick event |
|
|
Hi,
Can you help me how to detect mouse co-ordinates X, Y where dblclick event
is happened on a form?
Many Thanks in advance,
Sreekanth
|
|
| Back to top |
|
 |
Andrue Cope Guest
|
Posted: Wed Apr 28, 2004 10:52 am Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
On Wed, 28 Apr 2004 16:07:43 +0530, Sreekanth Reddy Bandi wrote:
| Quote: | Can you help me how to detect mouse co-ordinates X, Y where dblclick event
is happened on a form?
|
Make a note of them in OnMouseUp.
--
Andrue Cope
[Bicester UK]
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Wed Apr 28, 2004 10:58 am Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
Sreekanth Reddy Bandi wrote:
| Quote: | Can you help me how to detect mouse co-ordinates X, Y where dblclick event
is happened on a form?
|
There are several ways.
You can use the GetCursorPos function and convert the coordinates
to the form coordinates.
You could also take two private variables
int Xpos;
int Ypos;
and in the MouseDown eventhandler (which has the X and Y as parameters,
and always comes before the DoubleClick event) assign X and Y to
Xpos resp. Ypos.
Then in the OnDoubleclick eventhandler use Xpos and Ypos.
Hans.
| Quote: | Many Thanks in advance,
|
?
Hans.
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Apr 28, 2004 5:40 pm Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
"Sreekanth Reddy Bandi" <sreekanth_reddy (AT) persistent (DOT) co.in> wrote
| Quote: | Can you help me how to detect mouse co-ordinates X,
Y where dblclick event is happened on a form?
|
You will have to use the GetCursorPos() function from the Win32 API, or the
global TMouse::CursorPos property from the VCL (older versions of the VCL
don't have a global TMouse object). Once you have the coordinates of the
mouse cursor on the screen, you can translate them into client coordinates
by using the form's ScreenToClient() method.
Gamit
|
|
| Back to top |
|
 |
Corey Murtagh Guest
|
Posted: Wed Apr 28, 2004 8:03 pm Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | "Sreekanth Reddy Bandi" <sreekanth_reddy (AT) persistent (DOT) co.in> wrote in message
news:408f897a (AT) newsgroups (DOT) borland.com...
Can you help me how to detect mouse co-ordinates X,
Y where dblclick event is happened on a form?
You will have to use the GetCursorPos() function from the Win32 API, or the
global TMouse::CursorPos property from the VCL (older versions of the VCL
don't have a global TMouse object). Once you have the coordinates of the
mouse cursor on the screen, you can translate them into client coordinates
by using the form's ScreenToClient() method.
|
GetCursorPos() will return the /current/ location of the mouse cursor,
which may be completely unrelated to its position at the time the
double-click event was generated. Only way to be sure is to save the
cursor position at the time of the event... MouseDown or MouseUp.
--
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur!"
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Apr 28, 2004 8:24 pm Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
"Corey Murtagh" <emonk (AT) slingshot (DOT) no.uce> wrote
| Quote: | GetCursorPos() will return the /current/ location of the
mouse cursor, which may be completely unrelated to
its position at the time the double-click event was generated.
|
Possibly, but only if message handling is delayed. If you are not blocking
the main VCL thread, then the coordinates will match (to within a few
pixels, anyway).
| Quote: | Only way to be sure is to save the cursor position at
the time of the event... MouseDown or MouseUp.
|
Actually, since OnDblClick is triggered in the context of a WM_LBUTTONDBLCLK
message, you could try calling GetMessagePos(), which will return the actual
cordinates of the mouse cursor at the time the message was first issued. Of
course, if the VCL is simulating that message at any time, GetMessagePos()
is useless. It will only work for messages retrieved from the main message
queue itself. But it is an alternative to consider.
Gambit
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Wed Apr 28, 2004 8:34 pm Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
Corey Murtagh wrote:
| Quote: | GetCursorPos() will return the /current/ location of the mouse cursor,
which may be completely unrelated to its position at the time the
double-click event was generated. Only way to be sure is to save the
cursor position at the time of the event... MouseDown or MouseUp.
|
Sorry, that makes no sense. The MouseUp and MousDown events are
also on a different time then the OnDoubleClick even.
Every solution will have the same problem.
Of course GetCursorpos should be called as first statement
in the OnDblClick eventhandler.
Hans.
|
|
| Back to top |
|
 |
Corey Murtagh Guest
|
Posted: Wed Apr 28, 2004 9:04 pm Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
Hans Galema wrote:
| Quote: | Corey Murtagh wrote:
GetCursorPos() will return the /current/ location of the mouse cursor,
which may be completely unrelated to its position at the time the
double-click event was generated. Only way to be sure is to save the
cursor position at the time of the event... MouseDown or MouseUp.
Sorry, that makes no sense. The MouseUp and MousDown events are
also on a different time then the OnDoubleClick even.
|
It makes perfect sense. The operating system sends 4 messages for a
double-clic sequence. For the left button they are:
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK
WM_LBUTTONUP
The VCL translates these messages into 5 events:
MouseDown
MouseUp
DoubleClick
MouseDown (fired in TControl::WMLButtonDblClk)
MouseUp
If the cursor has moved appreciably between the first mouse down and the
second, or if the MouseDown events are too far apart in time, the
DoubleClick doesn't get called. So the first MouseDown is within a
couple pixels at most of the location of the double-click.
| Quote: | Every solution will have the same problem.
|
Nope. Some solutions have no problems at all.
| Quote: | Of course GetCursorpos should be called as first statement
in the OnDblClick eventhandler.
|
If your program is busy doing something, or something else in the system
- which you have no control over - is making the system crawl when the
message is sent, your program may not process the double-click message
until much later. At that point the mouse cursor could be anywhere on
the screen. It doesn't matter at that point whether you call
GetCursorPos() immediately or at the last possible moment, you'll still
get a nonsense result.
Since TControl::WMLButtonDblClk() fires an extra MouseDown event using
the position and button data from the Windows WM_LBUTTONDBLCLK message,
the only way to get the exact information on where the double-click
happened is to set a flag in DblClick and test it in MouseDown. If the
flag is set, process a double-click and reset the flag.
It's a shame that the VCL doesn't provide positional and button
information in the call to OnDblClick, since it's available in the
windows message.
--
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur!"
|
|
| Back to top |
|
 |
Corey Murtagh Guest
|
Posted: Wed Apr 28, 2004 9:10 pm Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | "Corey Murtagh" <emonk (AT) slingshot (DOT) no.uce> wrote in message
news:40900f9a (AT) newsgroups (DOT) borland.com...
GetCursorPos() will return the /current/ location of the
mouse cursor, which may be completely unrelated to
its position at the time the double-click event was generated.
Possibly, but only if message handling is delayed. If you are not blocking
the main VCL thread, then the coordinates will match (to within a few
pixels, anyway).
|
Happens all too often unfortunately, especially on machines with limited
memory. There's no telling when the OS is going to decide to give a
couple of seconds of time to some other process before getting back to you.
| Quote: | Only way to be sure is to save the cursor position at
the time of the event... MouseDown or MouseUp.
|
Actually I was wrong. I didn't check before I sent that, although the
above method is /almost/ accurate. See my response to Hans for a better
explanation and fully accurate solution.
| Quote: | Actually, since OnDblClick is triggered in the context of a WM_LBUTTONDBLCLK
message, you could try calling GetMessagePos(), which will return the actual
cordinates of the mouse cursor at the time the message was first issued. Of
course, if the VCL is simulating that message at any time, GetMessagePos()
is useless. It will only work for messages retrieved from the main message
queue itself. But it is an alternative to consider.
|
You could intercept WM_LBUTTONDBLCLK, since that message includes
positional information anyway. It's possible to be accurate without
messing with messages however.
--
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur!"
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Apr 28, 2004 9:57 pm Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
"Corey Murtagh" <emonk (AT) slingshot (DOT) no.uce> wrote
| Quote: | Since TControl::WMLButtonDblClk() fires an extra
MouseDown event using the position and button data
from the Windows WM_LBUTTONDBLCLK message,
the only way to get the exact information on where the
double-click happened is to set a flag in DblClick and test
it in MouseDown.
|
A better solution is to simply do all of the handling in OnMouseDown only.
During a double-click operation, the Shift parameter will include the
ssDouble flag.
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Apr 28, 2004 9:58 pm Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
"Corey Murtagh" <emonk (AT) slingshot (DOT) no.uce> wrote
| Quote: | It's a shame that the VCL doesn't provide positional
and button information in the call to OnDblClick, since
it's available in the windows message.
|
The same could be said for the OnClick event as well.
Gambit
|
|
| Back to top |
|
 |
Corey Murtagh Guest
|
Posted: Wed Apr 28, 2004 10:17 pm Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | "Corey Murtagh" <emonk (AT) slingshot (DOT) no.uce> wrote in message
news:40901da4 (AT) newsgroups (DOT) borland.com...
Since TControl::WMLButtonDblClk() fires an extra
MouseDown event using the position and button data
from the Windows WM_LBUTTONDBLCLK message,
the only way to get the exact information on where the
double-click happened is to set a flag in DblClick and test
it in MouseDown.
A better solution is to simply do all of the handling in OnMouseDown only.
During a double-click operation, the Shift parameter will include the
ssDouble flag.
|
lol... would you believe I have /never/ seen that flag before? I
skipped over it while reading the source and everything.
So, our definitive 'position of a double-click' solution: use
OnMouseDown and check for shift.Contains(ssDouble).
Nice :)
--
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur!"
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Thu Apr 29, 2004 11:21 am Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
Corey Murtagh wrote:
| Quote: | It makes perfect sense. The operating system sends 4 messages for a
double-clic sequence. For the left button they are:
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK
WM_LBUTTONUP
The VCL translates these messages into 5 events:
MouseDown
MouseUp
DoubleClick
MouseDown (fired in TControl::WMLButtonDblClk)
MouseUp
|
You omitted one:
FormMouseDown
FormClick
FormMouseUp
FormDblClick
FormMouseDown
FormMouseUp
| Quote: | If the cursor has moved appreciably between the first mouse down and the
second,
|
Yes than there is inaccuracy. I always advise a steady hand. <g>
| Quote: | or if the MouseDown events are too far apart in time, the
DoubleClick doesn't get called.
|
Indeed.
| Quote: | Nope. Some solutions have no problems at all.
Since TControl::WMLButtonDblClk() fires an extra MouseDown event using
the position and button data from the Windows WM_LBUTTONDBLCLK message,
the only way to get the exact information on where the double-click
happened is to set a flag in DblClick and test it in MouseDown. If the
flag is set, process a double-click and reset the flag.
|
That could be a nice solution then. The first time I see that here.
| Quote: | It's a shame that the VCL doesn't provide positional and button
information in the call to OnDblClick, since it's available in the
windows message.
|
Indeed. I was very amazed, when I bought bcb1 and discovered that.
That too much object-oriented approch caused many people problems since.
Hans.
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Thu Apr 29, 2004 11:25 am Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | A better solution is to simply do all of the handling in OnMouseDown only.
During a double-click operation, the Shift parameter will include the
ssDouble flag.
|
Well that is a very nice discovery. How did you find out ?
Why didn't you tell before ?
Events for a single click:
FormMouseDown
FormClick
FormMouseUp
Events for a doubleclick:
FormMouseDown
FormClick
FormMouseUp
FormDblClick
FormMouseDown Shift Contains ssDouble
FormMouseUp
I know how you found out. It's in the help for TShiftState.
Hans.
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Apr 29, 2004 7:43 pm Post subject: Re: how to detech mouse coordinates X and Y in dblclick even |
|
|
"Hans Galema" <dontusethis (AT) dontusethis (DOT) nl> wrote
| Quote: | Well that is a very nice discovery. How did you find out ?
|
Reading the documentation for starters ;-)
TShiftState Type
TShiftState indicates the state of the Alt, Ctrl, and Shift keys and the
mouse buttons.
...
ssDouble The mouse was double-clicked.
Then looking at the actual VCL source code to see what it is ACTUALLY doing.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|