Microsoft KB Archive/137033

= How To Suppress Maximize & Minimize Buttons on MDI Parent Form =

Article ID: 137033

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q137033



SUMMARY
This article shows by example how to suppress the maximize and minimize buttons on an MDI parent form.

On non-MDI forms, you can set the MinButton and MaxButton properties to False to disable the form's Minimize and Maximize buttons. However, these properties are not available on an MDI parent form. To disable an MDI form's Minimize and Maximize buttons, you need to use the SetWindowLong Windows API function to change the style of the window.



MORE INFORMATION
Both of the following examples eliminate the Minimize and Maximize buttons from the main MDI form (MDIForm1).

NOTE: Information in the Visual Basic versions 4.0 and 5.0 section applies only to Visual Basic versions 4.0 and 5.0, and information in the Visual Basic 3.0 section applies only to Visual Basic 3.0.

Step-by-Step Example
 Start a new project in Visual Basic. Form1 is created by default. Change the MDIChild property of Form1 to True. Add an MDI form (MDIForm1) to the project.  Add the following code to the MDIForm_Load event procedure for MDIForm1: Private Sub MDIForm_Load Dim L as Long L = GetWindowLong(Me.hWnd, GWL_STYLE) L = L And Not (WS_MINIMIZEBOX) L = L And Not (WS_MAXIMIZEBOX) L = SetWindowLong(Me.hWnd, GWL_STYLE, L)     End Sub

  Add the following declarations to the general section of MDIForm1:

NOTE: You only need the Win32 declares below if you are using Visual Basic 5.0 or if you develop only in the 32-bit version of Visual Basic 4.0.

#If Win32 Then Private Declare Function SetWindowLong Lib "user32" Alias _ "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _         ByVal dwNewLong As Long) As Long Private Declare Function GetWindowLong Lib "user32" Alias _ "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) _ As Long #Else Declare Function SetWindowLong Lib "User" (ByVal hwnd As Integer, _         ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long Declare Function GetWindowLong Lib "User" (ByVal hwnd As Integer, _         ByVal nIndex As Integer) As Long #End If

Const WS_MINIMIZEBOX = &H20000 Const WS_MAXIMIZEBOX = &H10000 Const GWL_STYLE = (-16)  Press the F5 key to run the program.</ol>

Step-by-Step Example
<ol> Start a new project in Visual Basic. Form1 is created by default.</li> Change the MDIChild property of Form1 to True.</li> Add an MDI form (MDIForm1) to the project.</li>  Add the following code to the MDIForm_Load event procedure for MDIForm1: Sub MDIForm_Load Dim L as Long L = GetWindowLong(Me.hWnd, GWL_STYLE) L = L And Not (WS_MINIMIZEBOX) L = L And Not (WS_MAXIMIZEBOX) L = SetWindowLong(Me.hWnd, GWL_STYLE, L)     End Sub

</li>  Add the following declarations to the general section of MDIForm1: ' Enter the following Declare statement as one, single line: Declare Function SetWindowLong Lib "User" (ByVal hwnd As Integer,        ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long

' Enter the following Declare statement as one, single line: Declare Function GetWindowLong Lib "User" (ByVal hwnd As Integer,        ByVal nIndex As Integer) As Long

Const WS_MINIMIZEBOX = &H20000 Const WS_MAXIMIZEBOX = &H10000 Const GWL_STYLE = (-16)

</li> Press the F5 key to run the program.</li></ol>

Keywords: kbhowto kbui KB137033

-

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

© Microsoft Corporation. All rights reserved.