How to Remove Menu Items from a Form's Control-Menu BoxID: Q110393
|
The Control-menu box is located in the upper-left corner of a Visual Basic
form. You can remove certain menu items from the Control-menu box by using
the using form's MaxButton, MinButton, and BorderStyle properties. You can
also remove Control-menu items by using Windows API functions, as shown in
a sample program in the More Information section below.
To completely remove the Control-menu box, set the form's ControlBox
property to False.
The default Control-menu box in the upper left-hand corner of a Visual
Basic form contains the following nine entries, including separators:
Restore
Move
Size
Minimize
Maximize
-----------------------
Close Alt+F4
-----------------------
Switch to... Ctrl+Esc
Setting Description
----------------------------------------------------------------------
0 No border and no related border elements.
1 Fixed Single. Can include Control-menu box, title bar,
Maximize button, and Minimize button. Resizable only using
Maximize and Minimize buttons.
2 (Default) Sizable. Resizable using any of the optional border
elements listed for setting 1.
3 Fixed Double. Can include Control-menu box and title bar;
cannot include Maximize or Minimize buttons. Not resizable.
Sub Form_Load ()
Dim hSysMenu%, r%, j%, dw&, rr&
Const MF_BYPOSITION = &H400
' Me refers to the form where code is currently executing:
hSysMenu = GetSystemMenu(Me.hWnd, 0)
For j = 8 To 4 Step -1
r = RemoveMenu(hSysMenu, j, MF_BYPOSITION)
Next j
For j = 2 To 1 Step -1
r = RemoveMenu(hSysMenu, j, MF_BYPOSITION)
Next j
' Leave the Restore and Minimize items.
dw& = GetWindowLong(Me.hWnd, -16) 'Window style
dw& = dw& And &HFFFEFFFF 'Turn off bits for Maximize arrow button
rr& = SetWindowLong(Me.hWnd, -16, dw&)
End Sub
The default Control-menu items are numbered 0 through 8 from the top
down. You may remove any or all items using Windows API functions. Be
sure to remove items in reverse sequence, from 8 to 0, or else the
numbering will become confused.
Sub Command1_Click ()
End
End Sub
This button lets you end the program, since Close is removed from the
Control-menu box.
' Enter each of the following Declare statements as one, single line:
Declare Function RemoveMenu% Lib "User" (ByVal hMenu%, ByVal nPosition%,
ByVal wFlags%)
Declare Function GetSystemMenu% Lib "User" (ByVal hWnd%, ByVal revert%)
Declare Function GetWindowLong Lib "User" (ByVal hWnd As Integer,
ByVal nIndex As Integer) As Long
Declare Function SetWindowLong Lib "User" (ByVal hWnd As Integer,
ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
Additional query words: 3.00
Keywords : kbcode PrgOther
Version : 3.00
Platform : WINDOWS
Issue type :
Last Reviewed: June 22, 1999