Microsoft KB Archive/159907

= PRB: Missing Window Buttons if Form ControlBox Property False =

Article ID: 159907

Article Last Modified on 6/24/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q159907



SYMPTOMS
When 32-bit Visual Basic applications run on Windows 95, Windows 98, Windows Me, Windows NT 4.0, and Windows 2000, 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 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, Windows 98, Windows Me, Windows NT 4.0, and Windows 2000 enforce different UI behaviors for 32-bit applications versus 16-bit applications.



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

 Start 32-bit Visual Basic. Form1 is created by default.  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   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  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.

Keywords: kbprb KB159907

-

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

© Microsoft Corporation. All rights reserved.