-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
particle.c
148 lines (131 loc) · 3.71 KB
/
particle.c
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
#include <windows.h>
#include <stdio.h>
#include <time.h>
typedef struct {
HWND hwnd;
int x;
int y;
int dx;
int dy;
} particle;
static particle p[4] = {0};
static HBRUSH hb = NULL;
LRESULT CALLBACK
WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
HDC hdc = NULL;
RECT rc = {0};
PAINTSTRUCT ps;
switch (uMsg) {
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rc);
FillRect(hdc, &rc, hb);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
break;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
void CALLBACK
UpdateProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {
int i;
for (i = 0; i < sizeof(p)/sizeof(p[0]); i++) {
p[i].x += p[i].dx;
p[i].y += p[i].dy;
p[i].dy += 2;
if (p[i].dy >= 30) {
DestroyWindow(p[i].hwnd);
break;
}
SetWindowPos(p[i].hwnd, NULL, p[i].x, p[i].y, 0, 0,
SWP_NOSIZE|SWP_NOZORDER|SWP_NOOWNERZORDER);
}
}
int WINAPI
WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpszCmdLine, int nCmdShow) {
TCHAR app[] = TEXT("particle");
MSG msg;
WNDCLASSEX wc;
int i;
int exit_code = 1;
int argc;
LPWSTR *argv;
int r = 0xff, g = 0xff, b = 0xff;
RECT rc = {0};
POINT pt = {200, 200};
HWND hwnd;
int w = 0, h = 0;
wchar_t *pos = NULL;
HRGN hrgn;
srand((unsigned)time(NULL));
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if (argc >= 2) {
pos = wcschr(argv[1], ',');
if (pos) *pos++ = 0;
hwnd = (HWND) _wtoi64(argv[1]);
}
if (hwnd == NULL) hwnd = GetForegroundWindow();
if (pos && swscanf(pos, L"%d,%d,%d,%d", &pt.x, &pt.y, &w, &h) == 4) {
GetWindowRect(hwnd, &rc);
pt.x = (rc.right - rc.left) / w * pt.x;
pt.y = (rc.bottom - rc.top) / h * pt.y;
ClientToScreen(hwnd, &pt);
} else {
if (GetWindowRect(hwnd, &rc)) {
pt.x = (rc.left + rc.right) / 2 + rand() % 200 - 100;
pt.y = (rc.top + rc.bottom) / 2 + rand() % 200 - 100;
ClientToScreen(hwnd, &pt);
}
}
if (argc >= 3) {
swscanf(argv[2], L"%02x%02x%02x", &r, &g, &b);
} else {
r = rand() % 256;
g = rand() % 256;
b = rand() % 256;
}
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hinst;
wc.hIcon = (HICON)LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED);
wc.hCursor = (HCURSOR)LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = app;
wc.hIconSm = (HICON)LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED);
if (!RegisterClassEx(&wc)) goto leave;
hb = CreateSolidBrush(RGB(r, g, b));
for (i = 0; i < sizeof(p)/sizeof(p[0]); i++) {
p[i].hwnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_LAYERED | WS_EX_NOACTIVATE,
app, app, WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
10, 10, NULL, NULL, hinst, NULL);
if (p[i].hwnd == NULL) goto leave;
SetLayeredWindowAttributes(p[i].hwnd, RGB(0xFF, 0xFF, 0xFF), 70, LWA_ALPHA);
p[i].x = pt.x;
p[i].y = pt.y;
p[i].dx = (rand() % 10) - 5;
p[i].dy = -10 - (rand() % 10);
hrgn = CreateEllipticRgn(0, 0, 10, 10);
if (hrgn != NULL)
SetWindowRgn(p[i].hwnd, hrgn, TRUE);
ShowWindow(p[i].hwnd, nCmdShow);
UpdateWindow(p[i].hwnd);
}
SetTimer(NULL, 0, 1, UpdateProc);
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
exit_code = (int)msg.wParam;
leave:
if (argv) LocalFree(argv);
return exit_code;
}
/* vim:set et sw=2: */