Write a timed shutdown program with C ++ Builder

zhaozj2021-02-08  246

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 checked = false; // is invalid when accessing checkbox1-> enabled = false;} else checkbox1-> enabled = true; / / Visit IF (checkbox1-> checked == true ") == DateTimetostr (now ()) {// Call the WIN API function to close the dword tmp; // call the win API function Computer EXITWINDOWSEX (EWX_SHUTDOWN, TMP);}} The code of the INCHANGE event procedure of the DateTimePicker4 is similar to the date and time "linkage" (simultaneous changes) set by the DateTimePicker4 (simultaneous changes), and the component DateTimePicker3 is set. : Void __fastcall tform1 :: datetimepicker3change (TOBJECT * Sender) {// component change "linkage" DateTimePicker4-> DateTime = DateTimePicker3-> DateTime; // date set for the test is valid if (DateTimePicker4-> DateTime Checked = false; CheckBox1-> Enabled = false;} else CheckBox1-> Enabled = True;} Component DateTimePicker4 onchange code settings as follows: void __fastcall tform1 :: datetimepicker4change (TOBJECT * Sender) {// component change "linkage" DateTimePicker3-> DateTime =

转载请注明原文地址:https://www.9cbs.com/read-2370.html

New Post(0)