首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> VC >> 關於VC++

VC 視窗加入 3D 邊框控件 C3DBar

     編輯:關於VC++

C3DBar 類別介面

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);

使用步驟

  1. 將 3DBar.h/.cpp 加入專案。
  2. 於需使用的類別(如 CDigiStatic)包含標頭、宣告成員 C3DBar m_Bar;。
  3. 初始化呼叫 m_Bar.SetBarColour(...)。
  4. OnPaint 中依需求呼叫 DrawLeft/Right/Top/Bottom。

範例:自訂靜態控件繪製四邊 3D 邊框

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 效果。類別封裝顏色設定與重複繪製邏輯,方便在各類自繪控件中複用。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved