以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 C/C++编程思想 』  (http://bbs.xml.org.cn/list.asp?boardid=61)
----  如何在在窗体中加入3D Bar ?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=61&rootid=&id=87670)


--  作者:葛靖青001
--  发布时间:11/12/2010 3:04:00 PM

--  如何在在窗体中加入3D Bar ?
【转自互联网】
前几天由于编程的需要。要做一个有3D边框的static控件,于是在查考别人做的3DBar的基础上,自己做了一个C3DBar类,现在把它奉献给大家。下面是C3DBar的使用方法。

  这个类的使用方法很简单,3DBbar中一共有7个public函数。分别为:

  void SetBarColour(COLORREF cr);

  void DrawHorizontal(CDC* pDC, CRect& BarRect);    //画水平bar

  void DrawVertical(CDC*pDC,CRect& BarRect);      //画垂直bar

  void DrawLeft(CDC*pDC,CRect&leftRect);        //画左边bar

  void DrawRight(CDC*pDC,CRect&rightRect);       //画右边bar

  void DrawTop(CDC*pDC,CRect&topRect);         //画顶边bar

  void DrawBottom(CDC*pDC,CRect&bottomRect);      //画底边bar

  从以上我们也可以看到,其实我们在用的时候一般用的是SetBarColour(COLORREF cr)、 DrawLeft、DrawRight、DrawTop和DrawBottom这5个函数,用法也很简单。如:我们在一个自定义的Static CDigiStatic中使用。可以分为以下几步:

  1、首先把3DBar.h 和3DBar.cpp 加入到你的工程中。

  2、在你使用的类中加入头文件,#include "3dbar.h"

  3、申明一个C3DBar对象。C3DBar Bar;

  4、在类的初始化中调用Bar的函数:SetBarColour;

  5、在你使用的类的OnPaint();函数中调用前面介绍的4个函数就可以了。

  例如:

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

  }


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
32.227ms