Re: UserForm displayed on second monitor
From: RB Smissaert (bartsmissaert_at_blueyonder.co.uk)
Date: 03/19/05
- Next message: Cindy M -WordMVP-: "Re: Sendkeys"
- Previous message: Walt: "certificates are being lost consistently"
- In reply to: J Whales (anti-spam alias): "UserForm displayed on second monitor"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 19 Mar 2005 13:05:49 -0000
Have just figured out how to handle a dual (or multi-) monitor setup.
The first thing to understand is that there is a virtual desktop width
(and height) and that you have to place your userform according to this.
The following API's will tell you about this:
Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1
Private Const SM_CXVIRTUALSCREEN As Long = 78
Private Const SM_CMONITORS As Long = 80
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As
Long) As Long
Function GetDesktopMaximumWidth() As Long
If IsMultiMonitorSystem() Then
GetDesktopMaximumWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN)
Else
GetDesktopMaximumWidth = GetSystemMetrics(SM_CXSCREEN)
End If
End Function
Function IsMultiMonitorSystem() As Boolean
IsMultiMonitorSystem = GetSystemMetrics(SM_CMONITORS) > 1
End Function
Function GetMonitorCount() As Long
GetMonitorCount = GetSystemMetrics(SM_CMONITORS)
End Function
Then you can place your forms accordingly as shown in the following
code fragment:
'SystemMetrics API is in pixels
'Userform left and top is in points
'1 pixel = 15 twips
'1 point = 20 twips
'1 point = 20/15 pixels
'1 point = 1.3333333 pixels
'1 pixel = 0.75 points
With frmForm
If bDualMonitor = True Then
If strAddinScreen = "Right" Then
.StartupPosition = 0
.Top = 0
.Left = (GetDesktopMaximumWidth() * 0.75) - .Width
Else
.StartupPosition = 0
.Top = 0
.Left = 0
End If
End If
End With
Hope this clarifies it.
The best place to get information about the API's to do with this is:
http://vbnet.mvps.org/index.html?code/screen/index.html
RBS
"J Whales (anti-spam alias)" <jwhales@gmail.com> wrote in message
news:1111178472.831888.212710@o13g2000cwo.googlegroups.com...
> Hello!
>
> I have a somewhat annoying problem... I work with two monitors, with
> Word or Excel on one side and the VBA IDE on the other.
>
> When I display a userform, it shows up on the monitor where the IDE is
> located (whether or not the IDE is actually openned) instead of in the
> middle of the monitor where Word or Excel is openned.
>
> Is there some settings that would prevent that?
>
> Thanks for your help
>
> J Whales
> (anti-spam alias)
>
- Next message: Cindy M -WordMVP-: "Re: Sendkeys"
- Previous message: Walt: "certificates are being lost consistently"
- In reply to: J Whales (anti-spam alias): "UserForm displayed on second monitor"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|