Windows GDI 提供 CDC、CPen、CBrush 等類,在 OnPaint 或定時器觸發的 Invalidate 中繪製波形點。
OnPaint 處理。SetTimer(1, 50, NULL))每 50ms 觸發 OnTimer 更新相位並 Invalidate()。OnPaint 中:CPaintDC dc(this);
CRect rect; GetClientRect(&rect);
int midY = rect.Height() / 2;
CPen pen(PS_SOLID, 1, RGB(0,255,0));
CPen *old = dc.SelectObject(&pen);
dc.MoveTo(0, midY);
for (int x = 0; x < rect.Width(); ++x) {
double rad = (x * 0.05 + phase) * 3.14159 / 180;
int y = midY - (int)(sin(rad) * 100);
dc.LineTo(x, y);
}
dc.SelectObject(old);BitBlt 到屏幕 DC,消除閃爍。