Microsoft KB Archive/76557

= PRB: No Events Generated When Msgbox Active =

Article ID: 76557

Article Last Modified on 12/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q76557



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.



Steps to Demonstrate Behavior
 Start Visual Basic or from the File menu, choose New Project if Visual Basic is already running.  Add the following code to the general declarations section: ' Enter the following Declare statement on one, single line: Declare Function MessageBox Lib &quot;User&quot; (ByVal hWnd As Integer, ByVal lpText     As String, ByVal lpCaption As String, ByVal wType As Integer) As Integer   Add the following code to the Form_Click event: Sub Form_Click MsgBox &quot;move me&quot;, 0, &quot;MsgBox&quot; unused = MessageBox(hWnd, &quot;move me&quot;, &quot;MessageBox&quot;, 0) End Sub   Add the following code to the Form_Paint event: Sub Form_Paint Line (0, 0)-(ScaleWidth - 1, ScaleHeight - 1), &HFF, BF  End Sub  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.</li> Click OK to display the MessageBox API dialog. When you drag this dialog box around, the form is repainted.</li></ol>

Additional query words: 2.00 3.00

Keywords: kbprb KB76557

-

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

© Microsoft Corporation. All rights reserved.