How to Determine Display State of a VB Form, Modal or ModelessLast reviewed: August 11, 1997Article ID: Q77316 |
The information in this article applies to: - Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0- Microsoft Visual Basic programming system for Windows, version 1.0
SUMMARYThe 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 INFORMATIONWhen 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 "user" (ByVal hWnd, ByVal nIndex) Form1.FrmSub Form_Click () ' Flip between "Modeless" and "Modal" display states. Static ShowStyle Unload form2 form2.Show ShowStyle ShowStyle = (ShowStyle + 1) Mod 2 End Sub Form2.FrmSub 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 "FORM1" when "FORM2" ' is displayed with the Modal flag (Show 1). Print "Modal - Show 1" Else ' The WS_DISABLED style is not set on "FORM1" when "FORM2" ' is displayed with the Modeless flag (Show or Show 0). Print "Modeless - Show" End If End Sub Keywords : APrgWindow PrgOptTips kbcode kbhowto kbtlc Version : 1.0 2.0 3.0 Platform : WINDOWS Issue type : kbhowto Solution Type : kbcode |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |