A Complete Screen Saver Framework Using MFC

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

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

  • Technology has transformed the distribution industry so much that the industry is barely recognizable today. With the new technology options available today, smaller distributors can have the agility, precision, and speed they need to succeed against large competitors with deep pockets. Configure-price-quote (CPQ) software is one of the main technologies helping distributors become more competitive. Read this white paper to learn how an integrated, rules-based CPQ solution can provide an interactive visual …

  • Many enterprises are working with an IT architecture that's evolved over time. As business needs evolve, IT must decide whether to modernize incrementally, or all at once. Each approach has its benefits and drawbacks. Identity Management is key to modernizing IT; it plays a crucial role in migrating to cloud apps like Office 365 or HR information systems, building web and mobile apps, and opening developer access to business systems. Read how Okta's modern approach to identity management helps business lower …

Most Popular Programming Stories

More for Developers

RSS Feeds

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