I have a dual monitor setup. And I want to get the size of the Access window
so that I can play around with form sizes & positions.
Sorry, this is a bit longwinded.
Option Compare Database
Option Explicit
Private Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private vate Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long,
lpRect As Rect) As Long Private Declare Function MonitorFromWindow Lib
"User32.dll" _ (ByVal hWnd As Long, ByVal dwFlags As Long) As Long
Private Declare Function GetMonitorInfo Lib "User32.dll" Alias
"GetMonitorInfoW" _ (ByVal hMonitor As Long, ByVal lpMonitorInfo As Long) As
Long
Dim AreaHeight As Integer
Dim AreaWidth As Integer
Sub GetAccessWindowSize()
Dim Rec As Rect
GetWindowRect Application.hWndAccessApp, Rec
AreaHeight = Rec.Bottom
AreaWidth = Rec.Right
End Sub
This gets the Size of the Access Window (AreaWidth & AreaHeight) OK on my
right hand monitor and for a maximised Access window I get a size of 1928 *
1058. Odd as the correct resolution should be 1920 * 1080 but the difference
in height may be something to do with the Windows Task bar). If I drag Access
over to the left hand monitor (it’s a bit narrower) I get maximizes Access
window of 8 * 1058 Again Odd as the resolution should be 1680*1050: There is
no taskbar on this monitor) So it appears that the GetWindowRect
overestimates both width & height by 8, which can easily be compensated for.
Sub MonitorDetails()
Dim hMonitor As Long
Dim MonitorInfo As typMonitorInfo
Dim apiReturnCode As Long
hMonitor = MonitorFromWindow(Application.hWndAccessApp, &H0&)
MonitorInfo.cbSize = LenB(MonitorInfo)
apiReturnCode = GetMonitorInfo(hMonitor, VarPtr(MonitorInfo))
With MonitorInfo.rcMonitor
Debug.Print "Horizontal resolution: " & .Right - .Left
Debug.Print "Vertical resolution: " & .Bottom - .Top
Debug.Print Debug.Print "Form Left: " & Me.WindowLeft & " Form width: " &
Me.WindowWidth End With
End Sub
This returns the resolutions correctly as either 1920 * 1080 or 1680 * 1050
depending on which monitor the form gets opened on.
So what I want is to get the correct width of the Access Window on the
smaller left hand screen.
Any ideas please?
Phil
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com