Microsoft KB Archive/110620

= How to Determine the Restored State of a Minimized Form =

Article ID: 110620

Article Last Modified on 10/29/2003

-

APPLIES TO


 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q110620



SUMMARY
It is not possible within Visual Basic to determine programatically whether an iconized form will be restored to a maximized or normal state without using the Windows API (application programming interface) function GetWindowPlacement. This article gives an example of how to call this function from a Visual Basic application.



MORE INFORMATION
The following program demonstrates how to determine whether a minimized form will be restored as maximized or normal. The program requires two forms with a Label and a Command control on Form 1.

 Start a new project in Visual Basic. Form1 is created by default. From the File menu, choose New Form to create Form2.  From the File menu, choose New Module to create a .BAS file and enter the following code in the (General) (Declarations) section: Type RECT left As Integer top As Integer right As Integer bottom As Integer End Type

Type POINTAPI x As Integer y As Integer End Type

Type WINDOWPLACEMENT length As Integer flags As Integer showCmd As Integer ptMinPosition As POINTAPI ptMaxPosition As POINTAPI rcNormalPosition As RECT End Type

Global Const WPF_RESTORETOMAXIMIZED = &H0002

' Enter the following Declare statement as one, single line:

Declare Function GetWindowPlacement Lib "User" (ByVal hWnd As Integer, lpwndpl As WINDOWPLACEMENT) As Integer

Function is_max (hWnd As Integer) As Integer Dim wp As WINDOWPLACEMENT Dim rtn As Integer wp.length = Len(wp) ' Initialize size rtn = GetWindowPlacement(hWnd, wp) If wp.flags = WPF_RESTORETOMAXIMIZED Then is_max = True Else is_max = False End If  End Function NOTE: The value of wp.length must be initialized or the call to GetWindowPlacement will return an error. There is no mention of this in the Microsoft Windows "Programmer[ASCII 146]s Reference," but it is described as a documentation error in the following article in the Microsoft Knowledge Base:

89569 DOCERR: GetWindowPlacement Function Always Returns an Error

 Add a Label control and Command control to Form1.  Add the following code to the Command_Click procedure of Form1: Sub Command1_Click If is_max((Form2.hWnd)) Then Label1.Caption = "Form 2 will be Maximized" Else Label1.Caption = "Form 2 will be Normalized" End If  End Sub NOTE: Form2.hWnd cannot be passed directly to a function as a parameter. It must be enclosed in an extra set of parentheses or stored in a temporary variable.  From the File menu, choose Save Project to save the forms and project. Run your application by choosing Start from the Run menu or by pressing the F5 function key. Minimize Form2, click the Command button on Form1, and observe the message displayed in the Label control. Restore Form2, maximize it, and then minimize it again. Click the Command button on Form1, and again observe the message displayed in the Label control.</li></ol>

Additional query words: 3.00

Keywords: KB110620

-

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

© Microsoft Corporation. All rights reserved.