A Complete Screen Saver Framework Using MFC

This article was contributed by chensu.

Environment: Visual C++ 6.0 with Service Pack 3, Windows 9x and Windows NT 4.0 with Service Pack 3

Here is a complete screen saver framework. It is based on the MFC sample "SAVER: Screen Saver" that comes with Visual C++. But I added more functionality so that it does everything a screen saver needs to do. To help you understand it and insert your own code, I removed all the drawing code so that it is as simple as possible (blank screen). In addition, I wrote a simple installation program. This installation program puts the screen saver (saver.scr) into its resource so that only one executable file (sinstall.exe) needs to be distributed. The Project Workspace contains two projects. One is the screen saver itself, another is the installation program.

In most cases, you will only need to make the following modifications.

  • Add drawing code in the drawwnd.h and drawwnd.cpp.
  • Add a configuration dialog box, launch it in the CSaverApp::DoConfig function of the saver.cpp.
  • Add your own resource if any (resource.h and saver.rc).

For your reference, I list some Web sites related to Windows screen saver programming here.

Happy Screen Saving!


Download Source Code - 161 Kb


  • Let's a screensaver do anything you like!

    Posted by Legacy on 05/01/2003 12:00am

    Originally posted by: Xin Feng

    I changed the code slightly so it'll call, say, "saver.bat" and run any command you want when screensaver is activated. One great program to run is the wizmo which allows almost all power management such as turning off monitor. Download wizmo on http://grc.com/wizmo/wizmo.htm.

    Here is the part I changed in CSaverApp::InitInstance()

    case SMSAVER:
    // Run the screen saver
    // CSaverWnd *pWnd = new CSaverWnd;
    // pWnd->Create();
    // m_pMainWnd = pWnd;
    return TRUE;

  • Fix for multiple monitors

    Posted by Legacy on 03/14/2002 12:00am

    Originally posted by: Donald Kackman

    This is a very nice piece of work and saved me a ton of 

    I think I've got a fix for multiple monitor support. You do
    need to set WINVER = 0x500 to compile this but the if test
    should keep it working on 95 and NT4.

    BOOL CSaverWnd::Create()
    CRect rect;
    //Win95 and NT 4 should return 0 because they do
    //not support SM_CMONITORS
    //just create a window to fill the primary (and only)
    //SM_CMONITORS is not defined if WINVER < 0x0500
    if ( ::GetSystemMetrics(SM_CMONITORS) == 0 )
    rect.SetRect(0, 0,
    //on 98/ME/2000/and XP create a window to fill the
    //entire virtual desktop

    return this->CDrawWnd::Create(WS_EX_TOPMOST,


  • thank you very much!

    Posted by Legacy on 12/31/2001 12:00am

    Originally posted by: yunchang yuan

  • Excellent Code

    Posted by Legacy on 10/15/2000 12:00am

    Originally posted by: Jason Hattingh

    This has been invaluable to me, and I also really like the framework for creating custom setups! The SaveResourceToFile functions came in useful, to

    Thanks dude

  • Nice work, but ...

    Posted by Legacy on 10/29/1999 12:00am

    Originally posted by: Joachim Fehlauer

    Your workframe is fine. By the way don't forget to implement a String in the String-Table with ID = 1 and insert a text, so this text will appear in the Screensaver Properties Name. E.g. "Mobbing Screensaver".

  • It's Useful Solution

    Posted by Legacy on 08/12/1999 12:00am

    Originally posted by: Viktor

    Your idea is good. Someone has really a bit to modify/add to the 'saver' project to get particular fitness. But in some aspects the things are not transparent. For instance why do You use two-step derivation from CWnd? (I expect because it's a part of some larger project from Your accumulations remaining unchanged.) The better is to implement primary screensaver functions as virtual methods with simple implementation in a single base class. If You intend the user should change something in Your code it's not good to modify the intermediate class (may affect the derivative). So the skeletal functions should be placed in the leaf class of the hierarchy.

    I found strange that every call to a method of the currect object within its class scope is preceded with 'this->'. It does not affect the semantics but what is it for?

    Thank You for the idea with placing an executable within a resource. It is the easier than I could mean.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The open source cloud computing project OpenStack has come a long way since NASA and Rackspace launched it in 2010. Backed by leading technology infrastructure providers including Cisco, Dell, EMC, HP, IBM, Intel, and VMware, OpenStack underpins significant workloads at an increasingly diverse set of organizations, including BWM, CERN, Comcast, eBay, and Wal-Mart. For CIOs engaged in broader programs to win, serve, and retain customers -- and refocus business technology (BT) spend -- a planned and pragmatic …

  • Entire organizations suffer when their networks can't keep up and new opportunities are put on hold. Waiting on service providers isn't good business. In these examples, learn how to simplify network management so that your organization can better manage costs, adapt quickly to business demands, and seize market opportunities when they arise.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date