Re: UserForm displayed on second monitor

From: RB Smissaert (bartsmissaert_at_blueyonder.co.uk)
Date: 03/19/05


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)
>



Relevant Pages

  • Re: Preventing the power option Turn off Monitor?
    ... except for when you are watching a movie on your computer, ... turning off the monitor could be a great feature;-)). ... Private Const ES_CONTINUOUS As Integer = -2147483648 ... Public Sub PreventPowerOptionTurnOffMonitor() ...
    (microsoft.public.dotnet.languages.vb)
  • Monitor Size
    ... Can I determine the monitor size? ... Private Declare Function GetDeviceCaps& Lib "gdi32" (ByVal hdc As ... Private Const HORZSIZE& = 4 ...
    (microsoft.public.vb.general.discussion)
  • Re: RGB to VGA on a IIGS (again)
    ... I've been working on a converter for old computers ... that takes the various res's and syncs it to a n RGB type monitor, ... interpreting the pixel widths slightly differently. ... pixels is about 375, and to 560 Apple pixels, 750. ...
    (comp.sys.apple2)
  • Re: Ok First question about XP Pro
    ... if you Run a 1280 x 1024 LCD Display ... at 1024 x 768 that means that each Pixel on the ... Resolution you want & it will support), a CRT Monitor has a "Native ...
    (uk.people.silversurfers)
  • Re: RGB to Component video converter (SCART)
    ... if you have a line of horizontal black pixels which turn to white there will be one pixel at the transition that is gray. ... I had the impression from past threads that this ghosting effect was caused by the monitor not being able to sync with the IIgs signal frequency. ... monitor not being locked to the dot clock of the IIgs. ...
    (comp.sys.apple2)