-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
137 lines (116 loc) · 3.71 KB
/
Main.cpp
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
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
// #define TESTING 1
// Get the horizontal and vertical screen sizes in pixel
void GetDesktopResolution(int& horizontal, int& vertical) {
RECT desktop;
// Get a handle to the desktop window
const HWND hDesktop = GetDesktopWindow();
// Get the size of screen to the variable desktop
GetWindowRect(hDesktop, &desktop);
// The top left corner will have coordinates (0,0)
// and the bottom right corner will have coordinates
// (horizontal, vertical)
horizontal = desktop.right;
vertical = desktop.bottom;
}
// c:\windows\system32\shutdown /l
// c:\windows\system32\shutdown /r /t 0
// c:\windows\system32\shutdown /s /f /t 0
// rundll32.exe powrprof.dll,SetSuspendState 0,1,0
void shutdown(void) {
// Shutdown ... NOW!
#ifdef TESTING
ShowMessage("Shutdown");
#else
// system("shutdown /s /t 0");
// system("c:\\windows\\system32\\shutdown /s /f /t 0");
system("c:\\windows\\system32\\shutdown /s /f /t 0");
Application->MainForm->Close();
#endif
}
void restart(void) {
// Restart ... NOW
#ifdef TESTING
ShowMessage("Restart");
#else
// system("shutdown /r /t 0");
system("c:\\windows\\system32\\shutdown /r /t 0");
Application->MainForm->Close();
#endif
}
void logoff(void) {
// Log Off
#ifdef TESTING
ShowMessage("Log Off");
#else
// system("shutdown /l");
system("c:\\windows\\system32\\shutdown /l");
Application->MainForm->Close();
#endif
}
void sleep(void) {
// Sleep Mode
#ifdef TESTING
ShowMessage("Sleep");
#else
// system("RUNDLL32.EXE powrprof.dll,SetSuspendState 0,1,0");
system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0");
Application->MainForm->Close();
#endif
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {
Form1->Height = 195;
Form1->Width = 405;
Form1->Color = clBlack;
Form1->Button_Shutdown->TabOrder = 0;
Form1->Button_Restart->TabOrder = 1;
Form1->Button_LogOff->TabOrder = 2;
Form1->Button_Sleep->TabOrder = 3;
// Position = poScreenCenter;
int horizontal = 0;
int vertical = 0;
GetDesktopResolution(horizontal, vertical);
Form1->Left = horizontal/20;
Form1->Top = vertical - (Form1->Height + (vertical/16));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button_SleepClick(TObject *Sender) {
sleep();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button_LogOffClick(TObject *Sender) {
logoff();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button_ShutdownClick(TObject *Sender) {
shutdown();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button_RestartClick(TObject *Sender) {
restart();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image_ShutdownClick(TObject *Sender) {
shutdown();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image_RestartClick(TObject *Sender) {
restart();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image_LogOffClick(TObject *Sender) {
logoff();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image_SleepClick(TObject *Sender) {
sleep();
}
//---------------------------------------------------------------------------