ACC: Maximized Form Shows Control Box, Min/Max/Restore Buttons
ID: Q128196
|
The information in this article applies to:
-
Microsoft Access versions 2.0, 97
SYMPTOMS
Advanced: Requires expert coding, interoperability, and multiuser skills.
In Microsoft Access 97, a form whose ControlBox, MinMaxButtons, and
CloseButton properties are set to No still displays the Restore and Close
buttons when you maximize the form.
In Microsoft Access 2.0, a form whose ControlBox, MinButton, and MaxButton
properties are set to No still displays the Control-menu box and a Restore
button when you maximize the form.
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information
about Visual Basic for Applications, please refer to your version of the
"Building Applications with Microsoft Access" manual.
NOTE: Visual Basic for Applications is called Access Basic in Microsoft
Access version 2.0. For more information about Access Basic, please refer
to the "Building Applications" manual.
CAUSE
Microsoft Access is a multiple document interface (MDI) application. The
default behavior for an MDI application is for all maximized child windows
to always display a Control-menu box and a Restore button.
RESOLUTION
You can use the following technique to simulate maximizing a window
by sizing it as large as possible in the restored, windowed
(non-maximized), state.
The following example demonstrates how to create and use a sample Sub
procedure called MaximizeRestoredForm to restore a form if it is maximized,
and then move it to the upper-left corner of the Microsoft Access client
area window and size it as large as possible.
NOTE: This technique will produce a blank section at the top of the form
that is approximately the height and width of a toolbar, if the form is
opened in Design view, and then switched to Form view. This code works best
when the form is opened from the Database window or through code while
running the application.
NOTE: In the following sample code, an underscore (_) at the end of a line
is used as a line-continuation character. Remove the underscore from the
end of the line when re-creating this code in Access Basic.
- Create a new module and type the following lines in the Declarations
section:
In Microsoft Access 97:
Type Rect
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, _
lpRect As Rect) As Long
Declare Function IsZoomed Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal _
nCmdShow As Long) As Long
Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal _
X As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight _
As Long, ByVal bRepaint As Long) As Long
Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNORMAL = 1
In Microsoft Access 2.0:
Option Explicit
Type Rect
x1 As Integer
y1 As Integer
x2 As Integer
y2 As Integer
End Type
Declare Sub GetWindowRect Lib "User" (ByVal hWnd As Integer, _
lpRect As Rect)
Declare Function IsZoomed Lib "User" (ByVal hWnd As Integer) _
As Integer
Declare Sub ShowWindow Lib "User" (ByVal hWnd%, ByVal nCmdShow%)
Declare Sub MoveWindow Lib "User" (ByVal hWnd As Integer, _
ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As _
Integer, ByVal nHeight As Integer, ByVal bRepaint As Integer)
Declare Function GetParent Lib "User" (ByVal hWnd As Integer) _
As Integer
Const SW_MAXIMIZE = 3
Const SW_SHOWNORMAL = 1
- Type the following Sub procedure in the module:
Sub MaximizeRestoredForm (F As Form)
Dim MDIRect As Rect
' If the form is maximized, restore it.
If IsZoomed(F.hWnd) <> 0 Then
ShowWindow F.hWnd, SW_SHOWNORMAL
End If
' Get the screen coordinates and window size of the
' MDIClient window.
GetWindowRect GetParent(F.hWnd), MDIRect
' Move the form to the upper left corner of the MDIClient
' window (0,0) and size it to the same size as the
' MDIClient window.
MoveWindow F.hWnd, 0, 0, MDIRect.x2 - MDIRect.x1, _
MDIRect.y2 - MDIRect.y1, True
End Sub
- To simulate maximizing a form automatically when it is opened, set the
OnLoad property of the form to the following event procedure:
Sub Form_Load()
MaximizeRestoredForm Me
End Sub
- To simulate maximizing a form called MyForm, use the following statement
in a function or subroutine:
MaximizeRestoredForm Forms!MyForm
STATUS
This behavior does not occur in Microsoft Access 7.0.
Additional query words:
Keywords : kbusage FmsProp
Version : WINDOWS:2.0,97
Platform : WINDOWS
Issue type : kbprb
|