如何对 BCGControlBarPro 进行换肤

2007-11-19 14:14:39
如何对 BCGControlBarPro 进行换肤
 

如何对 BCGControlBarPro 进行换肤 作者:阙海忠

效果图 图一   我们知道使用VC开发大型的应用系统时,都会碰到一个界面设计和风格布局的问题。如果一切都重头开始设计和编写的话,将会是巨大的工作量。在短时间内很难写出一个比较健壮功能强大的界面系统出来。对软件项目进度也带来了不可预测的风险。在这种形势下BCG库就应运而生了。目前BCG可以做出诸如Visual Studio .Net 2003 ,Outlook等大型界面系统。几乎可以满足目前市场上绝大多数管理信息系统的界面要求。在我所看到的很多ERP,GSP等的MIS软件公司,都在采用BCG系统。该库非常稳定和易用。   随着 Mircorsoft WindowsXP 系统的推出,计算机世界已经进入个性化时代。用户对界面系统提出更高一层的要求。尽管BCG本身自带了Skin工程,但那个工程的功能还是非常弱的。主要表现在:

  1. 不能对标题栏,滚动条和 Windows 系统标准的窗口换肤;
  2. 没有丰富的界面元素提供下载。

  本人使用Skin++库(www.uipower.com),在BCG的例子中作了几处改动后,BCG就拥有了动态换肤的功能。   我们在这里以BCGCBDotNetExample为例: 1、Skin头文件的包含在StdAfx.h中包含Skin库的头文件。

		#include "SkinPlusPlus.h"
2、Skin库的加载:
BOOL CBCGCBDotNetExampleApp::InitInstance()
{
	......
	InitializeSkin(_T("XPCorona.ssk"));
	......
}
3、让BCG重新取下系统色:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	..................
	-----------------
	// Create menu bar:
	//-----------------
	if (!m_wndMenuBar.Create (this))
	{
		TRACE0("Failed to create menubar/n");
		return -1; // fail to create
	}
	m_wndMenuBar.SendMessage(WM_SYSCOLORCHANGE,0,0);
	..................
}
4、工具条图标的透明色问题;   从CBCGPToolBar派生一个子类CMyBCGPToolBar,在该子类中覆盖CBCGPToolBar的 virtual void DoPaint(CDC* pDCPaint)。这里主要处理工具条图标的透明色问题。   凡是使用CBCGPToolBar的地方全部替换成CMyBCGPToolBar。这样你的工具条就有了和皮肤一致的皮肤色。而不是Windows的系统色。代码如下:
#ifndef _MYTOOLBAR_H_
#define _MYTOOLBAR_H_

#include "stdafx.h"

class CMyBCGPToolBar : public CBCGPToolBar
{
public:
    virtual void DoPaint(CDC* pDCPaint)
    {
        ASSERT_VALID(this);
        ASSERT_VALID(pDCPaint);

        CRect rectClip;
        pDCPaint->GetClipBox (rectClip);

        BOOL bHorz = GetCurrentAlignment () & CBRS_ORIENT_HORZ ? TRUE : FALSE;

        CRect rectClient;
        GetClientRect (rectClient);

        CDC* pDC = pDCPaint;
        BOOL m_bMemDC = FALSE;
        CDC dcMem;
        CBitmap bmp;
        CBitmap* pOldBmp = NULL;

        if (dcMem.CreateCompatibleDC (pDCPaint) &&
            bmp.CreateCompatibleBitmap (pDCPaint, rectClient.Width (),
            rectClient.Height ()))
        {
            m_bMemDC = TRUE;
            pOldBmp = dcMem.SelectObject (&bmp);
            pDC = &dcMem;

            if ((GetStyle () & TBSTYLE_TRANSPARENT) == 0)
            {
                CBCGPVisualManager::GetInstance ()->OnFillBarBackground (pDC, this,
                    rectClient, rectClip);
            }
        }

        OnFillBackground (pDC);

        pDC->SetTextColor (globalData.clrBtnText);
        pDC->SetBkMode (TRANSPARENT);

        CRect rect;
        GetClientRect(rect);

        if (bHorz)
        {
            rect.bottom = rect.top + GetRowHeight ();
        }
        else
        {
            rect.right = rect.left + GetColumnWidth ();
        }

        CBCGPToolBarImages* pImages = GetImageList 
		    (m_Images, m_ImagesLocked, m_LargeImages, m_LargeImagesLocked);
        CBCGPToolBarImages* pHotImages = pImages;
        CBCGPToolBarImages* pColdImages = GetImageList(m_ColdImages, 
		     m_ColdImagesLocked, m_LargeColdImages,m_LargeColdImagesLocked);
        CBCGPToolBarImages* pDisabledImages = GetImageList(m_DisabledImages,
		     m_DisabledImagesLocked, m_LargeDisabledImages,m_LargeDisabledImagesLocked);
        CBCGPToolBarImages* pMenuImages = !m_bLocked ? 
		    &m_MenuImages : &m_MenuImagesLocked;
        CBCGPToolBarImages* pDisabledMenuImages = !m_bLocked ? 
		    &m_DisabledMenuImages : &m_DisabledMenuImagesLocked;

        BOOL bDrawImages = pImages->IsValid ();

        //globalData.clrBtnFace
        pHotImages->SetTransparentColor(GetDefaultSysColor(COLOR_BTNFACE));

        BOOL bFadeInactiveImages = CBCGPVisualManager::GetInstance ()->IsFadeInactiveImage ();

        CBCGPDrawState ds;
        if (bDrawImages && 
            !pHotImages->PrepareDrawImage (ds, 
            m_bMenuMode ? m_sizeMenuImage : GetImageSize (),
            bFadeInactiveImages))
        {
            return; 
        }

        CFont* pOldFont;
        if (bHorz)
        {
            pOldFont = (CFont*) pDC->SelectObject (&globalData.fontRegular);
        }
        else
        {
            pOldFont = (CFont*) pDC->SelectObject (&globalData.fontVert);
        }

        if (pColdImages->GetCount () > 0)
        {
            CBCGPVisualManager::GetInstance ()->SetFadeInactiveImage (FALSE);
        }

        if (pColdImages->GetCount ())
        {
            CBCGPVisualManager::GetInstance ()->SetFadeInactiveImage (FALSE);
        }

        int iButton = 0;
        for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL; iButton ++)
        {
            CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) m_Buttons.GetNext (pos);
            if (pButton == NULL)
            {
                break;
            }

            ASSERT_VALID (pButton);

            rect = pButton->Rect ();
            CRect rectInter;

            if (pButton->m_nStyle & TBBS_SEPARATOR)
            {
                BOOL bHorzSeparator = bHorz;
                CRect rectSeparator; rectSeparator.SetRectEmpty ();

                OnCalcSeparatorRect (pButton, rectSeparator, bHorz);

                if (pButton->m_bWrap && bHorz)
                {
                    bHorzSeparator = FALSE;
                }

                if (rectInter.IntersectRect (rectSeparator, rectClip) && !pButton->IsHidden())
                {
                    DrawSeparator (pDC, rectSeparator, bHorzSeparator);
                }

                continue;
            }

            if (!rectInter.IntersectRect (rect, rectClip))
            {
                continue;
            }

            BOOL bHighlighted = FALSE;
            BOOL bDisabled = (pButton->m_nStyle & TBBS_DISABLED) && !IsCustomizeMode ();

            if (IsCustomizeMode () && !m_bLocked)
            {
                bHighlighted = FALSE;
            }
            else
            {
                if (m_bMenuMode)
                {
                    bHighlighted = (iButton == m_iHighlighted);
                }
                else
                {
                    bHighlighted = ((iButton == m_iHighlighted ||
                        iButton == m_iButtonCapture) &&
                        (m_iButtonCapture == -1 ||
                        iButton == m_iButtonCapture));
                }
            }

            if (pDC->RectVisible(&rect))
            {
                BOOL bDrawDisabledImages = FALSE;

                if (bDrawImages)
                {
                    CBCGPToolBarImages* pNewImages = NULL;

                    if (pButton->m_bUserButton)
                    {
                        if (pButton->GetImage () >= 0)
                        {
                            pNewImages = m_pUserImages;
                        }
                    }
                    else
                    {
                        if (m_bMenuMode)
                        {
                            if (bDisabled && pDisabledMenuImages->GetCount () > 0)
                            {
                                bDrawDisabledImages = TRUE;
                                pNewImages = pDisabledMenuImages;
                            }
                            else if (pMenuImages->GetCount () > 0)
                            {
                                pNewImages = pMenuImages;
                            }
                            else
                            {
                                bDrawDisabledImages = 
                                    (bDisabled && pDisabledImages->GetCount () > 0);

                                pNewImages = bDrawDisabledImages ? pDisabledImages : pHotImages;
                            }
                        }
                        else // Toolbar mode
                        {
                            bDrawDisabledImages = 
                                (bDisabled && pDisabledImages->GetCount () > 0);

                            pNewImages = bDrawDisabledImages ? pDisabledImages : pHotImages;

                            if (!bHighlighted && !bDrawDisabledImages &&
                                (pButton->m_nStyle & TBBS_PRESSED) == 0 &&
                                pColdImages->GetCount () > 0 &&
                                !pButton->IsDroppedDown ())
                            {
                                pNewImages = pColdImages;
                            }
                        }
                    }

                    if (bDrawImages && pNewImages != pImages && pNewImages != NULL)
                    {
                        pImages->EndDrawImage (ds);

                        pNewImages->SetTransparentColor (globalData.clrBtnFace);

                        pNewImages->PrepareDrawImage (ds,
                            m_bMenuMode ? m_sizeMenuImage : GetImageSize (), bFadeInactiveImages);

                        pImages = pNewImages;
                    }
                }

                DrawButton (pDC, pButton, bDrawImages ? pImages : NULL, 
                    bHighlighted, bDrawDisabledImages);
            }
        }

        //-------------------------------------------------------------
        // Highlight selected button in the toolbar customization mode:
        //-------------------------------------------------------------
        if (m_iSelected >= m_Buttons.GetCount ())
        {
            m_iSelected = -1;
        }

        if (IsCustomizeMode () && m_iSelected >= 0 && !m_bLocked && 
            m_pSelToolbar == this)
        {
            CBCGPToolbarButton* pSelButton = GetButton (m_iSelected);
            ASSERT (pSelButton != NULL);

            if (pSelButton != NULL && pSelButton->CanBeStored ())
            {
                CRect rectDrag1 = pSelButton->Rect ();
                if (pSelButton->GetHwnd () != NULL)
                {
                    rectDrag1.InflateRect (0, 1);
                }

                pDC->Draw3dRect(&rectDrag1, globalData.clrBtnText, globalData.clrBtnText);
                rectDrag1.DeflateRect (1, 1);
                pDC->Draw3dRect(&rectDrag1, globalData.clrBtnText, globalData.clrBtnText);
            }
        }

        if (IsCustomizeMode () && m_iDragIndex >= 0 && !m_bLocked)
        {
            DrawDragMarker (pDC);
        }

        pDC->SelectObject (pOldFont);

        if (bDrawImages)
        {
            pImages->EndDrawImage (ds);
        }

        if (m_bMemDC)
        {
            //--------------------------------------
            // Copy the results to the on-screen DC:
            //-------------------------------------- 
            pDCPaint->BitBlt (rectClip.left, rectClip.top, rectClip.Width(), rectClip.Height(),
                &dcMem, rectClip.left, rectClip.top, SRCCOPY);

            dcMem.SelectObject(pOldBmp);
        }

        CBCGPVisualManager::GetInstance ()->SetFadeInactiveImage (bFadeInactiveImages);
    }
};
#endif //_MYTOOLBAR_H_
5、Skin 库的释放:
int CBCGCBDotNetExampleApp::ExitInstance() 
{
    ExitSkin();
    .......
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
12.0完整版本下载地址: BCGControlBar Library Professional Edition v11.00完整源代码(含帮助文件和VS2008中文向导) 第二部分下载地址:http://download.csdn.net/source/2033250 使用方法: 1、解压至C:\Program Files目录下(解压密码:xiaoqing); 2、双击导入注册表C:\Program Files\BCGSoft\BCGControlBarPro\bcgcontrolbarpro.11.00.reg; 3、运行向导C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBProIntegrationWizard.exe。 与其它不同之处: 1、包含完整的源代码、帮助文件; 2、已经对 BCGPAppWizard2005 中的向导进行汉化,在 Visual Studio 2008 中可使用中文向导 BCGPAppWizard (参考 Visual Studio 2008 原有的中文向导,如果您想学习汉化向导,参考目录是:C:\Program Files\Microsoft Visual Studio 9.0\VC\VCWizards\AppWiz\MFC\Application\templates\2052) 关于静态链接: 1、首先必须在运行向导BCGCBProIntegrationWizard.exe时已经编译静态库; 2、在 Visual Studio 建立项目向导时,选择静态链接即可。 关于使用 Office2007、2010 风格: 如果您使用了这些新风格,必须在项目中包括这些资源,否则 debug 版本启动时会报错(缺少资源,release版本不会提示,但显示不正常),具体有二种方法: 1、直接在“解决方案资源管理器”-“资源文件”中点右键,“添加”-“现有项”,把C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles中所有扩展名为 .rc 的资源包括进来即可。 2、直接在“资源视图”-“您的项目”上点右键,选择“资源包括”,在“资源包括”中的“编译时指令”中的#include "BCGCBPro.rc"后面添加以下代码: #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2007Aqua.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2007Luna.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2007Obsidian.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2007Silver.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2010White.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyleCarbon.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyleScenic.rc" 3、如果使用动态库链接,请手工编译C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\Office2007_styles.sln或者build_all.dsp 仅为学习使用,下载后24小时内删除,请支持 BCGSoft 购买正版,本人不提供技术支持,不对任何负责。 尊重他人劳动成果,欢迎与大家分享成果。
BCGControlBarPro.v12.00完整源代码(含资源汉化帮助文件和VS2008中文向导)第三部分 使用方法: 1、解压至C:\Program Files目录下(密码:xiaoqing); 2、双击导入注册表C:\Program Files\BCGSoft\BCGControlBarPro\bcgcontrolbarpro.12.00.reg; 3、运行向导C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBProIntegrationWizard.exe。 与其它不同之处: 1、包含完整的源代码、帮助文件; 2、已经对 BCGPAppWizard2005 中的向导进行汉化,在 Visual Studio 2008 中可使用中文向导 BCGPAppWizard (参考 Visual Studio 2008 原有的中文向导,如果您想学习汉化向导,参考目录是:C:\Program Files\Microsoft Visual Studio 9.0\VC\VCWizards\AppWiz\MFC\Application\templates\2052) 关于静态链接: 1、首先必须在运行向导BCGCBProIntegrationWizard.exe时已经编译静态库; 2、在 Visual Studio 建立项目向导时,选择静态链接即可。 关于使用 Office2007、2010 风格: 如果您使用了这些新风格,必须在项目中包括这些资源,否则 debug 版本启动时会报错(缺少资源,release版本不会提示,但显示不正常),具体有二种方法: 1、直接在“解决方案资源管理器”-“资源文件”中点右键,“添加”-“现有项”,把C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles中所有扩展名为 .rc 的资源包括进来即可。 2、直接在“资源视图”-“您的项目”上点右键,选择“资源包括”,在“资源包括”中的“编译时指令”中的#include "BCGCBPro.rc"后面添加以下代码: #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2007Aqua.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2007Luna.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2007Obsidian.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2007Silver.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyle2010White.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyleCarbon.rc" #include "C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\BCGPStyleScenic.rc" 3、如果使用动态库链接,请手工编译C:\Program Files\BCGSoft\BCGControlBarPro\BCGCBPro\Styles\Office2007_styles.sln或者build_all.dsp 仅为学习使用,下载后24小时内删除,请支持 BCGSoft 购买正版,本人不提供技术支持,不对任何负责。 尊重他人劳动成果,欢迎与大家分享成果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值