OnExitButton、OnDestroy、OnTimer、OnDrawButton。int m_Radius, m_direction;。OnInitDialog 設定定時器(50ms)、初始半徑 50、方向 1、啟動顏色對話框預設值。OnTimer 更新半徑(10~100 間往復)、呼叫 Invalidate 觸發重繪。OnPaint 使用 CPen 繪製橢圓,顏色由顏色對話框決定。OnDestroy 關閉定時器。// OnInitDialog
SetTimer(1, 50, NULL);
m_Radius = 50; m_direction = 1;
// OnTimer
m_Radius += m_direction;
if (m_Radius >= 100) m_direction = -1;
if (m_Radius <= 10) m_direction = 1;
Invalidate();
// OnPaint
CPaintDC dc(this);
CPen pen(PS_SOLID, 10, dlg.m_color); // 寬度 10
CPen* pOld = dc.SelectObject(&pen);
CRect rc(30, 10, 20 + m_Radius*2, 10 + m_Radius*2);
dc.Ellipse(&rc);
dc.SelectObject(pOld);
CMemDC)消除閃爍。本範例展示 MFC 定時器驅動動畫的基本模式,適合初學者理解訊息迴繪圖流程。