-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStayAwake.c
More file actions
114 lines (96 loc) · 2.57 KB
/
StayAwake.c
File metadata and controls
114 lines (96 loc) · 2.57 KB
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
#include <windows.h>
#include <shellapi.h>
#include <stdlib.h>
#include <time.h>
#define WM_TRAYICON (WM_USER + 1)
NOTIFYICONDATA nid;
HMENU hMenu;
HWND hwnd;
HINSTANCE hInst;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (msg == WM_TRAYICON)
{
if (lParam == WM_RBUTTONUP)
{
POINT pt;
GetCursorPos(&pt);
SetForegroundWindow(hwnd);
TrackPopupMenu(hMenu, TPM_BOTTOMALIGN, pt.x, pt.y, 0, hwnd, NULL);
}
}
else if (msg == WM_COMMAND)
{
if (LOWORD(wParam) == 1)
{
Shell_NotifyIcon(NIM_DELETE, &nid);
PostQuitMessage(0);
}
}
else if (msg == WM_DESTROY)
{
Shell_NotifyIcon(NIM_DELETE, &nid);
PostQuitMessage(0);
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
void MoveMouseMinimal()
{
INPUT input = {0};
input.type = INPUT_MOUSE;
input.mi.dx = 5;
input.mi.dwFlags = MOUSEEVENTF_MOVE;
SendInput(1, &input, sizeof(INPUT));
Sleep(100);
input.mi.dx = -5;
SendInput(1, &input, sizeof(INPUT));
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
HANDLE hMutex = CreateMutex(NULL, TRUE, "TeamsHelperSingleInstance");
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
return 0;
}
hInst = hInstance;
srand((unsigned)time(NULL));
WNDCLASS wc = {0};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = "TeamsHelperClass";
RegisterClass(&wc);
hwnd = CreateWindow("TeamsHelperClass", "Hidden Window",
0, 0, 0, 0, 0,
HWND_MESSAGE, NULL, hInstance, NULL);
ZeroMemory(&nid, sizeof(nid));
nid.cbSize = sizeof(nid);
nid.hWnd = hwnd;
nid.uID = 1;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_TRAYICON;
nid.hIcon = (HICON)LoadImage(hInst, "logo.ico",
IMAGE_ICON, 64, 64, LR_LOADFROMFILE);
lstrcpy(nid.szTip, "TeamsHelper");
Shell_NotifyIcon(NIM_ADD, &nid);
hMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING, 1, "Exit");
MoveMouseMinimal();
int delay = 240 + (rand() % 46);
SetTimer(hwnd, 1, delay * 1000, NULL);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
if (msg.message == WM_TIMER)
{
MoveMouseMinimal();
int next = 240 + (rand() % 46);
SetTimer(hwnd, 1, next * 1000, NULL);
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
ReleaseMutex(hMutex);
CloseHandle(hMutex);
return 0;
}