-
Notifications
You must be signed in to change notification settings - Fork 0
/
soff.pas
270 lines (236 loc) · 6.71 KB
/
soff.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
unit soff;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons,ShellApi, ExtCtrls, UCountDown,
OSControl, UMsgBox, UnitCustom;
const
WM_NOTIFYICON = WM_USER+333;
type
TForm1 = class(TForm)
bbtn_soff: TBitBtn;
bbtn_cust: TBitBtn;
bbtn_off: TBitBtn;
bbtn_rein: TBitBtn;
bbtn_susp: TBitBtn;
bbtn_lock: TBitBtn;
bbtn_lout: TBitBtn;
bbtn_hib: TBitBtn;
GroupBox2: TGroupBox;
GroupBox1: TGroupBox;
checkbeep: TCheckBox;
checktop: TCheckBox;
Panel1: TPanel;
bbtn_pause: TBitBtn;
bbtn_stop: TBitBtn;
bbtn_play: TBitBtn;
BitBtn7: TBitBtn;
BitBtn6: TBitBtn;
BitBtn5: TBitBtn;
BitBtn4: TBitBtn;
BitBtn3: TBitBtn;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn8: TBitBtn;
procedure bbtn_soffClick(Sender: TObject);
procedure bbtn_suspClick(Sender: TObject);
procedure bbtn_reinClick(Sender: TObject);
procedure bbtn_offClick(Sender: TObject);
procedure bbtn_custClick(Sender: TObject);
procedure bbtn_hibClick(Sender: TObject);
procedure bbtn_loutClick(Sender: TObject);
procedure bbtn_lockClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure bbtn_playClick(Sender: TObject);
procedure bbtn_pauseClick(Sender: TObject);
procedure bbtn_stopClick(Sender: TObject);
procedure checkbeepClick(Sender: TObject);
procedure checktopClick(Sender: TObject);
private
{ Private declarations }
TrayIcon: TNotifyIconData;
HMainIcon: HICON;
Counter:TCountDown;
Action:integer;
procedure ClickTrayIcon(var msg: TMessage); message WM_NOTIFYICON;
procedure MinimizeClick(Sender:TObject);
procedure ShowButtonsForm();
procedure ShowTimerForm();
procedure CountDownFinished(Sender:TObject);
procedure StopCountDown();
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//------------------- PRIVATE DECLARATIONS -------------------//
procedure TForm1.ClickTrayIcon(var msg:TMessage);
begin
case msg.lparam of
WM_LBUTTONUP, WM_LBUTTONDBLCLK :
{WM_BUTTONDOWN may cause next Icon to activate if this icon is deleted -
(Icons shift left and left neighbor will be under mouse at ButtonUp time)}
begin
Application.Restore; {restore the application}
If WindowState = wsMinimized then WindowState := wsNormal; {Reset minimized state}
visible:=true;
SetForegroundWindow(Application.Handle); {Force form to the foreground }
Shell_NotifyIcon(NIM_Delete, @TrayIcon);
end;
end;
end;
procedure TForm1.MinimizeClick(Sender:TObject);
begin
Shell_NotifyIcon(NIM_Add, @TrayIcon);
Hide;
if IsWindowVisible(Application.Handle)then
ShowWindow(Application.Handle, SW_HIDE);
end;
procedure TForm1.ShowButtonsForm();
var
i:byte;
begin
groupbox2.Hide;
for i:=0 to 7 do
(Form1.Controls[i]as TBitBtn).Show;
Height:=160;
FormStyle:=fsNormal;
Form1.Caption:='ScreenOFF!';
end;
procedure TForm1.ShowTimerForm();
var
i:byte;
begin
Form1.Caption:='*** ACCION: ' + Form2.ComboBox1.Text + ' ***';
for i:=0 to 7 do
(Form1.Controls[i]as TBitBtn).Hide;
groupbox2.Top:=0;
groupbox2.Show;
form1.Height:=110;
end;
procedure TForm1.StopCountDown();
begin
with form1 do begin
Counter.StopTimer;
Counter.Free;
ShowButtonsForm;
end;
end;
procedure TForm1.CountDownFinished(Sender:TObject);
begin
StopCountDown;
case Action of
0: ScreenTurnOff;
1: SystemSuspend('La opción de SUSPENDER está deshabilitada en este equipo','ERROR!');
2: SystemReboot;
3: SystemPowerOff('El equipo no soporta la opción de soft power off','ERROR!');
4: SystemHibernate('La opción de HIBERNAR está deshabilitada en este equipo','ERROR!');
5: SystemLogOut;
6: SystemLock('La opción de BLOQUEO está deshabilitada en este equipo','ERROR!');
end;
end;
//-----------------------------------------------------------//
procedure TForm1.bbtn_lockClick(Sender: TObject);
begin
SystemLock('La opción de BLOQUEO está deshabilitada en este equipo','ERROR!');
end;
procedure TForm1.bbtn_offClick(Sender: TObject);
begin
SystemPowerOff('El equipo no soporta la opción de soft power off','ERROR!');
end;
procedure TForm1.bbtn_reinClick(Sender: TObject);
begin
SystemReboot;
end;
procedure TForm1.bbtn_suspClick(Sender: TObject);
begin
SystemSuspend('La opción de SUSPENDER está deshabilitada en este equipo','ERROR!');
end;
procedure TForm1.bbtn_loutClick(Sender: TObject);
begin
SystemLogOut;
end;
procedure TForm1.bbtn_hibClick(Sender: TObject);
begin
SystemHibernate('La opción de HIBERNAR está deshabilitada en este equipo','ERROR!');
end;
procedure TForm1.bbtn_soffClick(Sender: TObject);
begin
ScreenTurnOff;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Height:=160;
HMainIcon:=LoadIcon(MainInstance, 'MAINICON');
Shell_NotifyIcon(NIM_DELETE, @TrayIcon);
with trayIcon do
begin
cbSize := sizeof(TNotifyIconData);
Wnd := handle;
uID := 123;
uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
uCallbackMessage := WM_NOTIFYICON;
hIcon := HMainIcon;
szTip := 'Restaurar SOFF!';
end;
Application.OnMinimize:= MinimizeClick;
Counter := nil;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_Delete, @TrayIcon)
end;
//----------------- TIMER DECLARATIONS ---------------------
procedure TForm1.bbtn_custClick(Sender: TObject);
var
i:integer;
TCounter:TCountDown;
begin
Form2:=TForm2.Create(Application);
if(Form2.ShowModal=1)then begin
if(Counter <> nil)then
Counter.RefreshCountDown
else
Counter:=TCountDown.create(Panel1);
With Counter do begin
OnTimeOut:=Form1.CountDownFinished;
SetTimeHMS(Form2.spine_h.value,Form2.spine_m.value,Form2.spine_s.value);
SetRandomColor(true);
end;
Action:=Form2.ComboBox1.ItemIndex;
checkbeep.Checked:=Form2.checkBeep.Checked;
checktop.Checked:=Form2.checktop.Checked;
Counter.SetBeep(checkbeep.Checked);
ShowTimerForm;
Counter.StartTimer;
end;
Form2.Free;
end;
procedure TForm1.checkbeepClick(Sender: TObject);
begin
Counter.SetBeep(checkBeep.Checked);
end;
procedure TForm1.checktopClick(Sender: TObject);
begin
if(checktop.Checked)then
Form1.FormStyle:=fsStayOnTop
else
Form1.FormStyle:=fsNormal;
end;
procedure TForm1.bbtn_stopClick(Sender: TObject);
begin
StopCountDown;
end;
procedure TForm1.bbtn_pauseClick(Sender: TObject);
begin
Counter.StopTimer;
end;
procedure TForm1.bbtn_playClick(Sender: TObject);
begin
Counter.StartTimer;
end;
//------------------------------------------------------
end.