PRB: No Events Generated When Msgbox Active

Last reviewed: June 21, 1995
Article ID: Q76557
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 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

  1. 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
    
    

  2. Add the following code to the Form_Paint event:

       Sub Form_Paint ()
          Line (0, 0)-(ScaleWidth - 1, ScaleHeight - 1), &HFF, BF
       End Sub
    
    

  3. 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.

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


  • Additional reference words: 2.00 3.00
    KBCategory: kbprg kbcode kbprb
    KBSubcategory: APrgOther


    THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

    Last reviewed: June 21, 1995
    © 1998 Microsoft Corporation. All rights reserved. Terms of Use.