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
149
150
| #include "windows.h"
LRESULT CALLBACK WindowProc(
HWND,
UINT,
WPARAM,
LPARAM);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wc = {0};
wc.style = CS_HREDRAW|CS_VREDRAW;
wc.hInstance = hInstance;
wc.lpszClassName = "Classretertert";
wc.lpfnWndProc = WindowProc;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
if (0 == RegisterClass(&wc))
return 0;
HWND hwndmain = CreateWindow(
wc.lpszClassName,
"Window1",
WS_OVERLAPPEDWINDOW,
100,
100,
600,
600,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwndmain, nCmdShow);
UpdateWindow(hwndmain);
MSG Msg;
while (GetMessage(&Msg, 0,0,0))
DispatchMessage(&Msg);
return 0;
}
LRESULT CALLBACK WindowProc(
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch (uMsg) {
case WM_SIZE:{
InvalidateRect(hWnd,NULL,TRUE);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
hdc=BeginPaint(hWnd,&ps);
GetClientRect(hWnd,&rect);
LONG xCenter = rect.right/2;
LONG yCenter = rect.bottom/2;
Rectangle(hdc, rect.left, yCenter, rect.right, yCenter + 2);
Rectangle(hdc, xCenter, rect.top, xCenter + 1, rect.bottom);
}
InvalidateRect(hWnd,0,FALSE);
return 0;
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_NCMOUSEMOVE
WPARAM wParam, // hit-test value
LPARAM lParam // cursor position
);
case WM_MOUSEMOVE:{
HDC hdc;
POINT ptCursor;
char szMsg[128];
RECT rect;
GetClientRect(hWnd,&rect);
LONG xCenter = rect.right/2;
LONG yCenter = rect.bottom/2;
hdc=GetDC(hWnd);
GetCursorPos(&ptCursor);
ScreenToClient(hWnd,&ptCursor);
if (ptCursor.x<xCenter && ptCursor.y<yCenter){
SelectObject(hdc, CreateSolidBrush(RGB(255, 40, 140)));
Rectangle(hdc, rect.left, rect.top, xCenter, yCenter);}
else {SelectObject(hdc, CreateSolidBrush(RGB(255, 255, 255)));
Rectangle(hdc, rect.left, rect.top, xCenter, yCenter);}
if (ptCursor.x<rect.right && ptCursor.y<yCenter && ptCursor.x>xCenter){
SelectObject(hdc, CreateSolidBrush(RGB(255, 40, 140)));
Rectangle(hdc, xCenter + 1, rect.top, rect.right, yCenter);}
else {SelectObject(hdc, CreateSolidBrush(RGB(255, 255, 255)));
Rectangle(hdc, xCenter + 1, rect.top, rect.right, yCenter);}
if (ptCursor.x<xCenter && ptCursor.y<rect.bottom && ptCursor.y>yCenter){
SelectObject(hdc, CreateSolidBrush(RGB(255, 40, 140)));
Rectangle(hdc, rect.left, yCenter + 1, xCenter, rect.bottom);}
else {SelectObject(hdc, CreateSolidBrush(RGB(255, 255, 255)));
Rectangle(hdc, rect.left, yCenter + 1, xCenter, rect.bottom);}
if (ptCursor.x>xCenter && ptCursor.y>yCenter && ptCursor.x<rect.right && ptCursor.y<rect.bottom){
SelectObject(hdc, CreateSolidBrush(RGB(255, 40, 140)));
Rectangle(hdc, xCenter + 1, yCenter + 1, rect.right, rect.bottom);}
else {SelectObject(hdc, CreateSolidBrush(RGB(255, 255, 255)));
Rectangle(hdc, xCenter + 1, yCenter + 1, rect.right, rect.bottom);}
ReleaseDC(hWnd,hdc);
return 0;
}
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
} |