Introduction
This is a simple utility for shutting down your system.
Simply set the time on the tool, for the machine you wish to shut down (24 hrs), choose whether to log off, reboot or shutdown, or power off (ATX main boards only), and click Hide. It has been tested on Win9x/ME, WinNT/2000/XP. The full source code is in the Zip file.
In case of problems in getting it to work, when setting the end time make sure that you click on the number after that. It is a list box, so the GetCaretIndex()
call will always return 0 unless you select a number by clicking on it.
What's new in this tool?
- Well, old wine in a new bottle. The nasty code in
OnInitDialog()
is totally replaced by a new one. Now some of my colleagues will neither get totally shutdown by looking at that code ;-D nor will it look nasty!!!.
- Dialog refreshing is toggled by the flag, so that it doesn't get unnecessarily repainted (when clicked on menu "Open main window").
- Ability to abort shutdown in progress through message box.
What is really missing?
- The ability to shut down remote computers.
I don't have network here. But if you want to remotely shutdown the computer use the following function: BOOL InitiateSystemShutdown
. It has the following parameters:
- pointer to the name of the computer to be shutdown,
- pointer to the message to be displayed in the dialog box,
- time to display the dialog box,
- force applications closed flag,
- reboot flag.
The first parameter takes the name of the computer in the network. If it's null
the local machine will be down.
Working
As soon as you run/compile, it will be passed to the system tray. OnInitDialog()
will fill the list box with hrs/mins/secs as follows:
CListBox* pListHrs = static_cast(GetDlgItem(IDC_LISTHRS));
while(i<=24) { _itoa(i,buff,10); pListHrs->AddString(buff); i++;}
Timer will start its execution and the user's time will be checked at regular intervals. As soon as the condition is met, the selected option will be passed to Sflag
. This flag in turn is checked in the switch
statement and the following code executes:
Switch(Sflag) {
case 0: CDialog::KillTimer (nIDEvent);
ExitWindowsEx(EWX_SHUTDOWN ,EWX_FORCE);
exit(0);
break;
.
.
.
}
If you have recent versions of Visual Studio and MSDN (which, I don't have), you can simply add hibernate. You can use EWX_FORCEIFHUNG
instead of EWX_FORCE
, sometimes for Windows NT 5.0 and later: it forces processes to terminate if they do not respond to the WM_QUERYENDSESSION
or WM_ENDSESSION
message. This flag is ignored if EWX_FORCE
is used.
Credits
As far as the different classes that are used in my utility, appropriate credits are given to:
CHoverButton
by Niek Albers.
- Auto Font by Keith Rule.
- System Tray by Chris Maunder.
- On line MSDN by Microsoft.
tray.cpp and tray.h were originally named as systemtray.cpp and systemtray.h at CodeProject. All the above class files were downloaded from CodeProject. Thanks to all those who helped me directly or indirectly for this (and other utilities). Special thanks to all those people who maintain CodeProject.