Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How To Distinguish Between Single And Double-Click?

1 view
Skip to first unread message

Robert M. Cohen

unread,
Feb 7, 2001, 3:55:55 PM2/7/01
to
I'd like to be able to do different things when a control/form is either
single-clicked or double-clicked. However, it seems that any double-click
first passes through the single-click handler. Is there any way to prevent
this???

Thanks,
Bob Cohen


Jonathan Allen

unread,
Feb 7, 2001, 4:39:27 PM2/7/01
to
> Is there any way to prevent
> this???

I don't think so. It would involve the OS pausing long enough to determine
if a second click is coming. That would result in an annoying delay if you
really did click just once.

Also, some people double click on command buttons and such when first
starting out. By trapping the single click first, they are not hampered.
Thus this behavior is expected.

--
Jonathan Allen


"Robert M. Cohen" <robert...@hotmail.com> wrote in message
news:#u5CFiUkAHA.1320@tkmsftngp04...

Robert M. Cohen

unread,
Feb 8, 2001, 2:31:52 AM2/8/01
to
It seems to me that the OS does distinguish single and double clicks all
over the place right now. For instance the recognition delay is
programmable in the mouse control panel. Also, MFC readily handles this
issue. My feeling is that this is a .NET and/or C# issue only.

Thanks,
Bob Cohen


"Jonathan Allen" <greyw...@bigfoot.com> wrote in message
news:#x1N8RVkAHA.236@tkmsftngp04...

Jonathan Allen

unread,
Feb 8, 2001, 4:14:29 AM2/8/01
to
> Also, MFC readily handles this
> issue.

Does it?

MFC docs...
*******
Double-clicking the left mouse button actually generates a sequence of four
messages: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBLCLK, and WM_LBUTTONUP.
*******

Since the message sequence (WM_LBUTTONDOWN, WM_LBUTTONUP) triggers a click
event, I don't see how it can. For what you want to occure, you would have
to ignore the first two messages. But the only way to know if it should be
ignored is if you can see into the future and predict the third message,
WM_LBUTTONDBLCLK.

> For instance the recognition delay is
> programmable in the mouse control panel.

All that controls is the max time difference between the first and second
click. It does not provide the magical ability needed to predict a
double-click.

**************************

To acomplish your goal, you would need to follow these steps...

1. Determine the max delay for a Double Click, add 1 unit of time.
2. Sink the Click event and record the time.
3. Start a timer to be triggered at ([1] + [2])

A_4. Sink the DoubleClick Event
A_5. Stop the timmer so that the Click will be ignored
A_6. Handle the DoubleClick Event

B_4. Handle the Click Event. (Since DoubleClick didn't occur in time)

If you do this, you don't have to worry about the Click preceding the
DoubleClick. However you get a delay of [1] to all Click events, which can
be considerable. Intentionally making a program unresponsive is hardly the
way to develope a professional grade application.

**************************

Now that nonsense is settled, lets take a look at your design itself.
Exactly what are you trying to acomplish, and why do you think you need a
Click event that cannot precede a DoubleClick event?

--
Jonathan Allen

"Robert M. Cohen" <robert...@hotmail.com> wrote in message

news:e1ibWFakAHA.2068@tkmsftngp02...

David Lowndes

unread,
Feb 8, 2001, 7:16:45 AM2/8/01
to

Bob,

The usual way of accomplishing this is to handle the single click,
start a timer for a little longer than the system defined double click
time. If you get a double click event, kill the timer and do your
double click action, if the timer fires, do your single click event.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.

Ken Alverson

unread,
Feb 8, 2001, 7:24:29 AM2/8/01
to
"Robert M. Cohen" <robert...@hotmail.com> wrote in message
news:e1ibWFakAHA.2068@tkmsftngp02...

> It seems to me that the OS does distinguish single and double clicks all
> over the place right now. For instance the recognition delay is
> programmable in the mouse control panel. Also, MFC readily handles this
> issue. My feeling is that this is a .NET and/or C# issue only.

At every level I know of, down to the Petzold style window proc, a double
click will be preceeded by a click. The usual solution is to make the
double click gracefully follow a click. For example in explorer, first
click selects, double click executes. In word, first click sets cursor,
second click selects word. As Jonathan Allen pointed out, if you must
detect double click without handling the preceeding single click, you need
to wait the appropriate amount of time. But your users will probably become
irate that your program doesn't respond to single clicks very quickly...

Ken


Robert M. Cohen

unread,
Feb 8, 2001, 7:32:59 AM2/8/01
to
OK, right. Here's why I never remembered getting into trouble with MFC on
this: MFC doesn't contain a single click event, does it? It just has the
downs/ups and doubles. I'm in trouble in C# because I've also got the click
event. I think I need to experiment with not having the click, but just
using the downs/ups and doubles.

What I want to program is the ability to double-click a control on a form
and get a properties window up, but a single click selects the object (i.e.
outlines it).

Thanks,
Bob


"Jonathan Allen" <greyw...@bigfoot.com> wrote in message

news:u8ECFcbkAHA.1568@tkmsftngp04...

Robert M. Cohen

unread,
Feb 8, 2001, 8:07:16 AM2/8/01
to
Yes, I can see the "intent" issue more clearly now. I guess that it does
make sense to use the first click to do the selection and the second click
to do the properties. After all, the user would be doing the 'properties'
on the 'selected' control.

In studying this whole thing, however, another issue cropped up: I built a
little applet to show me mousestroke sequences and for a double click I'm
seeing Down/Up/Click/DoubleClick/Down/Up.

That is different from the MFC sequence that Jonathan Allen pointed out to
me (Down/Up/DoubleClick/Up). That creates a problem in that if I do my
dialog at the doubleclick, I get what looks like a phantom mouse down
immediately afterwards. I'm equipped to handle an "unattached" mouse up,
but that next mouse down takes me to places I really don't want to be.

Any ideas on that one???

Thanks,
Bob Cohen

"Ken Alverson" <K...@Alverson.com> wrote in message
news:OQspOpckAHA.2172@tkmsftngp02...

Robert M. Cohen

unread,
Feb 8, 2001, 8:14:47 AM2/8/01
to
In answer to my own question, I set up a private doubleclick bool and set it
to true in the doubleclick handler. Then, when I get any mouse down and the
doubleclick bool is true (implying the "phantom" down), I unset the bool and
just kick out. Of course, I'll have to recheck all of this on Beta 2!!!

Bob Cohen


"Robert M. Cohen" <robert...@hotmail.com> wrote in message

news:#tZXxAdkAHA.1136@tkmsftngp04...

Robert M. Cohen

unread,
Feb 8, 2001, 8:31:23 AM2/8/01
to
BTW, thanks to all of you for "talking this out" with me...

Bob Cohen


"Robert M. Cohen" <robert...@hotmail.com> wrote in message

news:eZ2T#EdkAHA.2180@tkmsftngp05...

Jonathan Allen

unread,
Feb 8, 2001, 2:52:34 PM2/8/01
to
No problem. It is always nice to help someone who will actually listen. Many
people are too stubborn to step back and consider changing their design to
fit the realities of the situation.

--
Jonathan Allen


"Robert M. Cohen" <robert...@hotmail.com> wrote in message

news:#lQ7POdkAHA.2180@tkmsftngp05...

Jonathan Allen

unread,
Feb 8, 2001, 2:49:03 PM2/8/01
to
> What I want to program is the ability to double-click a control on a form
> and get a properties window up, but a single click selects the object
(i.e.
> outlines it).
>

Unless selecting an object will kill your program, I don't see the problem.
Besides, they probably want the properties of the object they double-clicked
on.

--
Jonathan Allen

"Robert M. Cohen" <robert...@hotmail.com> wrote in message

news:OI$intckAHA.2080@tkmsftngp05...

Robert M. Cohen

unread,
Feb 9, 2001, 12:51:56 PM2/9/01
to
How else does one learn???

Bob Cohen


"Jonathan Allen" <greyw...@bigfoot.com> wrote in message

news:#OM8VRhkAHA.1664@tkmsftngp03...

me

unread,
Feb 9, 2001, 10:47:50 PM2/9/01
to
If I may share my thoughts on this, the mouse also have a right button
(unless your users are Mac people, where the mouse has that large, single
button). If you wanted to enable single-click property display
functionality, you could simply program the single left-button click as
select, and make the single right-button click as property window display.
Though not standard practice, there are programs that do it, such as ICQ,
where you can select your preference for right-or-left click functionality.
Doing this, you have still the option of making the (in this case) infamous
double-click do something else.


Juan Galvez

"Ken Alverson" <K...@Alverson.com> wrote in message
news:OQspOpckAHA.2172@tkmsftngp02...

Robert M. Cohen

unread,
Feb 10, 2001, 11:37:41 AM2/10/01
to
Yes, generally I prefer to be "standardized" in terms of left/right button
usage. At the moment I've pretty much reserved the right mouse button for
object context menus. And, it seems, that when a context menu is attached
to a form it pretty much takes over the right mouse button. For instance, I
never see the OnMouseDown occur when I right click an object with a context
menu attached.

Thanks,
Bob Cohen


"me" <juan_...@hotmail.com> wrote in message
news:OsO$3TykAHA.2156@tkmsftngp05...

Peter Torr (MS)

unread,
Feb 10, 2001, 6:36:33 PM2/10/01
to
"Jonathan Allen" <greyw...@bigfoot.com> wrote in message
news:u8ECFcbkAHA.1568@tkmsftngp04...

> Exactly what are you trying to acomplish, and why do you think you need a
> Click event that cannot precede a DoubleClick event?


Actually, Windows Explorer distinguishes between the two. If something is
selected, and you single-click on it, it waits for a fraction of a second
(waiting for a double-click) and then edits the name of the item. If you
happen to double-click, it opens the item.

Whether or not this is a good design is, of course, questionable, but there
certainly exists a precedent. Having actually read the design requirement of
the current problem at hand, though, I think that the double-click case
should logically also call the single-click case.

Peter

--
Peter Torr - pt...@microsoft.com
JScript .NET / VSA Runtime Program Manager
Please post all questions to the group. Thanks.

Robert M. Cohen

unread,
Feb 11, 2001, 3:25:39 AM2/11/01
to
Yes, that's where I ended up.

However, I have also bugged what I consider a problem in that the
double-click returns the following sequence:

Down/Up/Double-Click/Down/Up.

That second down is different than the MFC version (Down/Up/Double-Click/Up)
and leads to a "spurious" keystroke after the double-click. For instance if
I want to do a properties dialog on an object via a double-click, then the
first thing that happens when the dialog is done is to get another click.
This following click really isn't there and really isn't what the user
intended.

Bob Cohen


"Peter Torr (MS)" <pt...@microsoft.com> wrote in message
news:#QBtd28kAHA.1316@tkmsftngp03...

Jonathan Allen

unread,
Feb 11, 2001, 3:59:37 PM2/11/01
to
"Peter Torr (MS)" <pt...@microsoft.com> wrote in message
news:#QBtd28kAHA.1316@tkmsftngp03...
> Actually, Windows Explorer distinguishes between the two. If something is
> selected, and you single-click on it, it waits for a fraction of a second
> (waiting for a double-click) and then edits the name of the item. If you
> happen to double-click, it opens the item.

Good point. Do you know if it does that with a message from the OS or just a
timer?

--
Jonathan Allen


0 new messages