Write a timed shutdown program with C Builder
Liaoning University Zheng Yongfan
When downloading larger software from the Internet, many people like to take a break in the evening due to the current network bandwidth. At present, most download software can estimate the time required to download, if the computer is automatically turned off, you can freely suffer. This article describes a program that the author uses C Builder 5 that implements the timing automatic shutdown. The run interface of the program function program is shown in Figure 1:
figure 1
Figure 1 The upper half of the interface is used to instantly display the date and time information of the current system, and the lower half is used to set the date and time of the automatic shutdown. The computer will automatically turn off when the system time and the shutdown time of the setup (equal) and "Auto Shutdown Effect" are selected. Among them, only when the set shutdown time is within the effective range (ie, the system time), "automatic shutdown to take effect" can be activated. Component settings 2 TGROUPBOX components on the form: Groupbox1 and GroupBox2, its CAPTION attribute is set to "Current System Time" and "Preset Off Time". Place 4 TDATETIMEPICKER components on both components: DateTimePicker1, DateTimePicker2 and DateTimePicker3, DateTimePicker4, where the first two are used to display the date and time of the current system, and the latter two is used to set the date and time of automatic shutdown, they The partial property value is set as shown in the following table: Place a Tcheckbox component on the form: CheckBox1 (its CAPTION property is set to Auto Shutdown) and a TTIMER component: Timer component: Timer1 (its interval property takes antide value 1000).
The code writes in the form of the oncreate event process to prepare the following code: void __fastcall tform1 :: formcreate (TOBJECT * Sender) {checkbox1-> checked = false; // Initial set to not access CheckBox1-> enabled = false; datetimepicker4-> DateTime = now (); DateTimePicker3-> DateTime = now (); DateTimePicker2-> DateTime = now (); // Time initialization component DateTimePicker1-> DATETIME = now ();} Written during the ONTIMER event of the component Timer1 As follows: void __fastcall tform1 :: timer1timer (TOBJECT * Sender) {datetimepicker2-> DateTime = now (); // Receive the current date and time for instant display datetimepicker1-> datetime = now (); // At any time detection Determined shutdown date and time if it is effective if (DateTimePicker4-> DateTime