-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartup_pet.c
More file actions
126 lines (100 loc) · 3.44 KB
/
startup_pet.c
File metadata and controls
126 lines (100 loc) · 3.44 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
115
116
117
118
119
120
121
122
123
124
125
126
#include <windows.h>
#include <stdlib.h>
#include <time.h>
#define PET_COUNT 5
#define TIMER_ID 1
#define TIMER_INTERVAL 500
typedef struct {
const char *name;
const char *art_open;
const char *art_closed;
} Pet;
Pet pets[PET_COUNT];
Pet currentPet;
int blink = 0;
// Window procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_TIMER:
blink = !blink;
InvalidateRect(hwnd, NULL, TRUE);
return 0;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
RECT rect;
GetClientRect(hwnd, &rect);
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(255, 105, 180)); // cute pink
HFONT hFont = CreateFont(32, 16, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
FF_DONTCARE, TEXT("Consolas"));
SelectObject(hdc, hFont);
const char *art = blink ? currentPet.art_closed : currentPet.art_open;
DrawText(hdc, art, -1, &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP | DT_WORDBREAK);
DeleteObject(hFont);
EndPaint(hwnd, &ps);
return 0;
}
case WM_KEYDOWN:
if (wParam == VK_ESCAPE) DestroyWindow(hwnd); // ESC closes pet
return 0;
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
DestroyWindow(hwnd); // click closes pet
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
// Initialize pets
void initPets() {
srand((unsigned int)time(NULL));
pets[0] = (Pet){"Buddy",
" / \\__\n( o_o )\n / O\nDog",
" / \\__\n( -_- )\n / O\nDog"};
pets[1] = (Pet){"Whiskers",
" |\\---/|\n | o_o |\n \\_^_/\nCat",
" |\\---/|\n | -_- |\n \\_^_/\nCat"};
pets[2] = (Pet){"Bubbles",
" ><(((('>\nFish",
" ><(((('>\nFish"};
pets[3] = (Pet){"Thumper",
" (\\_/)\n (•_•)\n / >🥕\nBunny",
" (\\_/)\n (-_-) \n / >🥕\nBunny"};
pets[4] = (Pet){"Sunny",
" \\_v_/\n (o o)\n ( - )\nParrot",
" \\_v_/\n (- -)\n ( - )\nParrot"};
currentPet = pets[rand() % PET_COUNT];
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) {
initPets();
const char CLASS_NAME[] = "FloatingPet";
WNDCLASS wc = {0};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(
WS_EX_TOPMOST | WS_EX_LAYERED | WS_EX_TOOLWINDOW,
CLASS_NAME,
currentPet.name,
WS_POPUP,
100, 100, 400, 200,
NULL, NULL, hInstance, NULL
);
SetLayeredWindowAttributes(hwnd, 0, 255, LWA_ALPHA);
ShowWindow(hwnd, SW_SHOW);
SetTimer(hwnd, TIMER_ID, TIMER_INTERVAL, NULL);
MSG msg = {0};
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}