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!

Downloads

Download Source Code - 161 Kb


Comments

  • 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;
    system("saver");
    return TRUE;
    }

    Reply
  • 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 
    
    time.

    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)
    //monitor
    //SM_CMONITORS is not defined if WINVER < 0x0500
    if ( ::GetSystemMetrics(SM_CMONITORS) == 0 )
    {
    rect.SetRect(0, 0,
    ::GetSystemMetrics(SM_CXSCREEN),
    ::GetSystemMetrics(SM_CYSCREEN));
    }
    //on 98/ME/2000/and XP create a window to fill the
    //entire virtual desktop
    else
    {
    rect.SetRect(::GetSystemMetrics(SM_XVIRTUALSCREEN),
    ::GetSystemMetrics(SM_YVIRTUALSCREEN),
    ::GetSystemMetrics(SM_CXVIRTUALSCREEN),
    ::GetSystemMetrics(SM_CYVIRTUALSCREEN));
    }

    return this->CDrawWnd::Create(WS_EX_TOPMOST,
    ::AfxGetAppName(),
    WS_VISIBLE | WS_POPUP,
    rect,
    NULL);

    }

    Reply
  • thank you very much!

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

    Originally posted by: yunchang yuan

    Reply
  • 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

    Reply
  • 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".

    Reply
  • 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.

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

Top White Papers and Webcasts

  • As your content grows, it can be challenging to define the proper rules, regulations and policies that govern that content and ensure proper protection and compliance. Entrusting your content to Box – the only secure, modern content platform in the cloud – is the right first step. The next step is to evaluate your retention, disposition and defensible discovery needs and to establish the proper buy-in to satisfy all your needs. In this Information Governance webinar, learn how Box Governance can add …

  • On-demand EventEvent Date: March 21, 2017 With the rise in ransomware attacks, bank heists that reached new levels of sophistication, and extortion plots that were beyond anything we could have imagined, 2016 certainly was an eventful year for cybersecurity. Going into 2017, no business can afford to be uninformed about cybersecurity or unprepared for an attack. Watch this informative webinar, presented by Andrey Pozhogin, Senior B2B Product Marketing Manager at Kaspersky Lab, as he examines predictions for …

Most Popular Programming Stories

More for Developers

RSS Feeds

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