[译]关闭系统的简单实用程序
By robot-v1.0
本文链接 https://www.kyfws.com/applications/a-simple-utility-for-shutting-down-your-system-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 5 分钟阅读 - 2021 个词 阅读量 0[译]关闭系统的简单实用程序
原文地址:https://www.codeproject.com/Articles/3877/A-simple-utility-for-shutting-down-your-System
原文作者:Balkrishna Talele
译文由本站 robot-v1.0 翻译
前言
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.
只需在要关闭机器的工具上设置时间(24小时),选择注销,重新启动或关闭还是关闭电源(仅适用于ATX主板),然后单击"隐藏".它已经在Win9x/ME,WinNT/2000/XP上进行了测试.
介绍(Introduction)
这是一个用于关闭系统的简单实用程序.(This is a simple utility for shutting down your system.)
只需在工具上设置时间,即可针对要关闭的计算机设置时间(24小时),选择注销,重新启动或关闭还是关闭电源(仅适用于ATX主板),然后单击"隐藏".它已经在Win9x/ME,WinNT/2000/XP上进行了测试.完整的源代码在Zip文件中.(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()
呼叫将始终返回0,除非您通过单击选择一个数字.(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)**通过查看该代码;-D也不会看起来很讨厌!!!(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;
.
.
.
}
如果您拥有Visual Studio和MSDN的最新版本(我没有),则只需添加休眠即可.您可以使用(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
,有时对于Windows NT 5.0及更高版本:如果它们不响应进程,它将强制进程终止(, 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
尼克`阿尔伯斯(Niek Albers)着.(by Niek Albers.)- 自动字体的基思规则.(Auto Font by Keith Rule.)
- Chris Maunder撰写的系统任务栏.(System Tray by Chris Maunder.)
- 由Microsoft在MSDN上在线.(On line MSDN by Microsoft.) *tray.cpp(tray.cpp)*和(and)*托盘(tray.h)*原名为(were originally named as)*systemtray.cpp(systemtray.cpp)*和(and)*系统托盘(systemtray.h)*在CodeProject.以上所有类文件都是从CodeProject下载的.感谢所有直接或间接为我提供帮助的人(以及其他实用程序).特别感谢维护CodeProject的所有人员.(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.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VC6 WinXP Windows Win2K MFC Visual-Studio Dev 新闻 翻译