win32_step_14 - 8BitsCoding/RobotMentor GitHub Wiki
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_PAINT) {
PAINTSTRUCT ps;
HDC h_dc = BeginPaint(hWnd, &ps);
for (int i = 0; i < MAX_COUNT; i++) {
Rectangle(h_dc, i * 100, 0, 101 + i * 100, 101);
Rectangle(h_dc, i * 100, 100, 101 + i * 100, 200);
}
// μ€λͺ
μ μν μμ λ€λͺ¨
HGDIOBJ h_old_brush = SelectObject(h_dc, GetStockObject(NULL_BRUSH));
for (int i = 0; i < MAX_COUNT; i++) {
Rectangle(h_dc, i * 100 - 40, 5, 101 + i * 100 - 50, 95);
}
SelectObject(h_dc, GetStockObject(BLACK_BRUSH));
for (int i = 0; i < MAX_COUNT; i++) {
if (g_index[i] == 1) Ellipse(h_dc, i * 100 + 50, 50, 101 + i * 100 + 50, 150);
}
SelectObject(h_dc, h_old_brush);
EndPaint(hWnd, &ps);
return 0;
}
else if (uMsg == WM_LBUTTONDOWN) {
UINT x = LOWORD(lParam);
UINT y = HIWORD(lParam);
if (y >= 0 && y < 100) {
//UINT index = x / 100;
UINT index = (x + 50) / 100;
if (index < MAX_COUNT) {
/*
int remain = x % 100;
if (remain < 50) index++;
*/
g_index[index] = !g_index[index];
InvalidateRect(hWnd, NULL, TRUE);
}
}
}
else if (uMsg == WM_DESTROY) PostQuitMessage(0);
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}