-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmv.cpp
85 lines (72 loc) · 1.83 KB
/
mmv.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
#include <windows.h>
static const UINT IDT_TIMER = 1;
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
int WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
MSG msg;
char appTitle[] = "MMV";
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOWFRAME;
wc.lpszMenuName = NULL;
wc.lpszClassName = appTitle;
if (!RegisterClass(&wc))
return 0;
hwnd = CreateWindow(appTitle, appTitle,
WS_OVERLAPPEDWINDOW | WS_MAXIMIZE,
CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
NULL, NULL, hInst, NULL);
if (!hwnd)
return 0;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg)
{
case WM_PAINT:
PAINTSTRUCT ps;
HDC dc;
RECT r;
GetClientRect(hwnd, &r);
dc = BeginPaint(hwnd, &ps);
DrawText(dc, "Mouse Mover", -1, &r, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hwnd, &ps);
break;
case WM_CREATE:
ShowWindow(hwnd, SW_MAXIMIZE);
SetTimer(hwnd, IDT_TIMER, 10000, NULL);
break;
case WM_TIMER:
POINT pt;
RECT rc;
GetClientRect(hwnd, &rc);
pt.x = rc.left + (rand() % (rc.right - rc.left));
pt.y = rc.top + (rand() % (rc.top - rc.bottom));
ClientToScreen(hwnd, &pt);
SetCursorPos(pt.x, pt.y);
break;
case WM_DESTROY:
KillTimer(hwnd, IDT_TIMER);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
return 0;
}