Click here to Skip to main content
Licence 
First Posted 30 Jun 2002
Views 130,822
Downloads 2,293
Bookmarked 49 times

Multiple Monitor Support

By | 1 Jul 2002 | Article
Make your Screen Savers Span Multiple Monitors

Multiple Monitor Support

Whilst working on a screensaver for a client I came across the problem of multiple monitors. No, not myself as I am too poor to have two monitors on one system. However the client has a PC set up grand enough to make Cape Canaveral quake in its cowboy boots and run like a buffalo.

For those of you not aware of the problems of multiple monitors let me explain. Say we take Mr. Monitor here. He uses points to provide a location on his screen. Using an X and a Y co-ordinate like ( 20, 100 ). These points are taken relative to (0,0) which is the very top-left hand corner of the screen.

This is fine, however when creating a screen saver you need to know the boundaries that the screen saver can go up to. There is no point in making a screen saver that over-flows the screen. So for getting the screen parameters you may use this:

CRect rect;
  Rect.left = 0;
  Rect.top = 0;
  Rect.right = rect.left + ::GetSystemMetrics(SM_CYSCREEN);
  Rect.bottom = rect.top + ::GetSystemMetrics(SM_CXSCREEN);

This code will provide the bottom and right hand boundaries as well as defining the top and left as zero. From this you can create your window size using this:

const char* myWndClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|
  CSSAVEBITS|CSDBLCLKS, NULL);

  CWnd::CreateEx(WS_EX_TOPMOST, myWndClass, " ", WS_POPUP | WS_VISIBLE, 
  rect.left, rect.top, rectWidth(), rect.Height(), hwndParent, NULL );

If anyone using a multiple monitor system views the app with this code they will only see the screensaver on their primary monitor and will view the desktop on the others. For this we need to include a header file and change a little bit of code.

The header file is multimon.h and is available from Microsoft. Or in the source zip on this page. Add Multimon.h to your project and add the line:

#include "multimon.h"

to your Window class source file.

Then we change the code from:

CRect rect;
  Rect.left = 0;
  Rect.top = 0;
  Rect.right = rect.left + ::GetSystemMetrics(SM_CYSCREEN);
  Rect.bottom = rect.top + ::GetSystemMetrics(SM_CXSCREEN);

To

CRect rect;
  Rect.left = ::GetSystemMetrics(SM_XVIRTUALSCREEN);
  Rect.top = ::GetSystemMetrics(SM_YVIRTUALSCREEN);
  Rect.right = rect.left + ::GetSystemMetrics(SM_CYVIRTUALSCREEN);
  Rect.bottom = rect.top + ::GetSystemMetrics(SM_CXVIRTUALSCREEN);

That's it! The screensaver will now run over the entire virtual desktop.

Updates:

July 2nd 2002 - Added Demo Projects. Both in zip folder, one for single display support and one for multi monitor support.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Jon Newman

Web Developer

United Kingdom United Kingdom

Member

I think therefore I'm tired.
 
Goto my blog....now!

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generaltypos in description PinmemberLevix6:53 18 Jun '06  
GeneralSplitterWnd question PinmemberKarl Bahr6:04 26 Nov '05  
GeneralLayout... PinmemberDaniel Desormeaux9:31 7 Mar '05  
GeneralAnother way PinmemberAstham Ogetti1:58 23 Feb '05  
GeneralRe: Another way Pinmemberkozchris17:00 9 Nov '05  
GeneralRe: Another way Pinmemberjung-kreidler0:21 5 Jun '09  
GeneralWide windows resized by screensaver Pinmemberviaduct0:03 15 Dec '04  
Generalvideo in multiple monitor Pinmembertristestigres12:37 28 Apr '04  
GeneralIncorrect solution PinmemberYawar Maajed14:02 2 Dec '03  
GeneralRe: Incorrect solution PinmemberJonny Newman2:43 3 Dec '03  
GeneralRe: Incorrect solution Pinmember.:fl0yd:.9:41 18 Feb '04  
GeneralRe: Link error: _xGetSystemMetrics PinmemberBobGratton5:00 12 Jun '03  
GeneralLink error: _xGetSystemMetrics PinmemberBobGratton13:16 10 Jun '03  
Generallink error Pinmembercweng200311:42 12 Apr '03  
GeneralRe: link error Pinmemberxxxyyyzzz13:53 11 May '03  
GeneralRe: link error PinmemberTheSuperFreq6:02 29 Mar '04  
GeneralRe: Isaac Newton PinmemberJonny Newman4:11 3 Jul '02  
GeneralMinor formatting error PinmemberRama Krishna0:54 2 Jul '02  
GeneralRe: Minor formatting error PinmemberJonny Newman1:57 2 Jul '02  
GeneralIt's Jonnnnnnnnnnnnnyyyyyyyyyyyyyyyyy PinmemberNishant S14:59 1 Jul '02  
GeneralRe: It's Jonnnnnnnnnnnnnyyyyyyyyyyyyyyyyy PinmemberJonny Newman0:24 2 Jul '02  
GeneralRe: It's Jonnnnnnnnnnnnnyyyyyyyyyyyyyyyyy PinmemberNishant S0:28 2 Jul '02  
GeneralRe: It's Jonnnnnnnnnnnnnyyyyyyyyyyyyyyyyy PinmemberJonny Newman0:42 2 Jul '02  
GeneralRe: It's Jonnnnnnnnnnnnnyyyyyyyyyyyyyyyyy PinmemberNnamdi Onyeyiri7:28 2 Jul '02  
GeneralRe: It's Jonnnnnnnnnnnnnyyyyyyyyyyyyyyyyy PinmemberJonny Newman7:39 2 Jul '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 2 Jul 2002
Article Copyright 2002 by Jon Newman
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid