win32_step_16 - 8BitsCoding/RobotMentor GitHub Wiki


int g_pos[2] = { 0, };

void CALLBACK MyMoveTimer(HWND hWnd, UINT nMsg, UINT_PTR nIDEvent, DWORD dwTime)
{
	g_pos[0]++;
    g_pos[0] = g_pos[0]++%300;
	//if (g_pos[0] >= 300) g_pos[0] = 0;		// ์ผ์ • ๋ฒ”์œ„ ์ด์ƒ ๋„˜์–ด๊ฐ€๋ฉด ์›์ ๋ณต๊ท€
	InvalidateRect(hWnd, NULL, TRUE);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	if (uMsg == WM_PAINT) {
		PAINTSTRUCT ps;
		HDC h_dc = BeginPaint(hWnd, &ps);

		Ellipse(h_dc, g_pos[0], 10, 100 + g_pos[0], 110);
		Ellipse(h_dc, g_pos[1], 100, 100 + g_pos[1], 210);

		EndPaint(hWnd, &ps);
		return 0;
	}
	else if (uMsg == WM_CREATE) {
		SetTimer(hWnd, 1, 500, MyMoveTimer);
		SetTimer(hWnd, 2, 200, NULL);		// WM_TIMER๋ฅผ ํ˜ธ์ถœํ•ด์ค€๋‹ค.
		return 0;
	}
	else if (uMsg == WM_TIMER) {
		if (wParam == 2) {
			g_pos[1]++;
			InvalidateRect(hWnd, NULL, TRUE);
		}
	}
	else if (uMsg == WM_DESTROY) {
		KillTimer(hWnd, 1);
		KillTimer(hWnd, 2);
		PostQuitMessage(0);
	}
		

	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}