Multiple Monitor Info using EnumDisplaySettings

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
jpalic
Newbie
Posts: 17
Joined: Fri Aug 01, 2008 6:32 pm

Multiple Monitor Info using EnumDisplaySettings

Post by jpalic » Tue Sep 16, 2008 3:12 pm

We have a need to detect multiple monitors connected to a laptop and take appropriate action.

It would seem that the GetSystemMetrics "number of monitors" function would do the trick but:

// Number of monitors
Let>SM_CMONITORS = 80
// Virtual Width
Let>SM_CXVIRTUALSCREEN = 78
// Virtual Height
Let>SM_CYVIRTUALSCREEN = 79
LibFunc>user32,GetSystemMetrics,mcnt,SM_CMONITORS
LibFunc>user32,GetSystemMetrics,vsw,SM_CXVIRTUALSCREEN
LibFunc>user32,GetSystemMetrics,vsh,SM_CYVIRTUALSCREEN

always returns 0's for the virtual screen size and number of monitors unless the monitors are configured as "spanned" in the Nvidia driver - which isn't what we want to do. We need to detect whether or not there is a 2nd monitor attached to the laptop and whether or not the 2nd monitor is "active".

Tried WMI Win32_DisplayConfiguration and Win32_VideoController but don't get anything about the 2nd video output on the laptop.

Haven't yet tried to script the desk.cpl applet but that approach seems "fragile" as the dialog box changes depending on the hardware setup.

The Windows API EnumDisplaySettings seems appealing but using that function requires passing structures other than strings and longs so it can't be directly called using LibFunc>in MS.

UltraMon is a 3rd party dll that will supply the info from EnumDisplaySettings but the licensing is a bit more than we'd like to pay at the moment. They have a good description of how to use the EnumDisplaySettings library function at: http://realtimesoftware.com/multimon/pr ... basics.asp .

It appears that AutoIT can set up the structures and call the EnumDisplaySettings function but it's a bit of a challenge to switch horses midstream.

Could pull out the C++ compiler and write my own dll I guess. Been a while since I've done that though.

Has anybody run across a good way to get at the EnumDisplaySettings info or any other approach to deal with multiple monitor displays?

Thanks,

Jim

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Sep 16, 2008 3:16 pm

Do you just want to know how many monitors there are? I.e. is all you are interested in the number of monitors, or do you want information about each one (such as bit depth, resolution etc)?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Sep 16, 2008 3:20 pm

This works for me:

Code: Select all

// Number of monitors
Let>SM_CMONITORS=80
// Virtual Width
Let>SM_CXVIRTUALSCREEN=78
// Virtual Height
Let>SM_CYVIRTUALSCREEN=79
LibFunc>user32,GetSystemMetrics,mcnt,SM_CMONITORS

LibFunc>user32,GetSystemMetrics,vsw,SM_CXVIRTUALSCREEN
LibFunc>user32,GetSystemMetrics,vsh,SM_CYVIRTUALSCREEN

MessageModal>You have %mcnt% monitors%CRLF%Virtual Screen Size: %vsw%x%vsh% px
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

jpalic
Newbie
Posts: 17
Joined: Fri Aug 01, 2008 6:32 pm

Post by jpalic » Tue Sep 16, 2008 7:18 pm

Marcus,

I'd be interested to know if you have two video cards or a single card with two video outputs?

I'm trying to get this to work across a couple of types of laptops with different video cards. There is a single video card that has two outputs in the laptop. I've not succeeded getting the WMI calls to report two monitors when there is only one video card with two outputs.

I think I've come to the conclusion that I can run the desk.cpl dialog and do what I need to do there. I was trying to avoid popping that up but I think that'll just have to be the way it works.

I appreciate the feedback,

Jim Palic

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Sep 16, 2008 7:20 pm

My main PC has one video card with two outputs with a monitor connected to each. The above script tells me I have two screens, which is correct.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts