基於 MFC 實現圓環狀進度條(類似圖示效果),標準 CProgressCtrl 僅支持矩形,需自繪。
Picture Control (ID: IDC_PIC_PROGRESS),類型設為 Owner DrawCStatic m_picProgress; (DDX_Control)WM_PAINT 中使用 GDI+ 繪製背景圓環 + 進度扇形void CMyDlg::OnPaint() {
CPaintDC dc(this);
CRect rect;
m_picProgress.GetClientRect(&rect);
m_picProgress.ClientToScreen(&rect);
ScreenToClient(&rect);
Graphics g(dc.m_hDC);
g.SetSmoothingMode(SmoothingModeAntiAlias);
Pen penBg(Color(200,200,200), 10); // 背景圓環
Pen penFg(Color(0,180,0), 10); // 進度顏色
penFg.SetStartCap(LineCapRoundAnchor);
penFg.SetEndCap(LineCapRoundAnchor);
RectF bounds(rect.left, rect.top, rect.Width(), rect.Height());
g.DrawEllipse(&penBg, bounds); // 畫背景圓
float sweepAngle = progress * 3.6f; // 0-100 -> 0-360°
g.DrawArc(&penFg, bounds, -90, sweepAngle); // 畫進度弧 (-90° 從頂部開始)
}
void CMyDlg::OnTimer(UINT_PTR nIDEvent) {
if (nIDEvent == TIMER_PROGRESS) {
if (progress >= 100) KillTimer(TIMER_PROGRESS);
else { progress += 2; m_picProgress.Invalidate(); } // 觸發重繪
}
CDialogEx::OnTimer(nIDEvent);
}
m_picProgress.Invalidate() 避免整個對話框閃爍Graphics 內部雙緩衝,無需手動兼容 DC繼承 CProgressCtrl 重繪同樣可行,但 Picture Control + GDI+ 更靈活,易實現漸變、圓角、動畫等高級效果。