Microsoft KB Archive/77316

= How to Determine Display State of a VB Form, Modal or Modeless =

Article ID: 77316

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
 * Microsoft Visual Basic 1.0 Standard Edition

-



This article was previously published under Q77316



SUMMARY
The Show method in the Visual Basic for Windows language can display a form either as modal or modeless. No direct support exists in the language to determine the display state of the form without maintaining global variables that contain the display state of the form. However, the Windows API function GetWindowLong can be used to check the display state of the form.



MORE INFORMATION
When Visual Basic for Windows displays a modal form (.Show 1), all other forms will be modified to contain the Window Style WS_DISABLED. The Windows API function GetWindowLong can be used to return the Window Style of another form to check for the WS_DISABLED style.

The following code demonstrates this process:

Add the following to the General Declarations section of Form1 and Form2:

DefInt A-Z Global Const GWL_STYLE = (-16) Global Const WS_DISABLED = &H8000000 Declare Function GetWindowLong& Lib &quot;user&quot; (ByVal hWnd, ByVal nIndex)

Form1.Frm
Sub Form_Click ' Flip between &quot;Modeless&quot; and &quot;Modal&quot; display states. Static ShowStyle Unload form2 form2.Show ShowStyle ShowStyle = (ShowStyle + 1) Mod 2 End Sub

Form2.Frm
Sub Form_Paint ' Get the Window Style for Form1. WinStyle& = GetWindowLong(Form1.hWnd, GWL_STYLE) If WinStyle& And WS_DISABLED Then ' The WS_DISABLED style is set on &quot;FORM1&quot; when &quot;FORM2&quot; ' is displayed with the Modal flag (Show 1). Print &quot;Modal   - Show 1&quot; Else ' The WS_DISABLED style is not set on &quot;FORM1&quot; when &quot;FORM2&quot; ' is displayed with the Modeless flag (Show or Show 0). Print &quot;Modeless - Show&quot; End If End Sub

Keywords: kbhowto kbwndw kbcode KB77316

-

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

© Microsoft Corporation. All rights reserved.