HOWTO: Suppress Maximize & Minimize Buttons on MDI Parent Form

ID: Q137033


The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0
  • Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 16-bit and 32-bit, for Windows, version 4.0
  • Microsoft Visual Basic Standard and Professional Editions for Windows, version 3.0


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.

VISUAL BASIC 4.0 AND 5.0 SECTION

Step-by-Step Example

  1. Start a new project in Visual Basic. Form1 is created by default.


  2. Change the MDIChild property of Form1 to True.


  3. Add an MDI form (MDIForm1) to the project.


  4. 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
     


  5. 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) 


  6. Press the F5 key to run the program.


VISUAL BASIC 3.0 SECTION

Step-by-Step Example

  1. Start a new project in Visual Basic. Form1 is created by default.


  2. Change the MDIChild property of Form1 to True.


  3. Add an MDI form (MDIForm1) to the project.


  4. 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
     


  5. 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)
     


  6. Press the F5 key to run the program.


Keywords : kbui kbVBp400 kbVBp500 kbhowto PrgCtrlsStd VB4WIN vbwin
Version : 3.0 4.0 5.0
Platform : NT WINDOWS
Issue type :


Last Reviewed: June 18, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.