Here is a short summary of the problem:
I move the mouse pointer quickly from control 1 to control 2.
In IDE, the sequence is this:
Control 1: Enter
Control 1: Leave
Control 2: Enter
Control 2: Leave
When compiled, the sequence is this (sometimes, but not always):
Control 1: Enter
Control 2: Enter
Control 1: Leave
Control 2: Leave
Here is the full description of the problem:
I'm subclassing a usercontrol.
I process WM_MOUSEMOVE and WM_MOUSELEAVE.
When WM_MOUSEMOVE occurs, and the mouse pointer hasn't been on the control before, I detect it as "Enter".
Then I track the mouse event using the following code:
'Track the mouse leaving the indicated window
Private Sub TrackMouseLeave(ByVal lng_hWnd As Long)
Dim tme As TRACKMOUSEEVENT_STRUCT
With tme
.cbSize = Len(tme)
.dwFlags = TME_LEAVE
.hwndTrack = lng_hWnd
End With
Call TrackMouseEvent(tme)
End Sub
When WM_MOUSELEAVE occurs, I know that the mouse pointer has left the control.
It works perfectly: fine.
When I move the mouse pointer inside the control, the "Enter" event occurs. When I move the mouse outside the control, the "Leave" enter occurs.
Now I try the same again with very rapid mouse movements where I move the mouse pointer quickly into and out of control. It works perfectly fine, no matter how fast I do it. The Enter-Leave-Enter-Leave sequence is perfectly fine: Enter-Leave-Enter-Leave, etc.
Now I duplicate the control so that I have 2 of them next to each other:
I quickly move the mouse pointer from control 1 to control 2.
The sequence is still perfectly fine: Enter-Leave-Enter-Leave.
Now I compile the project and run the exe:
I do the same: I quickly move the mouse pointer from control 1 to control 2.
Now the following sequence occurs:
Control 1: Enter
Control 2: Enter
Control 1: Leave
Control 2: Leave
I thought that the sequence was fixed and not as "variable" as could be observed here.
What have I not thought of? What baffles me is that it works as expected in IDE, but not predictable when compiled.
To debug what is happening, I have tried Spy++, but it only reports WM_MOUSEMOVE, so I have no idea what else I could try now to find out if the message pumps receives it in the "correct" order, and for some reason, it just gets messed up in my application.
Thank you for any help.