By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,556 Members | 970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,556 IT Pros & Developers. It's quick & easy.

Dual Monitor Support

P: n/a
KJM
How can I detect if the user has dual monitors and then how do I control
which monitor a form is displayed on. Currently my forms always come up on
my right monitor. What if I want to have it always display on my left one?

Thanks
Ken
Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies

P: n/a
> How can I detect if the user has dual monitors and then how do I control
which monitor a form is displayed on. Currently my forms always come up on my right monitor. What if I want to have it always display on my left

one?

You may find the following of some help -- go to your VB Help Files, select
the Search tab (note I said SEARCH tab) and type in

SAMPLE: MULTIMON.EXE

or possibly

FILE: MULTIMON.EXE

depending on the version of your VB Help files. Anyway, select the first
listed article (at least its the first one on my system); it will start with
whichever of the above search strings you used. This gives you some
information and a link to download a heavily commented VB project called
Multimon.exe.
Rick - MVP
Jul 17 '05 #2

P: n/a
KJM
Rick,

Using the VB Sample Monitor.exe you told me about seems to have a problem.

It successfully knows I have two Monitors.
It successfully returns the virtual desktop.

The function GetMonitorFromWindow() always returns a 0 which then causes the
two buttons "Where is the Monitor I'm On?" and "Center this Form on the
Current Monitor" to always use my left Primary Monitor.

I was wondering if this works for you? And if so do you have any ideas why
it wouldn't work for me.

This function always returns a 0.

Public Function GetMonitorFromWindow(hwnd As Long, dwFlags As Long) As Long
'================================================= ====
'Returns a monitor handle that the Window (hwnd) is in
'================================================= ====
Dim lReturn As Long

On Error GoTo GetMonitorFromWindow_Err
lReturn = MonitorFromWindow(hwnd, dwFlags)
GetMonitorFromWindow = lReturn
Exit Function
GetMonitorFromWindow_Err:
If Err.Number = 453 Then
'Non-Multimonitor OS, return -1
GetMonitorFromWindow = -1
End If
End Function
Thanks
Ken
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:h-********************@comcast.com...
How can I detect if the user has dual monitors and then how do I control
which monitor a form is displayed on. Currently my forms always come up on
my right monitor. What if I want to have it always display on my left

one?

You may find the following of some help -- go to your VB Help Files,

select the Search tab (note I said SEARCH tab) and type in

SAMPLE: MULTIMON.EXE

or possibly

FILE: MULTIMON.EXE

depending on the version of your VB Help files. Anyway, select the first
listed article (at least its the first one on my system); it will start with whichever of the above search strings you used. This gives you some
information and a link to download a heavily commented VB project called
Multimon.exe.
Rick - MVP

Jul 17 '05 #3

P: n/a
I'm afraid I can't help you beyond giving you the reference that I did. I
only have one monitor on my system. Perhaps someone with multiple monitors
will stop by this thread, download the Monitor.exe file and test that
function out for you.

Rick - MVP
"KJM" <k.***@cox.net> wrote in message
news:ca********************@news2.central.cox.net. ..
Rick,

Using the VB Sample Monitor.exe you told me about seems to have a problem.

It successfully knows I have two Monitors.
It successfully returns the virtual desktop.

The function GetMonitorFromWindow() always returns a 0 which then causes the two buttons "Where is the Monitor I'm On?" and "Center this Form on the
Current Monitor" to always use my left Primary Monitor.

I was wondering if this works for you? And if so do you have any ideas why it wouldn't work for me.

This function always returns a 0.

Public Function GetMonitorFromWindow(hwnd As Long, dwFlags As Long) As Long '================================================= ====
'Returns a monitor handle that the Window (hwnd) is in
'================================================= ====
Dim lReturn As Long

On Error GoTo GetMonitorFromWindow_Err
lReturn = MonitorFromWindow(hwnd, dwFlags)
GetMonitorFromWindow = lReturn
Exit Function
GetMonitorFromWindow_Err:
If Err.Number = 453 Then
'Non-Multimonitor OS, return -1
GetMonitorFromWindow = -1
End If
End Function
Thanks
Ken
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:h-********************@comcast.com...
How can I detect if the user has dual monitors and then how do I control which monitor a form is displayed on. Currently my forms always come
up on
my right monitor. What if I want to have it always display on my left

one?

You may find the following of some help -- go to your VB Help Files,

select
the Search tab (note I said SEARCH tab) and type in

SAMPLE: MULTIMON.EXE

or possibly

FILE: MULTIMON.EXE

depending on the version of your VB Help files. Anyway, select the first
listed article (at least its the first one on my system); it will start

with
whichever of the above search strings you used. This gives you some
information and a link to download a heavily commented VB project called
Multimon.exe.
Rick - MVP


Jul 17 '05 #4

P: n/a

"KJM" <k.***@cox.net> skrev i meddelandet
news:Q7*********************@news2.central.cox.net ...
How can I detect if the user has dual monitors and then how do I control
which monitor a form is displayed on. Currently my forms always come up on my right monitor. What if I want to have it always display on my left

one?

Use EnumDisplayMonitors to detect all monitors and get their resolution with
GetMonitorInfo. There is a good example in the API-guide showing how to do
this. It also shows how to use MonitorFromRect to determine on what monitor
a form is located.

I don't know how your monitors are setup. Is the right one your primary
monitor? If you want to place a form at Left = 200 on your secondary monitor
you must add the width of your primary monitor to the value. If the primary
has a resolution of 800x600 the value would be 1000.
It would be more natural to have your primary monitor to the left and your
secondary to the right since that's the way the "joined" desktop is
structured.
Jul 17 '05 #5

P: n/a
I don't know how I would survive with out my 2nd monitor, stepping
through the code from UI.exe to AX.DLL to AX.EXE on one screen scares
me (I would in fact like another)anyhow!(what you say you don't need
to step through yours)
It works correctly on my system (Win98 VB6 SP5).why you have the
problem is beyond me, maybe its down to your drivers.
Shame its a nice little gizzmo, keeps a class collection of the
monitors but if there are snags then it not too hot.I will look at it
a bit more given time but like I say though it all works fine here.
--
Geoff
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message news:<Ia********************@comcast.com>...
I'm afraid I can't help you beyond giving you the reference that I did. I
only have one monitor on my system. Perhaps someone with multiple monitors
will stop by this thread, download the Monitor.exe file and test that
function out for you.

Rick - MVP
"KJM" <k.***@cox.net> wrote in message
news:ca********************@news2.central.cox.net. ..
Rick,

Using the VB Sample Monitor.exe you told me about seems to have a problem.

It successfully knows I have two Monitors.
It successfully returns the virtual desktop.

The function GetMonitorFromWindow() always returns a 0 which then causes

the
two buttons "Where is the Monitor I'm On?" and "Center this Form on the
Current Monitor" to always use my left Primary Monitor.

I was wondering if this works for you? And if so do you have any ideas

why
it wouldn't work for me.

Jul 17 '05 #6

P: n/a
KJM
Hi,

My left monitor is #1 and my right monitor is #2 when I click Identify in
Windows Screen Properties, Setting

All of my monitors are added to the monitors collection in the sample code.

The problem is the function call

lReturn = MonitorFromWindow(hwnd, dwFlags)

Always returns a zero so the sample always centers a form on my left #1
screen.

I use the Matrox Millennium G550 video card, Driver version 5.86.32.0, Two
monitors a 21" and a 19" both set to 1600 x 1200 resolution.

Thanks for your help
Ken
"B Pilgrim" <ex************@yahoo.se> wrote in message
news:%c*******************@newsb.telia.net...

"KJM" <k.***@cox.net> skrev i meddelandet
news:Q7*********************@news2.central.cox.net ...
How can I detect if the user has dual monitors and then how do I control
which monitor a form is displayed on. Currently my forms always come up on
my right monitor. What if I want to have it always display on my left

one?

Use EnumDisplayMonitors to detect all monitors and get their resolution

with GetMonitorInfo. There is a good example in the API-guide showing how to do
this. It also shows how to use MonitorFromRect to determine on what monitor a form is located.

I don't know how your monitors are setup. Is the right one your primary
monitor? If you want to place a form at Left = 200 on your secondary monitor you must add the width of your primary monitor to the value. If the primary has a resolution of 800x600 the value would be 1000.
It would be more natural to have your primary monitor to the left and your
secondary to the right since that's the way the "joined" desktop is
structured.

Jul 17 '05 #7

P: n/a
KJM
I should have also listed that I'm using Windows XP.


"KJM" <k.***@cox.net> wrote in message
news:_t********************@news2.central.cox.net. ..
Hi,

My left monitor is #1 and my right monitor is #2 when I click Identify in
Windows Screen Properties, Setting

All of my monitors are added to the monitors collection in the sample code.
The problem is the function call

lReturn = MonitorFromWindow(hwnd, dwFlags)

Always returns a zero so the sample always centers a form on my left #1
screen.

I use the Matrox Millennium G550 video card, Driver version 5.86.32.0, Two monitors a 21" and a 19" both set to 1600 x 1200 resolution.

Thanks for your help
Ken
"B Pilgrim" <ex************@yahoo.se> wrote in message
news:%c*******************@newsb.telia.net...

"KJM" <k.***@cox.net> skrev i meddelandet
news:Q7*********************@news2.central.cox.net ...
How can I detect if the user has dual monitors and then how do I control which monitor a form is displayed on. Currently my forms always come
up on
my right monitor. What if I want to have it always display on my left

one?

Use EnumDisplayMonitors to detect all monitors and get their resolution

with
GetMonitorInfo. There is a good example in the API-guide showing how to do this. It also shows how to use MonitorFromRect to determine on what

monitor
a form is located.

I don't know how your monitors are setup. Is the right one your primary
monitor? If you want to place a form at Left = 200 on your secondary

monitor
you must add the width of your primary monitor to the value. If the

primary
has a resolution of 800x600 the value would be 1000.
It would be more natural to have your primary monitor to the left and your secondary to the right since that's the way the "joined" desktop is
structured.


Jul 17 '05 #8

P: n/a
"KJM" <k.***@cox.net> skrev i meddelandet
news:_t********************@news2.central.cox.net. ..
The problem is the function call

lReturn = MonitorFromWindow(hwnd, dwFlags)

Always returns a zero so the sample always centers a form on my left #1
screen.


What code are you using when you try to position the form at your secondary
monitor? The form is loaded to the primary monitor by default so you have to
move it before you call MonitorFromWindow. Something like:

Me.Left = PrimaryMonitorWidth + (SecondaryMonitorWidth - Me.Width)/2

.... where the monitor widths are determined from the previous enumeration.
Just make sure that you use the same scalemode for all values.
Jul 17 '05 #9

P: n/a
> Use EnumDisplayMonitors to detect all monitors and get their resolution with
GetMonitorInfo. There is a good example in the API-guide showing how to do
this. It also shows how to use MonitorFromRect to determine on what monitor
a form is located.


A word of warning, though. Some graphic cards report two monitors as
one big monitor (with a resolution of, e.g. 2400x1024), notably all
ATI dual monitor cards I know and certain Matrox dual monitor cards.
To avoid having dialogs displayed between these two monitors
(centered) they usually come with extra applications like HydraVision,
or have driver extensions like PowerDesk that automatically position
windows.

If you have such a card, EnumDisplayMonitors does not help you in any
way. Otherwise it's very convenient, because it gives you the exact
size and position of every monitor, and you can decide where to move
the form based on that information.

Robert
Jul 17 '05 #10

sashi
Expert 100+
P: 1,754
hi there,

u want to detect or u want to be able to view the active monitor at a given instance..

well.. if you want to be able to detect currently installed monitor.. u can make use of WMI.. heard abt Windows Management Instrumentation?? very useful indeed.. check it out..
Jun 27 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.