-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUnit1.pas
242 lines (213 loc) · 5.32 KB
/
Unit1.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Spin, Buttons, ExtCtrls, shellapi;
type
TForm1 = class(TForm)
rgAction: TRadioGroup;
gpInterval: TGroupBox;
rgTimerType: TRadioGroup;
bBtnRun: TBitBtn;
SpinEdit1: TSpinEdit;
Label0: TLabel;
SpinEdit2: TSpinEdit;
Label1: TLabel;
SpinEdit3: TSpinEdit;
Label2: TLabel;
gpAdditional: TGroupBox;
cbVisualTimer: TCheckBox;
cbForceShutdown: TCheckBox;
btnSetReason: TButton;
bBtnCancel: TBitBtn;
DebugLabel: TLabel;
timeVisInterval: TTimer;
timeShutdown: TTimer;
procedure bBtnRunClick(Sender: TObject);
procedure timeVisIntervalTimer(Sender: TObject);
procedure btnSetReasonClick(Sender: TObject);
procedure rgActionClick(Sender: TObject);
procedure rgTimerTypeClick(Sender: TObject);
procedure bBtnCancelClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
secbuf: integer;
reas: string;
implementation
{$R *.dfm}
procedure TForm1.bBtnRunClick(Sender: TObject);
var
mc, ac: string[4];
command: string;
hs, ms, ss, timesec: integer;
begin
case rgAction.ItemIndex of
0:
mc := '-s ';
1:
mc := '-p ';
2:
mc := '-l ';
3:
mc := '-r ';
4:
mc := '-g ';
5:
mc := '-h ';
end;
if SpinEdit1.Value <> 0 then
hs := SpinEdit1.Value * 3600
else
hs := 0;
if SpinEdit2.Value <> 0 then
ms := SpinEdit2.Value * 60
else
ms := 0;
if SpinEdit3.Value <> 0 then
ss := SpinEdit3.Value
else
ss := 0;
case rgAction.ItemIndex of
0:
begin
timesec := hs + ms + ss;
secbuf := timesec;
end;
1:
begin
timesec := 1;
timeShutdown.Interval := (hs + ms + ss) * 1000;
secbuf := timeShutdown.Interval div 1000;
timeShutdown.Enabled := true;
end;
end;
if cbForceShutdown.Checked then
ac := '-f '
else
ac := '';
if cbVisualTimer.Checked then
timeVisInterval.Enabled := true;
if reas <> '' then
reas := ' -c "' + reas + '"';
command := ' ' + mc + ac;
if(rgAction.ItemIndex < 5) then
command := command + '-t ' + inttostr(timesec) + reas;
if(rgAction.ItemIndex = 5) then
WinExec('powercfg -h on', SW_SHOWNORMAL);
if(rgAction.ItemIndex = 6)
then
begin
WinExec('powercfg -h off', SW_SHOWNORMAL);
WinExec('RUNDLL32.EXE powrprof.dll,SetSuspendState 0,1,0', SW_HIDE);
end
else
ShellExecute(Application.Handle, pchar('open'), pchar('shutdown'), pchar(command), '', SW_SHOWNORMAL);
bBtnCancel.Enabled := true;
bBtnRun.Enabled := false;
gpInterval.Enabled := false;
rgAction.Enabled := false;
SpinEdit1.Enabled := false;
SpinEdit2.Enabled := false;
SpinEdit3.Enabled := false;
Label0.Enabled := false;
Label1.Enabled := false;
Label2.Enabled := false;
gpAdditional.Enabled := false;
cbVisualTimer.Enabled := false;
cbForceShutdown.Enabled := false;
rgAction.Enabled := false;
// DebugLabel.Caption:=command;
end;
procedure TForm1.bBtnCancelClick(Sender: TObject);
begin
WinExec('shutdown -a', SW_hide);
timeShutdown.Enabled := false;
timeVisInterval.Enabled := false;
bBtnRun.Caption := 'Âûïîëíèòü';
rgAction.Enabled := true;
rgAction.ItemIndex := -1;
rgAction.ItemIndex := -1;
bBtnCancel.Enabled := false;
bBtnRun.Enabled := true;
end;
procedure TForm1.btnSetReasonClick(Sender: TObject);
begin
reas := InputBox('Ïðèíà îòêëþ÷åíèÿ',
'Íàïèøèòå çäåñü íàïîìèíàíèå äëÿ ñåáÿ, ïî÷åìó âû çàïëàíèðîâàëè îòêëþ÷åíèå:',
'');
if reas <> '' then
begin
rgAction.Caption := 'Ïðè÷èíà óêàçàíà';
rgAction.Font.Style := [fsItalic];
end;
end;
procedure TForm1.rgActionClick(Sender: TObject);
var
continue: boolean;
begin
continue := true;
if (rgAction.ItemIndex = 1) or (rgAction.ItemIndex = 4) or (rgAction.ItemIndex = 5) then
begin
continue := false;
if (Win32Platform = VER_PLATFORM_WIN32_NT) then
begin
if (rgAction.ItemIndex = 1) then
begin
bBtnRun.Enabled := true;
cbForceShutdown.Checked := true;
end;
if (rgAction.ItemIndex = 4) then
begin
continue := true;
end;
if (rgAction.ItemIndex = 5) then
begin
bBtnRun.Enabled := true;
end;
end
else
begin
MessageDlg('Â âàøåé ÎÑ íå ïîääåðæèâàåòñÿ äàííàÿ ôóíêöèÿ!', mtError,
[mbOK], 0);
rgAction.ItemIndex := -1;
end;
end;
if (rgAction.ItemIndex = 2) or (rgAction.ItemIndex=6) then
begin
bBtnRun.Enabled := true;
continue := false;
end;
if continue then
begin
rgTimerType.Enabled := true;
bBtnRun.Enabled := false;
rgAction.Enabled := false;
end;
end;
procedure TForm1.rgTimerTypeClick(Sender: TObject);
begin
gpInterval.Enabled := true;
SpinEdit1.Enabled := true;
SpinEdit2.Enabled := true;
SpinEdit3.Enabled := true;
Label0.Enabled := true;
Label1.Enabled := true;
Label2.Enabled := true;
gpAdditional.Enabled := true;
cbVisualTimer.Enabled := true;
cbForceShutdown.Enabled := true;
btnSetReason.Enabled := true;
bBtnRun.Enabled := true;
end;
procedure TForm1.timeVisIntervalTimer(Sender: TObject);
begin
secbuf := secbuf - 1;
bBtnRun.Caption := 'Äî âûêëþ÷åíèÿ îñòàëîñü: ' + inttostr(secbuf) +
' ñåêóíä...';
end;
end.