Article ID: 128196
Article Last Modified on 1/19/2007
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
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
Sub Form_Load()
MaximizeRestoredForm Me
End Sub
MaximizeRestoredForm Forms!MyFormKeywords: kbprb kbprogramming kbusage KB128196