Skip to content

Commit 0b0de46

Browse files
Add files via upload
1 parent 69dd937 commit 0b0de46

File tree

4 files changed

+387
-0
lines changed

4 files changed

+387
-0
lines changed

TestingGUI.cbp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<CodeBlocks_project_file>
3+
<FileVersion major="1" minor="6" />
4+
<Project>
5+
<Option title="TestingGUI" />
6+
<Option pch_mode="2" />
7+
<Option compiler="gcc" />
8+
<Build>
9+
<Target title="Debug">
10+
<Option output="bin/Debug/TestingGUI" prefix_auto="1" extension_auto="1" />
11+
<Option object_output="obj/Debug/" />
12+
<Option type="1" />
13+
<Option compiler="gcc" />
14+
<Compiler>
15+
<Add option="-g" />
16+
</Compiler>
17+
</Target>
18+
<Target title="Release">
19+
<Option output="bin/Release/TestingGUI" prefix_auto="1" extension_auto="1" />
20+
<Option object_output="obj/Release/" />
21+
<Option type="1" />
22+
<Option compiler="gcc" />
23+
<Compiler>
24+
<Add option="-O2" />
25+
</Compiler>
26+
<Linker>
27+
<Add option="-s" />
28+
</Linker>
29+
</Target>
30+
</Build>
31+
<Compiler>
32+
<Add option="-Wall" />
33+
</Compiler>
34+
<Unit filename="main.c">
35+
<Option compilerVar="CC" />
36+
</Unit>
37+
<Extensions>
38+
<lib_finder disable_auto="1" />
39+
</Extensions>
40+
</Project>
41+
</CodeBlocks_project_file>

TestingGUI.depend

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# depslib dependency file v1.0
2+
1668063074 source:c:\users\administrator\desktop\testinggui\main.c
3+
<stdio.h>
4+
<tchar.h>
5+
<windows.h>
6+
<string.h>
7+
<stdio.h>
8+
<pthread.h>
9+
10+
1668346897 source:c:\users\kepin\desktop\testinggui\main.c
11+
<stdio.h>
12+
<tchar.h>
13+
<windows.h>
14+
<string.h>
15+
<limits.h>
16+
<unistd.h>
17+
<stdio.h>
18+
<stdlib.h>
19+
20+
1668415150 source:c:\users\administrator\desktop\autoshutdownproject\testinggui\main.c
21+
<stdio.h>
22+
<tchar.h>
23+
<windows.h>
24+
<string.h>
25+
<limits.h>
26+
<unistd.h>
27+
<stdio.h>
28+
<stdlib.h>
29+
30+
1668430716 source:c:\users\kepin\desktop\autoshutdownproject\testinggui\main.c
31+
<stdio.h>
32+
<tchar.h>
33+
<windows.h>
34+
<string.h>
35+
<limits.h>
36+
<unistd.h>
37+
<stdio.h>
38+
<stdlib.h>
39+
40+
1668521317 source:c:\users\kepin\desktop\autoshutdownproject\autoshutdown\main.c
41+
<stdio.h>
42+
<tchar.h>
43+
<windows.h>
44+
<string.h>
45+
<limits.h>
46+
<unistd.h>
47+
<stdio.h>
48+
<stdlib.h>
49+
50+
1668862621 source:c:\users\dell\desktop\autoshutdownproject\autoshutdown\main.c
51+
<stdio.h>
52+
<tchar.h>
53+
<windows.h>
54+
<string.h>
55+
<limits.h>
56+
<unistd.h>
57+
<stdio.h>
58+
<stdlib.h>
59+

TestingGUI.layout

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<CodeBlocks_layout_file>
3+
<FileVersion major="1" minor="0" />
4+
<ActiveTarget name="Debug" />
5+
<File name="main.c" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0">
6+
<Cursor>
7+
<Cursor1 position="6977" topLine="185" />
8+
</Cursor>
9+
</File>
10+
</CodeBlocks_layout_file>

main.c

Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
#if defined(UNICODE) && !defined(_UNICODE)
2+
#define _UNICODE
3+
#elif defined(_UNICODE) && !defined(UNICODE)
4+
#define UNICODE
5+
#endif
6+
7+
#include <stdio.h>
8+
#include <tchar.h>
9+
#include <windows.h>
10+
#include <string.h>
11+
#include <limits.h>
12+
#include <unistd.h>
13+
#include <stdio.h>
14+
#include <stdlib.h>
15+
16+
char usingWhile = 1;
17+
char usingKeyboard = 0;
18+
char UsingTimerShutDown = 0;
19+
char isPressedNo = 0;
20+
char numberTemp[10];
21+
char currentDir[PATH_MAX];
22+
23+
int currentWaktu = 0;
24+
int waktuLimit = 0;
25+
int currentCountDown = 0, currentCountDown2 = 0;
26+
int countDown = 0;
27+
28+
long lastX = 0;
29+
long lastY = 0;
30+
long FilterMousePosX = 0;
31+
long FilterMousePosY = 0;
32+
33+
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
34+
TCHAR szClassName[ ] = _T("AutoShutdown");
35+
HWND tField, buttonYes, buttonNo, mainMessage, mainWindow;
36+
MSG messages, keyMessage;
37+
HHOOK hHook;
38+
DWORD IDThread[3];
39+
POINT mousePoint;
40+
HANDLE HThread[3];
41+
42+
char* myitoa(int num) {
43+
if (numberTemp == NULL) return NULL;
44+
sprintf(numberTemp, "%d", num);
45+
return numberTemp;
46+
}
47+
48+
int getCharTotal(char* varStr, char valChar) {
49+
int res = 0;
50+
for (int a = 0; a < strlen(varStr); a++) if (varStr[a] == valChar) res++;
51+
return res;
52+
}
53+
54+
LRESULT CALLBACK keyboard_hook(const int code, const WPARAM wParam, const LPARAM lParam) {
55+
if (wParam == WM_KEYDOWN) usingKeyboard = 1;
56+
return CallNextHookEx(hHook, code, wParam, lParam);
57+
}
58+
59+
void loadConfig() {
60+
char resultWindowConf[33];
61+
memset(resultWindowConf, 0, 33);
62+
snprintf(resultWindowConf, 33, "%c:/AutoShutdown/AutoShutdown.conf", currentDir[0]);
63+
FILE* fp = fopen(resultWindowConf, "r");
64+
if (!fp) {
65+
waktuLimit = 5;
66+
countDown = 30;
67+
FilterMousePosX = 0;
68+
FilterMousePosY = 0;
69+
}
70+
else {
71+
fseek(fp, 0, SEEK_END);
72+
int fSize = ftell(fp);
73+
fseek(fp, 0, SEEK_SET);
74+
char* fData = malloc(fSize);
75+
fread(fData, fSize, 1, fp);
76+
fclose(fp);
77+
memcpy(&waktuLimit, fData, 4);
78+
memcpy(&countDown, fData + 4, 4);
79+
memcpy(&FilterMousePosX, fData + 8, 4);
80+
memcpy(&FilterMousePosY, fData + 12, 4);
81+
free(fData);
82+
}
83+
}
84+
85+
int WINAPI WinMain (HINSTANCE hThisInstance,
86+
HINSTANCE hPrevInstance,
87+
LPSTR lpszArgument,
88+
int nCmdShow)
89+
{
90+
getcwd(currentDir, PATH_MAX);
91+
if (lpszArgument[0] == '1') {
92+
HWND hWnd = GetConsoleWindow();
93+
ShowWindow( hWnd, SW_HIDE );
94+
95+
WNDCLASSEX wincl; /* Data structure for the windowclass */
96+
97+
wincl.hInstance = hThisInstance;
98+
wincl.lpszClassName = szClassName;
99+
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
100+
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
101+
wincl.cbSize = sizeof (WNDCLASSEX);
102+
103+
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
104+
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
105+
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
106+
wincl.lpszMenuName = NULL; /* No menu */
107+
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
108+
wincl.cbWndExtra = 0; /* structure or the window instance */
109+
wincl.hbrBackground = (HBRUSH)COLOR_WINDOW;
110+
if (!RegisterClassEx (&wincl)) return 0;
111+
RECT rect;
112+
113+
GetClientRect(GetDesktopWindow(), &rect);
114+
rect.left = (rect.right/2) - (330/2);
115+
rect.top = (rect.bottom/2) - (120/2);
116+
117+
mainWindow = CreateWindowEx (0, /* Extended possibilites for variation */
118+
szClassName, /* Classname */
119+
_T("AutoShutdown"), /* Title Text */
120+
WS_BORDER, /* default window */
121+
rect.left, /* Windows decides the position */
122+
rect.top, /* where the window ends up on the screen */
123+
330, /* The programs width */
124+
120, /* and height in pixels */
125+
HWND_DESKTOP, /* The window is a child-window to desktop */
126+
NULL, /* No menu */
127+
hThisInstance, /* Program Instance handler */
128+
NULL /* No Window Creation data */
129+
);
130+
131+
ShowWindow (mainWindow, SW_HIDE);
132+
SetWindowPos(mainWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
133+
while (GetMessage (&messages, NULL, 0, 0)) {
134+
TranslateMessage(&messages);
135+
DispatchMessage(&messages);
136+
}
137+
return messages.wParam;
138+
} else {
139+
printf("[+] AutoShutdown (C) Kevin Adhaikal\n");
140+
printf("\n[+] Jika anda tidak mau menggunakan AutoShutdown, anda bisa mengclose console ini");
141+
printf("\n[+] Jika konsol nya hilang sendiri, berarti aplikasi nya berjalan tanpa ada masalah!\n");
142+
printf("\n[+] AutoShutdown dimulai dalam 5");
143+
Sleep(1000);
144+
printf("\b4");
145+
Sleep(1000);
146+
printf("\b3");
147+
Sleep(1000);
148+
printf("\b2");
149+
Sleep(1000);
150+
printf("\b1");
151+
Sleep(1000);
152+
char* currentDirArr[getCharTotal(currentDir, '\\') + 1];
153+
char* strtokVar = strtok(currentDir, "\\");
154+
int currentDirPos = 0;
155+
while (strtokVar != NULL) {
156+
currentDirArr[currentDirPos++] = strtokVar;
157+
strtokVar = strtok(NULL, "\\");
158+
}
159+
char resultWindowExe[40];
160+
memset(resultWindowExe, 0, 40);
161+
snprintf(resultWindowExe, 40, "start %s/AutoShutdown/AutoShutdown.exe 1", currentDirArr[0]);
162+
system(resultWindowExe);
163+
exit(0);
164+
}
165+
return 0;
166+
}
167+
168+
void keyEvent() {
169+
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_hook, NULL, 0);
170+
while (GetMessage(&keyMessage, NULL, 0, 0));
171+
}
172+
173+
void changeButtonYes() {
174+
isPressedNo = 0;
175+
for (currentCountDown = countDown; currentCountDown > 0; currentCountDown--) {
176+
char strTime[5 + strlen(myitoa(currentCountDown)) + 1];
177+
sprintf(strTime, "Yes (%d)", currentCountDown);
178+
SetWindowText(buttonYes, strTime);
179+
Sleep(1000);
180+
currentCountDown2++;
181+
}
182+
if ((UsingTimerShutDown || currentCountDown2 == countDown) && !isPressedNo) {
183+
currentCountDown2 = 0;
184+
ShowWindow(mainWindow, SW_HIDE);
185+
system("shutdown -s -f -t 0");
186+
} else currentCountDown2 = 0;
187+
}
188+
189+
void runningEvent() {
190+
HThread[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)keyEvent, NULL, 0, &IDThread[0]);
191+
192+
while (usingWhile) {
193+
Sleep(1000);
194+
GetCursorPos(&mousePoint);
195+
196+
if ((mousePoint.x < lastX + FilterMousePosX + 1 && mousePoint.x > lastX - (FilterMousePosX + 1)) && (mousePoint.y < lastY + FilterMousePosY + 1 && mousePoint.y > lastY - (FilterMousePosY + 1))) {
197+
currentWaktu++;
198+
if (currentWaktu > waktuLimit) usingWhile = 0;
199+
} else {
200+
currentWaktu = 0;
201+
usingKeyboard = 0;
202+
}
203+
lastX = mousePoint.x;
204+
lastY = mousePoint.y;
205+
}
206+
207+
usingWhile = 1;
208+
currentWaktu = 0;
209+
210+
PostThreadMessage(IDThread[0], WM_QUIT, 0, 0);
211+
CloseHandle(HThread[0]);
212+
ShowWindow(mainWindow, SW_SHOW);
213+
214+
HThread[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)changeButtonYes, NULL, 0, &IDThread[1]);
215+
}
216+
217+
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
218+
switch (message) {
219+
case WM_CREATE: {
220+
tField = CreateWindow("STATIC",
221+
"Apakah komputer ini mau di matikan sekarang",
222+
WS_VISIBLE | WS_CHILD,
223+
15,5,320,20,
224+
hwnd, NULL, NULL, NULL);
225+
226+
buttonYes = CreateWindow("BUTTON",
227+
"Yes",
228+
WS_VISIBLE | WS_CHILD | WS_BORDER,
229+
200, 40, 100, 40,
230+
hwnd, (HMENU)1, NULL, NULL);
231+
232+
buttonNo = CreateWindow("BUTTON",
233+
"No",
234+
WS_VISIBLE | WS_CHILD | WS_BORDER,
235+
20, 40, 100, 40,
236+
hwnd, (HMENU)2, NULL, NULL);
237+
loadConfig();
238+
HThread[2] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)runningEvent, NULL, 0, &IDThread[2]);
239+
break;
240+
}
241+
case WM_COMMAND: {
242+
switch(LOWORD(wParam)) {
243+
case 1: {
244+
UsingTimerShutDown = 1;
245+
currentCountDown = 0;
246+
ShowWindow(mainWindow, SW_HIDE);
247+
break;
248+
}
249+
case 2: {
250+
UsingTimerShutDown = 0;
251+
currentCountDown = 0;
252+
isPressedNo = 1;
253+
CloseHandle(HThread[1]);
254+
CloseHandle(HThread[2]);
255+
ShowWindow(mainWindow, SW_HIDE);
256+
HThread[2] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)runningEvent, NULL, 0, &IDThread[2]);
257+
break;
258+
}
259+
default: {
260+
break;
261+
}
262+
}
263+
break;
264+
}
265+
case WM_DESTROY: {
266+
PostQuitMessage(0);
267+
break;
268+
}
269+
case WM_CLOSE: {
270+
break;
271+
}
272+
default: {
273+
return DefWindowProc (hwnd, message, wParam, lParam);
274+
}
275+
}
276+
return 0;
277+
}

0 commit comments

Comments
 (0)