Page 1 of 1

Up-down problem in all controls

Posted: 08 Nov 2009, 08:28
by TickTick
When you click a native MS control quickly, and then suddenly stop clicking and hold the mouse down, the control will always reflect the mouse down. In all your controls, this is not the case: Sometimes the control shows a down state, sometimes and up state.

Edit: Well, I must be fair: The MS combo also has this bug...

Re: Up-down problem in all controls

Posted: 08 Nov 2009, 10:47
by TiKu
Yeah, I know. But I have absolutly no clue why this is happening.

Re: Up-down problem in all controls

Posted: 08 Nov 2009, 14:53
by TickTick
This is a known behaviour which confuses some people.

Post this code into a form:

Option Explicit

Private bDown As Boolean

Private Sub Form_DblClick()

Debug.Print "dblclick"

End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Debug.Print "down"

bDown = True

End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

Debug.Print "up"

Debug.Assert bDown

bDown = False

End Sub

Now click quickly on the form.
The code will stop here:

down
up
dblclick
up

You see?
I cannot see your code, but I think you assume that when the event "DblClick" occured, the mouse is always up (which doesn't have to be the case).

Re: Up-down problem in all controls

Posted: 09 Nov 2009, 15:51
by TiKu
It's not that easy.
First, the events simply reflect the messages sent to the control window by Windows. So if you see an event sequence of Down, Up, DblClick, Up, this means that the control window received WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBLCLK, WM_LBUTTONUP. If I remember correctly, this message sequence is the same for a trivial C++ app (dialog + button), which does nothing more than logging the messages the button receives. So there's nothing wrong with the events.
Second, the button (and any other control of mine) is drawn by Windows, not by my code. The internal state (down/up) of the button is also managed by Windows. So the wrong state seems to be Windows' fault. On the other hand, I cannot reproduce this behavior with a C++ app, so it really seems to be my code that's wrong.