Click here to Skip to main content
13,624,955 members
Click here to Skip to main content
Add your own
alternative version


57 bookmarked
Posted 30 Jun 2002

Multiple Monitor Support

, 1 Jul 2002
Rate this:
Please Sign up or sign in to vote.
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; = 0;
  Rect.right = rect.left + ::GetSystemMetrics(SM_CYSCREEN);
  Rect.bottom = + ::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|

  CWnd::CreateEx(WS_EX_TOPMOST, myWndClass, " ", WS_POPUP | WS_VISIBLE, 
  rect.left,, 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; = 0;
  Rect.right = rect.left + ::GetSystemMetrics(SM_CYSCREEN);
  Rect.bottom = + ::GetSystemMetrics(SM_CXSCREEN);


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

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


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


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
I think therefore I'm tired.

Goto my!

You may also be interested in...


Comments and Discussions

Generaltypos in description Pin
Levix18-Jun-06 6:53
memberLevix18-Jun-06 6:53 
GeneralSplitterWnd question Pin
Karl Bahr26-Nov-05 6:04
memberKarl Bahr26-Nov-05 6:04 
GeneralLayout... Pin
Daniel Desormeaux7-Mar-05 9:31
memberDaniel Desormeaux7-Mar-05 9:31 
GeneralAnother way Pin
Astham Ogetti23-Feb-05 1:58
memberAstham Ogetti23-Feb-05 1:58 
GeneralRe: Another way Pin
kozchris9-Nov-05 17:00
memberkozchris9-Nov-05 17:00 
GeneralRe: Another way Pin
jung-kreidler5-Jun-09 0:21
memberjung-kreidler5-Jun-09 0:21 
GeneralWide windows resized by screensaver Pin
viaduct15-Dec-04 0:03
memberviaduct15-Dec-04 0:03 
Generalvideo in multiple monitor Pin
tristestigres28-Apr-04 12:37
membertristestigres28-Apr-04 12:37 
GeneralIncorrect solution Pin
Yawar Maajed2-Dec-03 14:02
memberYawar Maajed2-Dec-03 14:02 
GeneralRe: Incorrect solution Pin
Jonny Newman3-Dec-03 2:43
memberJonny Newman3-Dec-03 2:43 
GeneralRe: Incorrect solution Pin
.:fl0yd:.18-Feb-04 9:41
member.:fl0yd:.18-Feb-04 9:41 
GeneralRe: Link error: _xGetSystemMetrics Pin
BobGratton12-Jun-03 5:00
memberBobGratton12-Jun-03 5:00 
GeneralLink error: _xGetSystemMetrics Pin
BobGratton10-Jun-03 13:16
memberBobGratton10-Jun-03 13:16 
Generallink error Pin
cweng200312-Apr-03 11:42
membercweng200312-Apr-03 11:42 
GeneralRe: link error Pin
xxxyyyzzz11-May-03 13:53
memberxxxyyyzzz11-May-03 13:53 
GeneralRe: link error Pin
TheSuperFreq29-Mar-04 6:02
memberTheSuperFreq29-Mar-04 6:02 
GeneralMinor formatting error Pin
Rama Krishna2-Jul-02 0:54
memberRama Krishna2-Jul-02 0:54 
GeneralRe: Minor formatting error Pin
Jonny Newman2-Jul-02 1:57
memberJonny Newman2-Jul-02 1:57 
GeneralIt's Jonnnnnnnnnnnnnyyyyyyyyyyyyyyyyy Pin
Nishant S1-Jul-02 14:59
memberNishant S1-Jul-02 14:59 
GeneralRe: It's Jonnnnnnnnnnnnnyyyyyyyyyyyyyyyyy Pin
Jonny Newman2-Jul-02 0:24
memberJonny Newman2-Jul-02 0:24 
GeneralRe: It's Jonnnnnnnnnnnnnyyyyyyyyyyyyyyyyy Pin
Nishant S2-Jul-02 0:28
memberNishant S2-Jul-02 0:28 
GeneralRe: It's Jonnnnnnnnnnnnnyyyyyyyyyyyyyyyyy Pin
Jonny Newman2-Jul-02 0:42
memberJonny Newman2-Jul-02 0:42 
GeneralRe: It's Jonnnnnnnnnnnnnyyyyyyyyyyyyyyyyy Pin
Nnamdi Onyeyiri2-Jul-02 7:28
memberNnamdi Onyeyiri2-Jul-02 7:28 
GeneralRe: It's Jonnnnnnnnnnnnnyyyyyyyyyyyyyyyyy Pin
Jonny Newman2-Jul-02 7:39
memberJonny Newman2-Jul-02 7:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Cookies | Terms of Use | Mobile
Web03-2016 | 2.8.180712.1 | Last Updated 2 Jul 2002
Article Copyright 2002 by Jon Newman
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid