Jump to content
Steve Maughan

How to "eat" the second OnMouseDown / OnMouseUp events after a DblClick?

Recommended Posts

I have a TPaintBox where I normally process OnMouseDown, OnMouseMove and OnMouseUp events. I'd like to perform an action using the DoubleClick even. It seems that when the user double clicks the order of events is as follows:

  1. OnMouseDown
  2. OnMouseUp
  3. OnDblClick
  4. OnMouseDown
  5. OnMouseUp

I'd like to cancel / "eat" the second OnMouseDown and OnMouseUp events. How can I do this? Setting them to "nil" doesn't seem to work.

 

Thanks - Steve

Share this post


Link to post

I figured it out. Set a flag on the DblClick event, exit out of the OnMouseDown if the flag is set, then do the same for OnMouseUp but also reset the flag.

Share this post


Link to post

Looks like I haven't figured it out at all. It seems much more complex.

 

Here's the order of events:

  1. OnMouseDown (processed with no problem)
  2. OnMouseUp (processed with no problem)
  3. OnDblClick - I'm showing a form for the user at this point. The GUI is recording the mousemove actions and generating OnMouseMove messages
  4. OnMouseDown - the second OnMouseDown of the double click, which can be ignored using a flag
  5. OnMouseUp - the second OnMouseUp of the double click, which can be ignored using a flag, and the fag can be reset
  6. Multiple OnMouseMove - then all of the OnMouseMove messages that were generated while the form was showing are now processed

How do I either ensure the OnMouseMove messages aren't generated when the form is shown, or how do I remove them from the message queue?

 

Here's a short video that shows the behavior:

 

 

All help appreciate! Thanks,

 

Steve

 

Share this post


Link to post

We just had a similar discussion the other day.

Take a look at my solution (on the bottom of the thread) and try to adopt it. Use it only on the form you really need it, but if you are going to show a modal

form from the dobule-click handler there is no guarantee that the following messages are captured by your map's form but by the newly created/shown modal form.

 

You can also try to just to call ReleaseCapture before showing the modal window.

 

 

Edited by Attila Kovacs

Share this post


Link to post

Hi Attila,

 

Thanks! Yes - I managed to get it working using a similar technique. I set a flag in the DblClick event and then sent a message to clear the flag.

 

Steve

Share this post


Link to post

Perhaps these old routines can help you. They are Windows-only, though.

 

{!
<summary>
 Remove all key messages from the calling thread's message queue.</summary>
}
procedure EmptyKeyQueue;
var
  Msg: TMsg;
begin
  while PeekMessage(Msg, 0, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE or PM_NOYIELD) do
    ;
end;

{!
<summary>
 Remove all mouse messages from the calling thread's message queue.</summary>
}
procedure EmptyMouseQueue;
var
  Msg: TMsg;
begin
  while PeekMessage(Msg, 0, WM_MOUSEFIRST, WM_MOUSELAST,
    PM_REMOVE or PM_NOYIELD) do
    ;
end;

{!
<summary>
 Remove all key and mouse messages from the calling thread's message queue.</summary>
}
procedure DiscardPendingInput;
begin
  EmptyMouseQueue;
  EmptyKeyQueue;
end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×