第四章为程序制作自定义主题

Chapter 4: Tutorials for Using Xtreme Toolkit Pro v13.2 Up | Previous | Next怎样为程序制作自定义主题
你可以为程序制作自定义主题,通过继承toolkit中的任一主题类 。 源代码链接
  1. 通过继承toolkit中的任一可用的主题类,你可以制作自定义主题.

    制作一个类似Visual Studio 6.0的双把手( gripper) 主题.
    1. 新建一个类,派生自 toolkit中的预定义主题. 我们将使用CXTPDefaultTheme; 不过你也可以使用下面任何一个主题类::
      CXTPDefaultTheme 继承Office 2000 风格
      CXTPOfficeTheme继承Office XP 风格
      CXTPOffice2003Theme 继承Office 2003 风格
      CXTPNativeXPTheme 继承本地 XP 风格
      class CDoubleGripperTheme : public CXTPDefaultTheme
      {
          ...
      };
      
    2. 覆盖 CXTPDefaultTheme 基类(查看XTPPaintManager.h)的DrawCommandBarGripper函数.  可以画命令栏把手添加定制外观:
      class CDoubleGripperTheme : public CXTPDefaultTheme
      {
          virtual CSize DrawCommandBarGripper(
              CDC* pDC, CXTPCommandBar* pBar, BOOL bDraw);
      };
      
      // DrawCommandBarGripper函数.
      //  bDraw 为假返回 gripper size.
      //  bDraw 为真,绘制gripper.
      CSize CDoubleGripperTheme::DrawCommandBarGripper(CDC *pDC, CXTPCommandBar *pBar, BOOL bDraw)
      {
        // If 工具栏垂直停靠    
        if (pBar->GetPosition() == xtpBarRight ||        
            pBar->GetPosition() == xtpBarLeft)    
        {        
          if (bDraw)        
          {            
              CXTPClientRect rc(pBar);            
              Draw3dRect(pDC, CRect(3, 3, rc.right - 3, 6),                
                     COLOR_BTNHILIGHT, COLOR_3DSHADOW);            
              Draw3dRect(pDC, CRect(3, 7, rc.right - 3, 10),                
                     COLOR_BTNHILIGHT, COLOR_3DSHADOW);        
          }        
          return CSize(0, 10);    
        }    
        // if 工具栏水平停靠    
        elseif (pBar->GetPosition() == xtpBarTop ||
               pBar->GetPosition() == xtpBarBottom)
        {
          CXTPClientRect rc(pBar);
          if (bDraw)
          {
              Draw3dRect(pDC, CRect(3, 3, 6, rc.bottom - 3),COLOR_BTNHILIGHT, COLOR_3DSHADOW);
              Draw3dRect(pDC, CRect(7, 3, 10, rc.bottom - 3),COLOR_BTNHILIGHT, COLOR_3DSHADOW);
          }
          return CSize(10, 0);
        }
        else 
        return CXTPDefaultTheme::DrawCommandBarGripper(pDC, pBar, bDraw);
      }
      											
      
    3. 在CMainFrame::OnCreate()方法中调用 CXTPPaintManager::SetCustomTheme 使用我们刚创建的主题风格:
      int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
      {
          ...
      
          //使用自己的主题风格绘制命令栏grippers.
          CXTPPaintManager::SetCustomTheme(new CDoubleGripperTheme());
          return 0;
      }
      
      展示自定义主题风格的MDI 示例程序...
      ****************************************************************************************************************************************

                          OfficeXP风格程序对比(译者加),左边是连续三个点

                                   

                           *****************************************************************************************************************************************

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------

原文
  1. Create a new class derived from one of the predefiend themes found in the toolkit. We are going to useCXTPDefaultTheme; however you can use any of the following theme classes:
    CXTPDefaultTheme to inherit Office 2000 theme
    CXTPOfficeTheme to inherit Office XP theme
    CXTPOffice2003Theme to inherit Office 2003 theme
    CXTPNativeXPTheme to inherit Native XP theme
    class CDoubleGripperTheme : public CXTPDefaultTheme
    {
        ...
    };
    
  2. Override the DrawCommandBarGripper ofCXTPDefaultTheme base class (SeeXTPPaintManager.h). This will allow us to add our own custom look for drawing the command bar grippers:
    class CDoubleGripperTheme : public CXTPDefaultTheme
    {
        virtual CSize DrawCommandBarGripper(
            CDC* pDC, CXTPCommandBar* pBar, BOOL bDraw);
    };
    
    // DrawCommandBarGripper function.
    // if bDraw if FALSE must return gripper size.
    // if bDraw is TRUE must draw gripper.
    CSize CDoubleGripperTheme::DrawCommandBarGripper(CDC* pDC,
        CXTPCommandBar* pBar, BOOL bDraw)
    {
        // If Toolbar is vertical docked
        if (pBar->GetPosition() == xtpBarRight ||
            pBar->GetPosition() == xtpBarLeft)
        {
            if (bDraw)
            {
                CXTPClientRect rc(pBar);
                Draw3dRect(pDC, CRect(3, 3, rc.right - 3, 6),
                    COLOR_BTNHILIGHT, COLOR_3DSHADOW);
                Draw3dRect(pDC, CRect(3, 7, rc.right - 3, 10),
                    COLOR_BTNHILIGHT, COLOR_3DSHADOW);
            }
            return CSize(0, 10);
        }
        // if Toolbar is horizontal  docked
        else
        if (pBar->GetPosition() == xtpBarTop ||
            pBar->GetPosition() == xtpBarBottom)
        {
            CXTPClientRect rc(pBar);
            if (bDraw)
            {
                Draw3dRect(pDC, CRect(3, 3, 6, rc.bottom - 3),
                    COLOR_BTNHILIGHT, COLOR_3DSHADOW);
                Draw3dRect(pDC, CRect(7, 3, 10, rc.bottom - 3),
                    COLOR_BTNHILIGHT, COLOR_3DSHADOW);
            }
            return CSize(10, 0);
        }
        else return CXTPDefaultTheme::DrawCommandBarGripper(pDC, pBar, bDraw);
    }
    

  3. Call CXTPPaintManager::SetCustomTheme fromCMainFrame::OnCreate() method to use the theme we just created:
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        ...
    
        // Use our own theme for drawing command bar grippers.
        CXTPPaintManager::SetCustomTheme(new CDoubleGripperTheme());
    
        return 0;
    }
    
    MDI Sample Application Showing Custom Theme...
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值