WEB开发网
开发学院软件开发VC 如何对BCGControlBarPro进行换肤 阅读

如何对BCGControlBarPro进行换肤

 2010-07-11 20:44:25 来源:WEB开发网   
核心提示:4、工具条图标的透明色问题;从CBCGPToolBar派生一个子类CMyBCGPToolBar,在该子类中覆盖CBCGPToolBar的 virtual void DoPaint(CDC* pDCPaint),如何对BCGControlBarPro进行换肤(2),这里主要处理工具条图标的透明色问题,凡是使用CBCGPT

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();
  .......
}

上一页  1 2 

Tags:如何 BCGControlBarPro 进行

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接