HOWTO: Suppress Maximize & Minimize Buttons on MDI Parent Form

Last reviewed: July 3, 1997
Article ID: Q137033
The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0
  • Standard and Professional Editions of Microsoft Visual Basic 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)

  • 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 PrgCtrlsStd vb4all vb4win vb5all vb5howto vbwin kbhowto
    Version : 3.0 4.0 5.0
    Platform : NT WINDOWS


    THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

    Last reviewed: July 3, 1997
    © 1998 Microsoft Corporation. All rights reserved. Terms of Use.