PRB: Missing Window Buttons if Form ControlBox Property False
ID: Q159907
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
-
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0
SYMPTOMS
When 32-bit Visual Basic applications run on Windows 95, Windows 98,
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 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, 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:
- 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.
Additional query words:
kbVBp400 kbVBp500 kbVBp600 kbNoKeyWord kbVBp kbDSupport kbdsd
Keywords : kbGrpVB
Version :
Platform : NT WINDOWS
Issue type : kbprb
|