mfc_timer_advanced - 8BitsCoding/RobotMentor GitHub Wiki

// Dlg.h
#define MAX_COUNT 50
struct CircleData
{
int x, y; // μ€μ¬μ
int r; // λ°μ§λ¦
COLORREF color;
};
void CMFCApplication1Dlg::OnPaint()
{
CPaintDC dc(this); // 그리기λ₯Ό μν λλ°μ΄μ€ 컨ν
μ€νΈμ
λλ€.
if (IsIconic())
{
// ...
}
else
{
CircleData * p = m_list;
CBrush fill_brush, *p_old_brush = dc.GetCurrentBrush;
for (int i = 0; i < MAX_COUNT; i++) {
// dc.Ellipse(m_list[i].x - m_list[i].r, m_list[i].y - m_list[i].r,
// m_list[i].x + m_list[i].r, m_list[i].y + m_list[i].r);
// μ μ°μ°μ μ’ λ κ°λ¨ν
fill_brush.CreateSolidBrush(p->color);
//p_old_brush = dc.SelectObject(&fill_brush);
dc.SelectObject(&fill_brush);
dc.Ellipse(p->x - p->r, p->y - p->r, p->x + p->r, p->y + p->r);
p++;
dc.SelectObject(p_old_brush);
fill_brush.DeleteObject();
}
// CDialogEx::OnPaint();
}
}
void CMFCApplication1Dlg::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == 1) {
CRect r;
GetClientRect(r);
int w = r.Width(), h = r.Height();
CircleData * p = m_list;
for (int i = 0; i < MAX_COUNT; i++) {
p->r--;
if (p->r <= 0) {
p->x = rand() % w;
p->y = rand() % h;
p->r = rand() % 40 + 10; // 10 ~ 49
p->color = RGB(rand() % 256, rand() % 256, rand() % 256);
}
p++;
}
Invalidate();
}
else {
CDialogEx::OnTimer(nIDEvent);
}
}