VBA Determining Screen Resolutions of BOTH Monitors of a Dual Screen setup

Snipes

New Member
Joined
Jul 31, 2008
Messages
2
Hi there - here is something that no-one seems to be able to do: I am trying to get the screen resolutions on a dual monitor setup in Excel 2002.

GetSystemMetrics32(X) gives me some info, as follows - when X is:
(measurements in pixels by the way)

0 - I get the width of the primary monitor
1 - I get the height of the primary monitor
78 - I get the width of the virtual monitor
79 - I get the height of the virtual monitor

The virtual screen is the 2 screens "added together"

For example, if I have 2 monitors side by side:

Monitor 1: Res of 1680 x 1050
Monitor 2: Res of 1600 x 900

I can use GetSystemMetrics32 to get me the width of the primary monitor (1680) and the virtual monitor (3280), thus deducing the 2nd monitor has a width of 3280-1680 = 1600.

HOWEVER - I can't determine the Y height of the second monitor because the virtual monitor is 1050 (The largest of the 2 values)

My thought re:solutions so far have been to:

a) Somehow set the primary monitor temporarily to 800x600. That way, the Y value of the second monitor would be the Y value of the virtual screen (-ie- 900, as 900 is larger than 600). This is clumsy though, and assumes the second monitor is greater than 800x600.

b) Get the X value for the second monitor first, then somehow set the two screens temporarily one above the other (vertically) as opposed to horizontally. The method that I used to work out the width of the 2nd monitor could then be used to work out the height of the 2nd monitor because the virtual screen would be then 1680x1950, and I could work out the 2nd monitor's height = 1950-1050 = 900. Thats also clumsy though, and I don't know how to change horizontal to vertical in VBA.

Any ideas?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Thanks Geoff! After much looking around the net, I came across a similar section of code only not long ago - this way that appears in the code you mentioned to be the way to do it:

The key is the GetMonitorInfo routine which with the other code boils down to being able to reference the left, top, right and bottom of each screen using the monitor handle.

From there, you can work out the resolutions by simple subtractions. The code I found is at the bottom of the thread here:

http://www.developerfusion.co.uk/forums/t/49351/

which takes the same approach.

Thanks heaps Geoff for getting back to me. I can also use bits of the link you posted as well.
 
Upvote 0

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top