Board index » delphi » Problems with catching click and double click

Problems with catching click and double click

Hello,

In my component I want to respond to both an onClick and an onDblClick event.
At this moment I do it this way:

procedure TWinIcon.WndProc(var Message : TMessage);
begin
  If Message.Msg = SZ_TOOLICON then
  begin
    Case Message.lParam of
      WM_LBUTTONUP     : If Assigned(OnClick) then OnClick(self);
      WM_LBUTTONDBLCLK : If Assigned(OnDblClick) then OnDblClick(self);
    end;
  end;
end;

Problem here is that a double click also generates two click events.
Has anyone an idea how to filter the two onClick events generated at the time
that I've got the onDblClick event?

Bye!

Arjan

=========================================================
Arjan van de Logt author of Yer Winlogo and other utils.
E-mail Arjan_van_de_L...@wxs.nl

Quote
>(Replace all underscores [_] with dots [.] to reply!!!)

http://www.tomb.demon.nl
=========================================================
 

Re:Problems with catching click and double click


On Mon, 12 Jan 1998 14:45:48 GMT, Arjan_van_de_L...@wxs.nl (Arjan)
wrote:

Quote
>Hello,

>In my component I want to respond to both an onClick and an onDblClick event.
>At this moment I do it this way:

>procedure TWinIcon.WndProc(var Message : TMessage);
>begin
>  If Message.Msg = SZ_TOOLICON then
>  begin
>    Case Message.lParam of
>      WM_LBUTTONUP     : If Assigned(OnClick) then OnClick(self);
>      WM_LBUTTONDBLCLK : If Assigned(OnDblClick) then OnDblClick(self);
>    end;
>  end;
>end;

>Problem here is that a double click also generates two click events.
>Has anyone an idea how to filter the two onClick events generated at the time
>that I've got the onDblClick event?

>Bye!

>Arjan

>=========================================================
>Arjan van de Logt author of Yer Winlogo and other utils.
>E-mail Arjan_van_de_L...@wxs.nl
>>(Replace all underscores [_] with dots [.] to reply!!!)
>http://www.tomb.demon.nl
>=========================================================

Try changing the order of your case statements so that the
Double-click is checked first.

Re:Problems with catching click and double click


In article <34bc2c7f.8383...@news.wxs.nl>, Arjan_van_de_L...@wxs.nl (Arjan)
writes:

Quote
>Problem here is that a double click also generates two click events.
>Has anyone an idea how to filter the two onClick events generated at the time
>that I've got the onDblClick event?

The only way to do this is to wait after the mouse-down for a short time to see
if there's a mouse-up within the double-click time limit. If there is, then do
the double-click, if there's not, then do the mouse-up.

But I would have thought the only place to do this is in the windows O/S itself
- in other words windows should send the appropriate message _after_ deciding
which it is. Is this so and your problem is a mis-conceptional non-happening,
or does your problem really happen <g>.

BTW altering the order of your case statements should have _no_ effect on this,
unless you also put additional case statements and additional message checks in
the case statement as I outlined above. The case order is a logic separation,
not a time priority for dealing with the cases. In other words, the WMessages
are still there in the message queue and will be handled anyway.

Alan Lloyd
alangll...@aol.com

Re:Problems with catching click and double click


Quote
>On Mon, 12 Jan 1998 14:45:48 GMT, Arjan_van_de_L...@wxs.nl (Arjan)
>wrote:

>>Hello,

>>In my component I want to respond to both an onClick and an onDblClick event.
>>At this moment I do it this way:

>>procedure TWinIcon.WndProc(var Message : TMessage);
>>begin
>>  If Message.Msg = SZ_TOOLICON then
>>  begin
>>    Case Message.lParam of
>>      WM_LBUTTONUP     : If Assigned(OnClick) then OnClick(self);
>>      WM_LBUTTONDBLCLK : If Assigned(OnDblClick) then OnDblClick(self);
>>    end;
>>  end;
>>end;

>>Problem here is that a double click also generates two click events.
>>Has anyone an idea how to filter the two onClick events generated at the time
>>that I've got the onDblClick event?

>>Bye!

>>Arjan

>>=========================================================
>>Arjan van de Logt author of Yer Winlogo and other utils.
>>E-mail Arjan_van_de_L...@wxs.nl
>>>(Replace all underscores [_] with dots [.] to reply!!!)
>>http://www.tomb.demon.nl
>>=========================================================

>Try changing the order of your case statements so that the
>Double-click is checked first.

Nope, won't work at all.
Here are the messages you'll get if your control accepts double clicks:
(csDoubleClicks in ControlStyle) and you double click on it:

1. WM_LBUTTONDOWN
2. WM_LBUTTONUP
3. WM_LBUTTONDBLCLK
4. WM_LBUTTONUP

if your control does not handle dbl clicks
 (not (csDoubleClicks in ControlStyle)), you'll get
WM_LBUTTONDOWN in 3. above

Re:Problems with catching click and double click


On 13 Jan 1998 09:12:29 GMT, alangll...@aol.com (AlanGLLoyd) wrote:

Quote
>>Has anyone an idea how to filter the two onClick events generated at the time
>>that I've got the onDblClick event?

>The only way to do this is to wait after the mouse-down for a short time to see
>if there's a mouse-up within the double-click time limit.

Remember TControl defines a DblClick (among others) procedure which is
designed to handle double left clicks. If you have something you need
to do on the double click event you can simply override the original
DblClick method. Don't forget to call the inherited method :>

here's a very simple example. It's nothing more than a blank form
that, when you double click on it, beeps your computer (I used
MB_ICONQUESTION, but you may use any sound you like. check Delphi help
for information) :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  protected
    procedure DblClick; override;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.DblClick;
begin
  inherited DblClick;
  MessageBeep(MB_ICONQUESTION);
end;
end.

Remember, there are two sides to event handling:  through the OnXXXX
and through Event Method Override.  The OnXXXX property is meant for
the 'end user' to instert needed code to perform wanted actions. The
EMO (Event Method Override) is meant for the component architect to
modify default behavior.  When do you use EMO? When there is no OnXXXX
event or when some action must occur before the OnXXXX routine
executes.
jcko...@4dcomm.com
------------------
The following is a brief political announcement.   Thank you.

Other Threads