源碼
這個(gè)類(lèi)的使用方法很簡(jiǎn)單,3DBbar中一共有7個(gè)public函數(shù)。分別為:
void SetBarColour(COLORREF cr);
void DrawHorizontal(CDC* pDC, CRect& BarRect); //畫(huà)水平bar
void DrawVertical(CDC*pDC,CRect& BarRect); //畫(huà)垂直bar
void DrawLeft(CDC*pDC,CRectleftRect); //畫(huà)左邊bar
void DrawRight(CDC*pDC,CRectrightRect); //畫(huà)右邊bar
void DrawTop(CDC*pDC,CRect&topRect); //畫(huà)頂邊bar
void DrawBottom(CDC*pDC,CRect&bottomRect); //畫(huà)底邊bar
從以上我們也可以看到,其實(shí)我們?cè)谟玫臅r(shí)候一般用的是SetBarColour(COLORREF cr)、 DrawLeft、DrawRight、DrawTop和DrawBottom這5個(gè)函數(shù),用法也很簡(jiǎn)單。如:我們?cè)谝粋€(gè)自定義的Static CDigiStatic中使用??梢苑譃橐韵聨撞剑?
1、首先把3DBar.h 和3DBar.cpp 加入到你的工程中。
2、在你使用的類(lèi)中加入頭文件,#include "3dbar.h"
3、申明一個(gè)C3DBar對(duì)象。C3DBar Bar;
4、在類(lèi)的初始化中調(diào)用Bar的函數(shù):SetBarColour;
5、在你使用的類(lèi)的OnPaint();函數(shù)中調(diào)用前面介紹的4個(gè)函數(shù)就可以了。
例如: void CDigiStatic::OnPaint()
{
CRect dlgrect;
GetClientRect(dlgrect);
CRect rectleft(0,0,dlgrect.Width()/30,dlgrect.bottom),\
rectright(dlgrect.right-dlgrect.Width()/30,0,dlgrect.right,dlgrect.bottom),\
recttop(0,0,dlgrect.right,dlgrect.Width()/30),\
rectbottom(0,dlgrect.bottom-dlgrect.Width()/30,dlgrect.right,dlgrect.bottom);
CPaintDC dc(this); // device context for painting
Bar.DrawLeft(&dc,rectleft);
Bar.DrawTop(&dc,recttop);
Bar.DrawBottom(&dc,rectbottom);
Bar.DrawRight(&dc,rectright);
}