PRB: No Events Generated When Msgbox Active

ID: Q76557


The information in this article applies to:
  • Microsoft Visual Basic Standard and Professional Editions for Windows, versions 2.0, 3.0


SYMPTOMS

Visual Basic does not invoke the Paint event or any other event for controls or forms while a MsgBox or InputBox is active.


CAUSE

This behavior is by design. All events (including the timer control event) are disabled while a MsgBox is showing. The purpose is to block operations that could cause problems.


WORKAROUND

To compensate for Paint events not firing, you can set the form AutoRedraw property to True and paint the form from the Form_Load event.

To display a MsgBox-like dialog and allow all events to occur, you can:

  • Call the Windows API function MessageBox.


  • Display a modal form (formN.Show 1), which looks like the MsgBox dialog.



STATUS

This behavior is by design.


MORE INFORMATION

Steps to Demonstrate Behavior

  1. Start Visual Basic or from the File menu, choose New Project if Visual Basic is already running.


  2. Add the following code to the general declarations section:
    
       ' Enter the following Declare statement on one, single line:
       Declare Function MessageBox Lib "User" (ByVal hWnd As Integer, ByVal
    lpText
          As String, ByVal lpCaption As String, ByVal wType As Integer) As
    Integer 


  3. Add the following code to the Form_Click event:
    
       Sub Form_Click ()
          MsgBox "move me", 0, "MsgBox"
          unused = MessageBox(hWnd, "move me", "MessageBox", 0)
       End Sub 


  4. Add the following code to the Form_Paint event:
    
       Sub Form_Paint ()
          Line (0, 0)-(ScaleWidth - 1, ScaleHeight - 1), &HFF, BF
       End Sub 


  5. Run the application. Click the form to display the MsgBox dialog. When you drag this dialog box around on the form, the Paint event is not fired and the area previously occupied by the MsgBox is not updated.


  6. Click OK to display the MessageBox API dialog. When you drag this dialog box around, the form is repainted.


Additional query words: 2.00 3.00

Keywords :
Version :
Platform :
Issue type :


Last Reviewed: September 16, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.