wince_btn 建造者

#pragma once
#include "LAYOUT_BTN_INFO.h"
#include <vector>
#include "..//..//SourceWinCE600//MFC_UI//ButtonEx//UniBtnEx.h"
#include "..//..//SourceWinCE600//SdeFont//SdeFontEx.h"
#include "..//..//SourceWinCE600//MFC_2D.h"


using namespace std;

class BuildBtns
{
public:
 BuildBtns();
 virtual ~BuildBtns(void){ UnInit(); }
 int Init(const BTN_INFO btnInfo[], int iStart, int iEnd,
  CDC* pDC, CRect rtSrc);
 void UnInit();
 static void Build_AButton(CUniBtnEx& o_btnDest, const HRGN hRgn,
  CWnd* pParentWnd,int nID,int nImgID);

 static bool drawText(CDC* i_pCDC, CString strText, CRect rtDest,
  CSize sizeText, COLORREF cls, UINT uSign);

private:
 struct BMPS
 {
  CPoint objPoint;
  CSize objSize;
  BMPS()
  {
   bmp[0] = bmp[1] = NULL;
  }
  CBitmap* bmp[2];
 };
 static vector<BMPS> m_vtBMPS;
};


extern BuildBtns g_BuildBtnser;

 

//////////////////////////////////////////////////////////////////////////////////////////////

 

 

#include "StdAfx.h"
#include "BuildBtns.h"
#include "..//..//SourceWinCE600//MFC_2D.h"
#include "..//..//SourceWinCE600//COM_IMAGE.h"

 

BuildBtns g_BuildBtnser;

vector<BuildBtns::BMPS> BuildBtns::m_vtBMPS;

static bool DEBUG_IS_PRODUCE = true;


BuildBtns::BuildBtns()
{
}

bool BuildBtns::drawText(CDC* i_pCDC, CString strText, CRect rtDest,
       CSize sizeText, COLORREF cls, UINT uSign)
{
 if( NULL == i_pCDC)
  return false;
 CSdeFontEx::SetEvent(true);
 CSdeFontEx::SetTextColor(cls);
 CSdeFontEx::SetFontSize(sizeText.cx,sizeText.cy);
 CSdeFontEx::DrawText(i_pCDC,strText,&rtDest,uSign);
 CSdeFontEx::PrevFontSize();
 CSdeFontEx::PrevTextColor();
 CSdeFontEx::SetEvent(false);
 return true;
}

int BuildBtns::Init(const BTN_INFO btnInfo[], int iStart, int iEnd,
     CDC* pDC, CRect rtSrc)
{
 if( DEBUG_IS_PRODUCE)
 {
  if( NULL == pDC)
   return 0;
  CDCEx* pcdcBk = NULL;
  CDCEx* pImgDC = NULL;

  try
  {
   pcdcBk = new CDCEx(CSize(rtSrc.Width(),rtSrc.Height()),pDC, rtSrc);
  }
  catch (std::exception *e)
  {
   pcdcBk = NULL;
   return 0;
  }


  for(int i=iStart; i<iEnd; i++)
  {
   //大背景
   pcdcBk->drawImg(btnInfo[i].strSrcPath[0],&rtSrc,NULL);

   BMPS btnBmp;
   btnBmp.objPoint = btnInfo[i].point;
   btnBmp.objSize = btnInfo[i].csSrc;
   CRect rtBtnDest(0,0,btnBmp.objSize.cx,btnBmp.objSize.cy);
   CRect rtBtnSrc(btnBmp.objPoint.x,btnBmp.objPoint.y,
     btnBmp.objPoint.x+btnBmp.objSize.cx,
     btnBmp.objPoint.y+btnBmp.objSize.cy);
   
   //小背景
   pImgDC = NULL;
   try
   {
    pImgDC = new CDCEx(CSize(btnBmp.objSize.cx,btnBmp.objSize.cy),pDC, rtBtnDest);
   }
   catch (std::exception *e)
   {
    pImgDC = NULL;
    return 0;
   }

   if( NULL != pImgDC)
   {
    //BtnBackground
    ((CDC*)*pImgDC)->StretchBlt(
     rtBtnDest.left,rtBtnDest.top,rtBtnDest.Width(),rtBtnDest.Height(),
     (CDC*)*pcdcBk,
     rtBtnSrc.left,rtBtnSrc.top,rtBtnSrc.Width(),rtBtnSrc.Height(),
     SRCCOPY);

    //BtnImg
    CBitmap* pbmpBk = NULL;
    pbmpBk = pImgDC->save(CSize(btnBmp.objSize.cx,btnBmp.objSize.cy),rtBtnDest);
    if( NULL != pbmpBk)
    {
     for(int j=0; j<2; j++)
     {
      pImgDC->draw(rtBtnDest,pbmpBk,rtBtnDest);
      pImgDC->drawImg(btnInfo[i].strSrcPath[j+1]);
      btnBmp.bmp[j] = pImgDC->save(CSize(rtBtnSrc.Width(),rtBtnSrc.Height()),CRect(0,0,rtBtnSrc.Width(),rtBtnSrc.Height()));
     }
     delete pbmpBk;
     pbmpBk = NULL;
    }

    delete pImgDC;
    pImgDC = NULL;
   }

   m_vtBMPS.push_back(btnBmp);
  }

  delete pcdcBk;
  pcdcBk = NULL;

  return m_vtBMPS.size();
 }
 else
 {
  for(int i=iStart; i<iEnd; i++)
  {
   BMPS btnBmp;
   btnBmp.objPoint = btnInfo[i].point;
   btnBmp.objSize = btnInfo[i].csSrc;
   CRect rtBtnDest(0,0,btnBmp.objSize.cx,btnBmp.objSize.cy);
   CRect rtBtnSrc(btnBmp.objPoint.x,btnBmp.objPoint.y,
     btnBmp.objPoint.x+btnBmp.objSize.cx,
     btnBmp.objPoint.y+btnBmp.objSize.cy);
   m_vtBMPS.push_back(btnBmp);
  }

  return m_vtBMPS.size();
 }
}

void BuildBtns::UnInit()
{
 if( DEBUG_IS_PRODUCE)
 {
  for(int i=0; i<m_vtBMPS.size(); i++)
  {
   delete m_vtBMPS[i].bmp[0];
   delete m_vtBMPS[i].bmp[1];
  }
 }
 else
 {
  NULL;
 }
}

void BuildBtns::Build_AButton(CUniBtnEx& o_btnDest, const HRGN hRgn,
         CWnd* pParentWnd, int nID, int nImgID)
{
 if( DEBUG_IS_PRODUCE)
 {
  o_btnDest.Create(m_vtBMPS[nImgID].objPoint,
   hRgn, pParentWnd, nID,0,
   L"",
   m_vtBMPS[nImgID].bmp[0],
   m_vtBMPS[nImgID].bmp[1],
   m_vtBMPS[nImgID].bmp[0],
   m_vtBMPS[nImgID].bmp[0]
   );
 }
 else
 {
  o_btnDest.Create(m_vtBMPS[nImgID].objPoint,
   hRgn, pParentWnd, nID,0,
   L"",
   RGB(255,0,0),
   RGB(0,255,0),
   RGB(0,0,255),
   RGB(192,192,192)
  );
 }
}

你可能感兴趣的:(wince_btn 建造者)