Legend: function = function; program = program; SS = Screen Saver;
var = variable; Win = Windows;
WinMgr (Windows Manager) This program does the following:
- Enables / disables / activates the current active screen saver
through a call to the
SytemParametersInfo
function.
- Uses a configuration file to save two user options...stored
in "Windows" directory as "WinMgr.ini".
- Shows how to logoff Windows and/or reboot the machine (two
separate buttons)
- Uses a file menu system in a dialog box
- Calls "Help..about" from dialog system menu and/or
the dialog's file menu.
- 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()
{
BOOL pvParam;
BOOL l_RetVal_b = SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0,
&pvParam, 0);
if(l_RetVal_b)
{
if (pvParam != FALSE){
}
else if (pvParam == FALSE){
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE, 0, 0);
CheckSSStatus();
}
}
}
void CWinMgrDlg::CheckSSStatus(void)
{
BOOL pvParam;
BOOL l_RetVal_b = SystemParametersInfo(SPI_GETSCREENSAVEACTIVE,
0, &pvParam, 0);
if(l_RetVal_b)
{
if (pvParam == FALSE){
m_strEditSSStatus = "DISABLED";
UpdateData(FALSE);
}
else if (pvParam != FALSE)
{
m_strEditSSStatus = "ENABLED";
UpdateData(FALSE);
}
}
}
void CWinMgrDlg::OnButtonactivatess()
{
int ActSSVal;
ActSSVal = m_dConfigDlg.m_iSSValue;
switch(ActSSVal)
{
case 0:
ActivateSS();
OnOK();
break;
case 1:
ShowWindow(SW_MINIMIZE);
ActivateSS();
break;
}
}
void CWinMgrDlg::ActivateSS(void)
{
CDialog dlg;
dlg.Create(IDD_LAUNCHSS_DLG);
dlg.SendMessage(WM_SYSCOMMAND, SC_SCREENSAVE);
dlg.DestroyWindow();
}
LAST NOTES:
LIMITATIONS:
- (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.
- (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