PRB: Missing Window Buttons if Form ControlBox Property False

Last reviewed: November 27, 1996
Article ID: Q159907
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic for Windows, 32-bit only, version 4.0

SYMPTOMS

When 32-bit Visual Basic 4.0 applications run on Windows 95 and Windows NT 4.0, the three Window buttons in the upper-right corner of a form (Minimize, Maximize, and Close) disappear if the ControlBox property of that form is set to False. In 16-bit Visual Basic 4.0 applications, the Close Window button is disabled and the Minimize and Maximize Window buttons remain visible and enabled. The difference between 32-bit and 16-bit Visual Basic applications is not observed on Windows NT 3.51 because it has a different user interface.

CAUSE

The difference described above is by design. The user-interface specifications for Windows 95 and Windows NT 4.0 enforce different UI behaviors for 32-bit applications versus 16-bit applications.

WORKAROUND

To keep the Minimize and Maximize buttons visible and enabled while disabling the Close button, follow these steps:

  1. Start 32-bit Visual Basic 4.0. Form1 is created by default.

  2. Type the following code in the General Declarations section.

    Option Explicit

       Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long,
       ByVal bRevert As Long) As Long
       Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long,
       ByVal nPosition As Long, ByVal wFlags As Long) As Long
       Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
       (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
       Long) As Long
       Private Const SC_CLOSE = &HF060
       Private Const SC_MOVE = &HF010
       Private Const SC_SIZE = &HF000
       Private Const MF_BYCOMMAND = &H0&
       Private Const WM_NCACTIVATE = &H86
    
    

  3. Type the following code in the Form_Load event procedure:

       Private Sub Form_Load()
           Dim hMenu As Long, Success As Long
    
           hMenu = GetSystemMenu(Form1.hwnd, 0)
           Success = DeleteMenu(hMenu, SC_SIZE, MF_BYCOMMAND)
           Success = DeleteMenu(hMenu, SC_MOVE, MF_BYCOMMAND)
           Success = DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
           SendMessage Form1.hwnd, WM_NCACTIVATE, 0&, 0&
           SendMessage Form1.hwnd, WM_NCACTIVATE, 1&, 0&
       End Sub
    
    

  4. Run the program. The Close button on the upper-right corner of Form1 is disabled while the Minimize and Maximize buttons remain visible and enabled.


KBCategory: kbprg kbprb
KBSubcategory: kbnocat
Additional reference words: 4.00 vb4win vb432



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: November 27, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.