ID: Q110309
2.00 WINDOWS kbprg kbbuglist
The information in this article applies to:
Setting the MaxButton property of a form to False removes the Maximize item in the Control-menu box and removes the maximize button in the upper right corner of the form. However, double-clicking the title-bar still maximizes the form or toggles back to the default size.
The Control-menu box is also known as the System-menu box in other products for Windows.
By default, double-clicking the title bar has the same effect as choosing Maximize or Restore from the Control-menu box -- it acts as a toggle between the normal window size and the maximized window size. This behavior is by design in standard Microsoft Windows. Setting the MaxButton property of the form to False fails to suppress this behavior in Visual Basic version 2.0.
To prevent a double-click on the title bar from causing Maximize or Restore, call Windows API functions as shown in the sample program in the More Information section below.
Microsoft has confirmed this to be a problem in Visual Basic version 2.0 for Windows. This problem was corrected in version 3.0. In version 3.0, setting the form's MaxButton property to False correctly ignores double- clicks on the title bar.
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
These are numbered 0 through 8 from the top down. You may remove any or all
entries. Be sure to remove items in reverse sequence, from 8 to 0, or else
the numbering will become confused.
NOTE: To remove the Control-menu box, set the ControlBox property to False. To remove the minimize button, set the MinButton property to False. To remove the maximize button, set the MaxButton property to False.
The following program removes the Maximize feature from a Visual Basic form. This code can be used in Visual Basic versions 2.0 and 3.0.
1. Start a new project in Visual Basic. Form1 is created by default.
2. Add the following to the Form Load event code:
Sub Form_Load ()
Dim hSysMenu%, r%, j%, dw&, rr&
Const MF_BYPOSITION = &H400
' Set the default size of the form:
Form1.Height = Screen.Height + 45 ' Works on VGA.
Form1.Width = Screen.Width + 60 ' Works on VGA.
Form1.Left = -15 ' Works on VGA.
Form1.Top = -15 ' Works on VGA.
hSysMenu = GetSystemMenu(Form1.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 Restore and Minimize in the Control-menu box.
dw& = GetWindowLong(Form1.hWnd, -16) 'Window style
dw& = dw& And &HFFFEFFFF 'Turn off Maximize button
rr& = SetWindowLong(Form1.hWnd, -16, dw&)
End Sub
3. Add a command button to the form. Double-click the command button and
add the following code to the Command1 click event:
Sub Command1_Click ()
End
End Sub
This button lets you end the program because Close is removed from the
Control-menu box.
4. Add the following Declare statements to the general declarations
section:
' 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
5. Start the program, or press the F5 key.
The form's Control-menu box shows Restore (greyed) and Minimize. Double- clicking the title-bar has no effect, as desired.
Clicking the Minimize arrow or choosing the Minimize menu item minimizes the form to an icon. A single-click on that icon does not open a control menu, unlike normal Visual Basic application icons. A double-click is required to restore the form to its full-screen state.
NOTE: In the above program, the following Form properties should be left with their design-time default: ControlBox = True, MaxButton = True, MinButton = True. The API functions take care of any necessary property changes.
Keywords : PrgOther kbbuglist
Version : 2.00
Platform : WINDOWS
Solution Type : kbfix
Last Reviewed: November 1, 1997