Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get Access Window Position

1,116 views
Skip to first unread message

Rob Graber

unread,
Jun 4, 2001, 5:18:42 PM6/4/01
to
How can I get the current Access window size and position, save it, get the
maximum pixels (ie...resolution) for the current PC, resize my Access window, and
then later restore the Access window to the previous size and position?

Thanks!

Very truly yours,

Rob G.

P.S. I found the SetWindowPos() API example in the KB, but how do I Get the
position and the screen resolution?

Van T. Dinh

unread,
Jun 4, 2001, 9:57:40 PM6/4/01
to
I use the following code module to position/size the Access application
window as required.

HTH
Van T. Dinh


***Code Module***
Option Compare Database
Option Explicit

''''
============================================================================
=====
'''' Global Declarations
'''' NOTE: The following declaration is CASE-SENSITIVE
''''
============================================================================
=====

'''' For MaximizeRestoredForm
Type RECT
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type

'''' For fnSizeAccess
Declare Function SystemParametersInfo Lib "user32" Alias
"SystemParametersInfoA" (ByVal uAction As Long, _
ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
'' To find screen resolution
Declare Sub SetWindowPos Lib "user32" (ByVal hwnd&, ByVal hWndInsertAfter&,
_
ByVal X&, ByVal Y&, ByVal cX&, ByVal cY&, ByVal wFlags&)

'''' For MaximizeRestoredForm
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

Declare Function IsWindowEnabled Lib "user32" (ByVal hwnd As Long) As Long

'''' For fnSizeAccess
Public Const SPI_GETWORKAREA = 48 '' Used to find desktop area
Public Const HWND_TOP = 0 '' Move MS Access window to top of
Z-order
Public Const SWP_NOZORDER = &H4 '' Value for wFlags: Ignores the
hWndInsertAfter
Public Const TASKBAR_PXL = 28

'''' For MaximizeRestoredForm
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNORMAL = 1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''

Function fnSizeAccess1(lngWidth As Long, lngHeight As Long) As Boolean

Dim AccessHandle As Long
Dim lRet As Long
Dim apiRECT As RECT
Dim X_TL As Long, Y_TL As Long

On Error GoTo Err_fnSizeAccess1
Screen.MousePointer = vbHourglass: Echo False
'''' Get handle to MS Access
AccessHandle = Application.hWndAccessApp

lRet = SystemParametersInfo(SPI_GETWORKAREA, vbNull, apiRECT, 0)
X_TL = (apiRECT.x2 - lngWidth) \ 2 '' Set top left
corner
Y_TL = (apiRECT.y2 - lngHeight) \ 2

RunCommand acCmdAppRestore
SetWindowPos AccessHandle, HWND_TOP, X_TL, Y_TL, lngWidth, lngHeight,
SWP_NOZORDER '' Position Microsoft Access
'''' fnSizeAccess1 = True

Exit_fnSizeAccess1:
Screen.MousePointer = vbDefault: Echo True
Exit Function

Err_fnSizeAccess1:
'''' fnSizeAccess1 = False
MsgBox Err.Description: Resume Exit_fnSizeAccess1


End Function

Function fnSizeAccess2() As Boolean

Dim AccessHandle As Long
Dim lRet As Long
Dim apiRECT As RECT
Dim X_TL As Long, Y_TL As Long
Dim Width As Long, Height As Long

On Error GoTo Err_fnSizeAccess2
Screen.MousePointer = vbHourglass: Echo False
'''' Get handle to MS Access
AccessHandle = Application.hWndAccessApp

lRet = SystemParametersInfo(SPI_GETWORKAREA, vbNull, apiRECT, 0)
If apiRECT.x2 > 640 Then '' NOT 640 x
480 resolution
X_TL = (apiRECT.x2 - 640) \ 2 '' Set top
left corner
If X_TL < 0 Then X_TL = 0
Y_TL = (apiRECT.y2 - 460) \ 2
If Y_TL < 0 Then Y_TL = 0
Width = 640: Height = 464 '' Set
Access Window to 640 x 464

RunCommand acCmdAppRestore '' Restore
Access Window
SetWindowPos AccessHandle, HWND_TOP, X_TL, Y_TL, Width, Height,
SWP_NOZORDER '' Position Microsoft Access
Else '' 640 x 480
resolution
RunCommand acCmdAppMaximize '' Maximize
Access Window
End If

'''' fnSizeAccess2 = True

Exit_fnSizeAccess2:
Screen.MousePointer = vbDefault: Echo True
Exit Function

Err_fnSizeAccess2:
'''' fnSizeAccess2 = False
MsgBox Err.Description: Resume Exit_fnSizeAccess2


End Function

Function fnSizeAccess3() As Boolean

Dim AccessHandle As Long
Dim MDIRect As RECT
Dim X_TL As Long, Y_TL As Long
Dim Width As Long, Height As Long

On Error GoTo Err_fnSizeAccess3
Screen.MousePointer = vbHourglass: Echo False
RunCommand acCmdAppMaximize
'''' Get handle to MS Access
AccessHandle = Application.hWndAccessApp

GetWindowRect AccessHandle, MDIRect
If MDIRect.x2 > 640 Then '' NOT 640 x
480 resolution
RunCommand acCmdAppRestore '' Restore
Access Window
X_TL = (MDIRect.x2 - 640) \ 2 '' Set top
left corner
If X_TL < 0 Then X_TL = 0
Y_TL = (MDIRect.y2 - 480 - TASKBAR_PXL) \ 2 '' 32 pixels
for Taskbar
If Y_TL < 0 Then Y_TL = 0
Width = 640: Height = 464 '' Set Access
Window to 640 x 480

RunCommand acCmdAppRestore '' Restore
Access Window
SetWindowPos AccessHandle, HWND_TOP, X_TL, Y_TL, Width, Height,
SWP_NOZORDER '' Position Microsoft Access
End If

'''' fnSizeAccess3 = True

Exit_fnSizeAccess3:
Screen.MousePointer = vbDefault: Echo True
Exit Function

Err_fnSizeAccess3:
'''' fnSizeAccess3 = False
MsgBox Err.Description: Resume Exit_fnSizeAccess3


End Function

Sub MaximizeRestoredForm(F As Variant)
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 - 4, MDIRect.y2 -
MDIRect.y1 - 4, True
End Sub
***Code Module ends***

(watch out for e-mail word-wrapping)

"Rob Graber" <r.gr...@worldnet.att.net> wrote in message
news:412401c0ed3b$ee324860$9ee62ecf@tkmsftngxa05...

0 new messages