Microsoft KB Archive/240749

= BUG: WM_LBUTTONUP Message May Not Fire =

Article ID: 240749

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q240749



SYMPTOMS
If the validate event of a TextBox displays a MessageBox, shifting the focus to another control using the mouse causes the MessageBox to display. It also causes the WM_LBUTTONUP message for the control receiving the focus to be lost.

For example, if the control that is receiving the focus is a CommandButton, the Click event is not fired. If the control that is receiving the focus is a TextBox, notice that it appears to be in the selection state as if the left-mouse button is pressed.



CAUSE
When the message box is displayed, the focus moves to the message box, so the control that gets the focus does not get the WM_LBUTTONUP message.



RESOLUTION
To solve the problem, you can send a WM_LBUTTONUP message programmatically to the control that gets the focus.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Create a Standard EXE project. Form1 is created by default. Add two TextBoxes and one CommandButton to Form1.  Add the following code to the code window of Form1: Option Explicit

Private Sub Text1_Validate(Cancel As Boolean) MsgBox "Text1 Validate Message" End Sub

Private Sub Text2_MouseDown(Button As Integer, Shift As Integer, _                           X As Single, Y As Single) Debug.Print "Text2 Mouse Down" End Sub

Private Sub Text2_MouseUp(Button As Integer, Shift As Integer, _                         X As Single, Y As Single) Debug.Print "Text2 Mouse Up" End Sub

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, _                              X As Single, Y As Single) Debug.Print "Command1 Mouse Down" End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, _                            X As Single, Y As Single) Debug.Print "Command1 Mouse Up" End Sub

Private Sub Command1_Click MsgBox "Command1 Click" End Sub  Run the application. Move the focus to Text1 and then either select Text2 or click Command1. Observe the debug output in the immediate window and notice that the MouseUp event does not fire. You can also observe the other behavior described in the SYMPTOMS section.

Steps to Work Around the Behavior
To work around the problem, you can send the WM_LBUTTONUP message in the GotFocus event handler of all the controls that may affect the behavior of your project if WM_LBUTTONUP is lost, or you can send WM_LBUTTONUP message to all the controls on the form. The example here uses the second method.   Building on the sample above, add the following code to the code window of Form1: Private Const WM_LBUTTONUP = &H202

Private Declare Function PostMessage Lib "user32" _ Alias "PostMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, _   ByVal wParam As Long, ByVal lParam As Long) As Long

Private Sub ForceMouseUp Dim ctl As Control For Each ctl In Me.Controls PostMessage ctl.hwnd, WM_LBUTTONUP, 0, ByVal 0 Next End Sub </li>  Change the Text1_Validate event handler to be: Private Sub Text1_Validate(Cancel As Boolean) MsgBox "Text1 Validate Message" ForceMouseUp End Sub </li> Run the application and you can see the correct behavior.NOTE: You only need to call the ForceMouseUp when you do not want to set Cancel to True.</li></ol>

Keywords: kbbug kbpending KB240749

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.