Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2086965
  • 博文数量: 909
  • 博客积分: 4000
  • 博客等级: 上校
  • 技术积分: 12260
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-06 20:50
文章分类

全部博文(909)

文章存档

2008年(909)

我的朋友

分类:

2008-05-06 22:11:48

一起学习
如何对 BCGControlBarPro 进行换肤

作者:阙海忠

  • 下载 BCGPro6.4:(该版本是 BCGControlBar Professional v6.40 Retail 专业零售版,官方发布日期是2003-04-28)
  • 下载可执行文件:(Release, Skin Dll, BCG Dll)
  • 下载源代码

效果图



图一

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

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

  本人使用Skin 库(),在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();

    .......

}

下载本文示例代码


如何对 BCGControlBarPro 进行换肤如何对 BCGControlBarPro 进行换肤如何对 BCGControlBarPro 进行换肤如何对 BCGControlBarPro 进行换肤如何对 BCGControlBarPro 进行换肤如何对 BCGControlBarPro 进行换肤如何对 BCGControlBarPro 进行换肤如何对 BCGControlBarPro 进行换肤如何对 BCGControlBarPro 进行换肤如何对 BCGControlBarPro 进行换肤如何对 BCGControlBarPro 进行换肤如何对 BCGControlBarPro 进行换肤
阅读(601) | 评论(0) | 转发(0) |
0

上一篇:显示波形的控件

下一篇:{End bracket}专栏...

给主人留下些什么吧!~~