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

Size of Access windows on dual monitors

328 views
Skip to first unread message

Phil

unread,
May 14, 2014, 1:47:58 PM5/14/14
to
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

Patrick Finucane

unread,
May 14, 2014, 4:56:31 PM5/14/14
to
On Wednesday, May 14, 2014 12:47:58 PM UTC-5, Phil wrote:
> 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

I saw some API functions; EnumDisplayMonitors and GetMonitorInfo, but the functions were written in c++. not vba. Somehow you need the hwnd value for each monitor. Wish I could help.

Phil

unread,
May 15, 2014, 5:42:35 PM5/15/14
to
On 14/05/2014 21:56:26, Patrick Finucane wrote:
> On Wednesday, May 14, 2014 12:47:58 PM UTC-5, Phil wrote:
>> I have a dual monitor setup. And I want to get the size of the Access win
> dow 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 Funct ion GetMonitorInfo Lib "User32.dll" Alias
> "GetMonitorInfoW" _ (ByVal hMonit or As Long, ByVal lpMonitorInfo As Long)
> As Long Dim AreaHeight As Integer Dim AreaWidth As Integer Sub
> GetAccessWindowSize() Dim Rec As Rect GetWindo wRect
> 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 T ask bar). If I drag Access over to the left hand monitor (it's a
> bit narrow er) I get maximizes Access window of 8 * 1058 Again Odd as the
> resolution s hould 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 MonitorI nfo As typMonitorInfo Dim apiReturnCode As Long hMonitor
> = MonitorFromWin dow(Application.hWndAccessApp, &H0&) MonitorInfo.cbSize =
> LenB(MonitorInf o) apiReturnCode = GetMonitorInfo(hMonitor,
> VarPtr(MonitorInfo)) With Mon itorInfo.rcMonitor Debug.Print "Horizontal
> resolution: " & .Right - .Left D ebug.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 168 0 * 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 malw are
> because avast! Antivirus protection is active. http://www.avast.com I saw
> some API functions; EnumDisplayMonitors and GetMonitorInfo, but the f
> unctions were written in c++. not vba. Somehow you need the hwnd value for
> each monitor. Wish I could help.
>

Thanks Patrick

I have an enormouse API database probably about 500 APIs with parameters,
notes and most importantly examples all written in VBA Have found some
examples on monitors and will ltake it from there

DFS

unread,
May 15, 2014, 11:33:35 PM5/15/14
to
On 05/15/2014 05:42 PM, Phil wrote:


> I have an enormouse API database probably about 500 APIs with parameters,
> notes and most importantly examples all written in VBA Have found some
> examples on monitors and will ltake it from there


Any chance you could share that API with the group?


Phil

unread,
May 16, 2014, 3:09:09 AM5/16/14
to
Sorry, I got it wrong. 925 APIs, not the 500 I mentioned

See API-Guide 3.7 at

http://softadvice.informer.com/Api-guide_3.7.html
which should down load agsetup.exe

Ulrich Möller

unread,
May 16, 2014, 6:02:11 AM5/16/14
to
> over to the left hand monitor (itᅵs a bit narrower) I get maximizes Access
Hi Phil,

perhaps this article give you some hints for solving your problem:
http://www.vbaccelerator.com/home/VB/Tips/Working_with_Multiple_Monitors/article.asp.

Ulrich
0 new messages