void SetBarColour(COLORREF cr);
void DrawHorizontal(CDC* pDC, CRect& BarRect);
void DrawVertical(CDC* pDC, CRect& BarRect);
void DrawLeft(CDC* pDC, CRect& leftRect);
void DrawRight(CDC* pDC, CRect& rightRect);
void DrawTop(CDC* pDC, CRect& topRect);
void DrawBottom(CDC* pDC, CRect& bottomRect);
3DBar.h/.cpp 加入專案。CDigiStatic)包含標頭、宣告成員 C3DBar m_Bar;。m_Bar.SetBarColour(...)。OnPaint 中依需求呼叫 DrawLeft/Right/Top/Bottom。void CDigiStatic::OnPaint() {
CRect rc; GetClientRect(&rc);
int w = rc.Width()/30; // 邊框寬度
CRect left(0,0,w,rc.bottom), right(rc.right-w,0,rc.right,rc.bottom);
CRect top(0,0,rc.right,w), bottom(0,rc.bottom-w,rc.right,rc.bottom);
CPaintDC dc(this);
m_Bar.DrawLeft(&dc, left);
m_Bar.DrawTop(&dc, top);
m_Bar.DrawRight(&dc, right);
m_Bar.DrawBottom(&dc, bottom);
}
利用 CDC::Draw3dRect 或手動以亮/暗色筆刷繪製矩形四邊,模擬凸出/凹入 3D 效果。類別封裝顏色設定與重複繪製邏輯,方便在各類自繪控件中複用。