win32_step_5 - 8BitsCoding/RobotMentor GitHub Wiki
WM_PAINT๋ก ๋ค์ ๊ทธ๋ฆฌ๋ ๊ธฐ๋ฅ์ ๊ตฌํ
#define MAX_COUNT 1000
int g_is_clicked = 0;
int g_x[MAX_COUNT] = { 0, }, g_y[MAX_COUNT] = { 0, };
int g_count = 0;
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_DESTROY) PostQuitMessage(0);
else if (uMsg == WM_PAINT) {
PAINTSTRUCT ps;
HDC h_dc = BeginPaint(hWnd, &ps);
if(g_count > 0) MoveToEx(h_dc, g_x[0], g_y[0], NULL); // MoveTo์ ์ค๋ณตํธ์ถ์ ๋ง๋๋ค.
for (int i = 1; i < g_count; i++) {
LineTo(h_dc, g_x[i], g_y[i]);
}
EndPaint(hWnd, &ps);
return 0;
}
else if (uMsg == WM_LBUTTONDOWN) {
g_is_clicked = 1;
g_x[g_count] = GET_X_LPARAM(lParam);//
g_y[g_count] = GET_Y_LPARAM(lParam);
g_count++;
}
else if (uMsg == WM_LBUTTONUP) {
g_is_clicked = 0;
}
else if (uMsg == WM_MOUSEMOVE) {
if (g_is_clicked == 1 && g_count <= MAX_COUNT) {
HDC h_dc = GetDC(hWnd);
MoveToEx(h_dc, g_x[g_count-1], g_y[g_count-1], NULL);
g_x[g_count] = GET_X_LPARAM(lParam);//
g_y[g_count] = GET_Y_LPARAM(lParam);
LineTo(h_dc, g_x[g_count], g_y[g_count]);
g_count++;
ReleaseDC(hWnd, h_dc);
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}