Click here to Skip to main content
15,891,788 members
Articles / Programming Languages / C++
Article

A Windows screensaver and boot manager

Rate me:
Please Sign up or sign in to vote.
2.83/5 (5 votes)
21 May 20025 min read 87.6K   1.2K   24   4
This program Enables / disables / activates the current active screen saver and provides the means to logoff Windows and/or reboot the machine.

Legend: function = function; program = program; SS = Screen Saver; var = variable; Win = Windows;

WinMgr (Windows Manager) This program does the following:

  1. Enables / disables / activates the current active screen saver through a call to the SytemParametersInfo function.
  2. Uses a configuration file to save two user options...stored in "Windows" directory as "WinMgr.ini".
  3. Shows how to logoff Windows and/or reboot the machine (two separate buttons)
  4. Uses a file menu system in a dialog box
  5. Calls "Help..about" from dialog system menu and/or the dialog's file menu.
  6. Populating an edit box with text from code (see the CInfoDlg::OnInitDialog func)

Peruse the Onbuttonnable, Onbuttondisable & CheckSSStatus funcs. This code should be fairly straightforward and most of my code is generously commented as I am and on-and-off programmer.

This is an enhanced version of my second Win32 program, also only my second program in C++/VC++. When I last programmed, I was using Pascal on a 386 SX-16 w/ MS-DOS 5.0 & Win 3.1!

You may use this code in any manner you wish, but I request an email notifying me of the use of the code and a return email address so I can reply to you. I simply want to know how often it is being used by others.

Please send any improvements, bug reports, complaints or modifications you may have...as I am a beginner. My name is Marc and my email is: mehowe@yahoo.com. You will be credited if I use the modifications in any program I write.

This program was written because I burn CD-R's and the SS should be disabled while doing so to avoid transfer interruptions. I didn't want to have to go to my desktop and right-click to open the display properties or open the Control Panel from the start menu. Really, I just wanted to see if I could write a little utility to do various useful Windows tasks.

I did not find an article already on CodeProject dealing with this issue, so here is the code.

This code should work under UNICODE as well. I have only tested it on two separate machines running Win '98. According to MSDN documentation, this code will work on NT 4.0. Since NT 4.0 doesn't support USB, I am still using Win '98...waiting for Win 2000 Professional, as I understand it, it is the Win 2000 version of NT.

This code was written in the MSVC++ 6.0 Pro Edition (w/SR-3 update).

Overview of code:

NOTE: In WinMgr's project settings, I used MFC as a Statically Linked Library. This causes the compiler to give the following two warnings when set to the Level 4 error checking state:

LINK : warning LNK4089: all references to "SHELL32.dll" discarded by /OPT:REF
LINK : warning LNK4089: all references to "comdlg32.dll" discarded by /OPT:REF

If you receive either of these warnings, you can ignore them (according to documentation). This is just letting you know that the MFC is being used as a Statically Linked Library.

Now, the real stuff. First, the InitDialog function calls the CheckSSStatus function to determine the current SS Status and update the dialog's edit box with the SS state's value.

Next, if the Enable button is pressed, it calls the Onbuttonenable function. See the function for details.

The Disable button calls the Onbuttondisable function and works in the same manner as the Onbuttonenable func, except sending the FALSE value to disable the current SS.

The CheckSSStatus function initializes in basically the same manner as the above functions. However, it also sets a CString member var named m_strEditSSStatus to "ENABLED" or "DISABLED" depending on the SS current status and then sends it the the dialog's edit box. It then updates the dialog's display to show the user the current SS state.

void CWinMgrDlg::OnButtonenabless() 
{
    // TODO: Add your control notification handler code here
    // NOTE: The following code was corrected by Kunz Dieter...Thanks!

    //declare local bool variable for the SystemParametersInfo func()
    BOOL pvParam; 
    BOOL l_RetVal_b = SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, 
        &pvParam, 0);

    // the function call was ok - only in this case the pvParam holds 
    // valid data
    if(l_RetVal_b)
    {
        if (pvParam != FALSE){
            //If SS already enabled, do nothing
        } //end if

        //If SS disabled, enable it
        else if (pvParam == FALSE){
            //Enable screen saving capability for the current user session
            SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE, 0, 0); 

            //Call CheckSSStatus() function to check performance of 
            // SystemParameterInfo() function & update the dialog's 
            // display with current SS status

            CheckSSStatus();
        } //end else if 
    } //end top if
} //end OnButtonenabless()
void CWinMgrDlg::CheckSSStatus(void)
{

    BOOL pvParam; //declare local bool variable for the 
    //SystemParametersInfo func()
    BOOL l_RetVal_b = SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 
        0, &pvParam, 0);

    // the function call was ok - only in this case the pvParam 
    // holds valid data
    if(l_RetVal_b)
    {
        if (pvParam == FALSE){

            //If SS disabled, send "DISABLED" to read-only 
            // edit control and update the display
            //m_EditSSStatus is a member Cstring var for the dialog's 
            // edit box
            m_strEditSSStatus = "DISABLED"; 
            UpdateData(FALSE);
        } //end if

        //NOTE: also tried pvParam here as test value
        else if (pvParam != FALSE)
        { 
            //If SS enabled, send "ENABLED" to read-only edit control and 
            // update the display

            m_strEditSSStatus = "ENABLED"; //m_EditSSStatus is a member 
            // Cstring var for the dialog's 
            // edit box
            UpdateData(FALSE);
        } //end else if
    } //end top if

} //end CheckSSStatus()
void CWinMgrDlg::OnButtonactivatess() 
{
    // TODO: Add your control notification handler code here
    //Add code to check the state of the two check boxes for 
    //ActivateSS options
    //if()
    int ActSSVal;
    ActSSVal = m_dConfigDlg.m_iSSValue;
    switch(ActSSVal)
    {
    case 0: //Exit radio button
        ActivateSS();
        OnOK(); //Now Exit WinMgr
        break;
    case 1: //Minimize radio button
        ShowWindow(SW_MINIMIZE);
        ActivateSS();
        break;
    }
} //End OnButtonactivatess()

void CWinMgrDlg::ActivateSS(void)
{
    /*** Code contributed by anonymous source on CodeGuru 
    discussion board...Thank You!***/
    CDialog dlg; //Create temp modal dialog
    //Create temp dialog using IDD_LAUNCHSS_DLG dlg
    dlg.Create(IDD_LAUNCHSS_DLG);
    //send SysCommand message calling SS
    dlg.SendMessage(WM_SYSCOMMAND, SC_SCREENSAVE);
    dlg.DestroyWindow(); //destroy temporary dialog window

    //**Notice no call to DoModal()...therefore no window is shown**

    //Other way to activate SS...doesn't work here
    //OnSysCommand(SC_SCREENSAVE, SC_SCREENSAVE); 
}

LAST NOTES:

LIMITATIONS:

  1. (Intentional) Once a button is pushed, the SS enable/diable action is carried out...no way to cancel. This program was meant to be simple and small. The user must use the other button to reset the SS or go to the display properties via desktop or Control Panel to change it back.
  2. (Intentional) No OK or CANCEL buttons as ESC key or the [X] button on the system title bar will close the prog. Program does not eat the ESC key intentionally. If you would like some code to eat the ESC key, simply let me know.

SYSTEM REQUIREMENTS: 

Appears to use about 200K RAM when running. May run on any Win'9x or Win NT system...see "Tested On" below.
TESTED ON: Two Pentium II machines running Win'98. These machines are also running the freeware CPU cooler utility "RAIN"--a CPU cooler that I highly recommended for anyone using Win'9x. Win NT 4.0 already has a built-in CPU cooling routine as part of its OS. Neither system has experienced any conflicts with RAIN, ever! I am in no way affiliated with the RAIN programmers, I just recommend it for anyone using a Win '9x Pentium II (or better) machine as these CPU's get incredibly HOT due to their high clock speeds!

LEGAL/WARRANTY: 

This software is (C) Copyrighted 1999 by Marc E. Howe, All Rights Reserved. The author makes no warranties, either expressed or implied regarding the use of any of the WinMgr software. The user is wholly responsible for any and all damages resulting from the use of this software. The author is fully free from all liability regarding the use of this software by the consumer. You may use this code in any manner you wish, but the author requests an email notifying him of the use of the code and a return email address so the author can reply. By using this software, you agree to all of the terms in the above legal / warranty statements.

email to Marc at: mehowe@yahoo.com
(C) Copyrighted 1999 by Marc E. Howe, All Rights Reserved.

Peace, Honor & Respect,
Marc

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionactivate ss does not works on vista Pin
vikrant kpr12-Nov-07 12:49
vikrant kpr12-Nov-07 12:49 
GeneralPrinting Pages count Pin
ThangaDharma6-Oct-05 7:38
ThangaDharma6-Oct-05 7:38 
QuestionControl Panel->Display OK'd always ENABLE SS, Why?? Pin
Akif27-May-03 10:53
Akif27-May-03 10:53 
GeneralReboot and logoff will not work on NT/W2K Pin
Wouter Dhondt5-Mar-02 23:38
Wouter Dhondt5-Mar-02 23:38 

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.