Welcome to ErranLi's Blog!

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  106 Posts :: 1 Stories :: 97 Comments :: 0 Trackbacks

常用链接

留言簿(12)

搜索

  •  

积分与排名

  • 积分 - 169360
  • 排名 - 151

最新评论

阅读排行榜

这里实现了对话筐的换肤,测试效果还可以。


///////////////////////////////////////////////////
//
//  CDialogSK : dialog skin
//
//  writer: erran
//
//  time: 2006-03-24
//
///////////////////////////////////////////////////

#i nclude "BaseSK.h"      /// EVC下实现WinCE软件换肤之函数TransparentBitBlt
#i nclude "BitmapSK.h"   /// EVC下实现WinCE软件换肤之换肤基础类CBitmapSK  

class CDialogSK: public CDialog
{

public:
 // constructor and Destructor
 CDialogSK();
 CDialogSK(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL);
 CDialogSK(UINT nIDTemplate, CWnd* pParentWnd = NULL);
 ~CDialogSK();

protected:
 // common constructor
 Constructor(); 
 // Destructor,Release the bitmap
 Destructor();

protected:
 //window title text
 CString m_titleText;

protected:
 //interface bitmap
 CBitmapSK m_bmpLeft;  //dialog border left bitmap
 CBitmapSK m_bmpRight; //dialog border right bitmap
 CBitmapSK m_bmpBottom;//dialog border bottom bitmap
 CBitmapSK m_bmpTitle;   //two bitmap, dlg active and disactive
 CBitmapSK m_bmpTitleBtn;//max min close btn bitmap
 CBitmapSK m_bmpBkDlg; //dialog back ground bitmap
protected:
 //transparent color of bitmap
 COLORREF m_transColorLeft;
 COLORREF m_transColorRight;
 COLORREF m_transColorBottom;
 COLORREF m_transColorTitle;
 COLORREF m_transColorTitleBtn;
 COLORREF m_transColorBackDlg;

protected:

 //window border width and height
 // the border can not more than the border bmp size
 int m_borderLeftWidth;
 int m_borderRightWidth;
 int m_borderBottomHeight;
 int m_titleHeight;
 //offset in the bitmap
 int m_offsetLeft1, m_offsetLeft2;
 int m_offsetRight1, m_offsetRight2;
 int m_offsetBottom1, m_offsetBottom2;
 int m_offsetTitle1, m_offsetTitle2;

public:
 //window style
 BOOL m_titlable;
 BOOL m_sizable;
 BOOL m_minable;
 BOOL m_maxable;
 BOOL m_sysmenu;

 BOOL m_isActive;

public:
 BOOL m_winTransable;

public:
 //msg
 void OnPaint();
 BOOL OnEraseBkgnd(CDC* pDC);

public:
 // draw skin (x,y) is this dialog region
 BOOL DrawRight(CDC *pDC, int x, int y, int height, int state);
 BOOL DrawLeft(CDC *pDC, int x, int y, int height, int state);
 BOOL DrawBottom(CDC *pDC, int x, int y, int width, int state);
 BOOL DrawTitle(CDC *pDC, int x, int y, int width, int state);

 BOOL DrawFrame(CDC *pDC, int x, int y,int width, int height, int state);
 BOOL DrawBkDlg(CDC *pDC, int x, int y,int width, int height, int state); 
 
 BOOL DrawButton( CDC * pDC, int i, int state );

};

 

#i nclude "stdafx.h"
#i nclude "DialogSK.h"

/////////////////////////////////////////////////////////////////////////////
// CDialogSK dialog


CDialogSK::CDialogSK()
:CDialog()
{
}

CDialogSK::CDialogSK(LPCTSTR lpszTemplateName, CWnd* pParentWnd/*= NULL*/)
:CDialog(lpszTemplateName, pParentWnd)
{
}

CDialogSK::CDialogSK(UINT nIDTemplate, CWnd* pParentWnd/*/= NULL*/)
:CDialog(nIDTemplate, pParentWnd)
{
 
}

CDialogSK::~CDialogSK()
{
}

CDialogSK::Constructor()
{
   /*测试用
 m_bmpLeft.LoadBitmapEx(NULL, IDB_LEFT); 
 m_bmpRight.LoadBitmapEx(NULL, IDB_RIGHT);
 m_bmpBottom.LoadBitmapEx(NULL, IDB_BOTTOM);
 m_bmpTitle.LoadBitmapEx(NULL, IDB_TOP); 
  
 m_titleHeight = m_bmpTitle.Height()/2;
 m_borderLeftWidth = m_bmpLeft.Width()/2;
 m_borderRightWidth = m_bmpRight.Width()/2;
 m_borderBottomHeight = m_bmpBottom.Height()/2;

 m_offsetLeft1 = 10;
 m_offsetLeft2 = 10;
 m_offsetRight1 = 10;
 m_offsetRight2 = 10;
 m_offsetBottom1 = 10;
 m_offsetBottom2 = 10;
 m_offsetTitle1 = 10;
 m_offsetTitle2 = 10;
   */

}

CDialogSK::Destructor()
{
}


BOOL CDialogSK::DrawRight(CDC *pDC, int x, int y, int height, int state)

 int bmpwidth, bmpheight;
 m_bmpRight.Size(bmpwidth, bmpheight);

 //bitmap rect
 RECT srctop, srcmid, desmid, srcdown;

 if (state == 0)
 {
  srctop = CRect(0, 0, m_borderRightWidth, m_offsetRight1);
  srcmid = CRect(0, m_offsetRight1, m_borderRightWidth, m_offsetRight2);
  srcdown = CRect(0, m_offsetRight2, m_borderRightWidth, bmpheight);
 }
 else
 {
  srctop = CRect(m_borderRightWidth, 0, bmpwidth, m_offsetRight1);
  srcmid = CRect(m_borderRightWidth, m_offsetRight1, bmpwidth, m_offsetRight2);
  srcdown = CRect(m_borderRightWidth, m_offsetRight2, bmpwidth, bmpheight);
 }

 desmid = CRect(x, y+m_offsetRight1, x+m_borderRightWidth, y+height-bmpheight+m_offsetRight2);

 m_bmpRight.Draw(pDC, x, y, &srctop);
 m_bmpRight.Fill(pDC, &desmid, &srcmid);
 m_bmpRight.Draw(pDC, x, y+height-bmpheight+m_offsetRight2, &srcdown);

 return TRUE;
}

BOOL CDialogSK::DrawLeft(CDC *pDC, int x, int y, int height, int state)

 int bmpwidth, bmpheight;
 m_bmpLeft.Size(bmpwidth, bmpheight);

 //bitmap rect
 RECT srctop, srcmid, desmid, srcdown;

 if (state == 0)
 {
  srctop = CRect(0, 0, m_borderLeftWidth, m_offsetLeft1);
  srcmid = CRect(0, m_offsetLeft1, m_borderLeftWidth, m_offsetLeft2);
  srcdown = CRect(0, m_offsetLeft2, m_borderLeftWidth, bmpheight);
 }
 else
 {
  srctop = CRect(m_borderLeftWidth, 0, bmpwidth, m_offsetRight1);
  srcmid = CRect(m_borderLeftWidth, m_offsetLeft1, bmpwidth, m_offsetLeft2);
  srcdown = CRect(m_borderLeftWidth, m_offsetLeft2, bmpwidth, bmpheight);
 }

 desmid = CRect(x, y+m_offsetLeft1, x+m_borderLeftWidth, y+height-bmpheight+m_offsetLeft2);

 m_bmpLeft.Draw(pDC, x, y, &srctop);
 m_bmpLeft.Fill(pDC, &desmid, &srcmid);
 m_bmpLeft.Draw(pDC, x, y+height-bmpheight+m_offsetLeft2, &srcdown);

 return TRUE;
}

BOOL CDialogSK::DrawBottom(CDC *pDC, int x, int y, int width, int state)
{
 int bmpwidth, bmpheight;
 m_bmpBottom.Size(bmpwidth, bmpheight);

 RECT srcleft, srcmid, desmid, srcright;

 if (state == 0)
 {
  srcleft = CRect(0, 0, m_offsetBottom1, m_borderBottomHeight);
  srcmid = CRect(m_offsetBottom1, 0, m_offsetBottom2, m_borderBottomHeight);
  srcright = CRect(m_offsetBottom2, 0, bmpwidth, m_borderBottomHeight);
 }
 else
 {
  srcleft = CRect(0, m_borderBottomHeight, m_offsetBottom1, bmpheight);
  srcmid = CRect(m_offsetBottom1, m_borderBottomHeight, m_offsetBottom2, bmpheight);
  srcright = CRect(m_offsetBottom2, m_borderBottomHeight, bmpwidth, bmpheight);
 }
  
 desmid = CRect(x+m_offsetBottom1, y, x+width-bmpwidth+m_offsetBottom2, y+m_borderBottomHeight);

 m_bmpBottom.Draw(pDC, x, y, &srcleft);
 m_bmpBottom.Fill(pDC, &desmid, &srcmid);
 m_bmpBottom.Draw(pDC, x+width-bmpwidth+m_offsetBottom2, y, &srcright);

 return TRUE;
}

BOOL CDialogSK::DrawTitle(CDC *pDC, int x, int y, int width, int state)

 int bmpwidth, bmpheight;
 m_bmpTitle.Size(bmpwidth, bmpheight);

 RECT srcleft, srcmid, desmid, srcright;

 if (state == 0)
 {
  srcleft = CRect(0, 0, m_offsetTitle1, m_titleHeight);
  srcmid = CRect(m_offsetTitle1, 0, m_offsetTitle2, m_titleHeight);
  srcright = CRect(m_offsetTitle2, 0, bmpwidth, m_titleHeight);
 }
 else
 {
  srcleft = CRect(0, m_titleHeight, m_offsetTitle1, bmpheight);
  srcmid = CRect(m_offsetTitle1, m_titleHeight, m_offsetTitle2, bmpheight);
  srcright = CRect(m_offsetTitle2, m_titleHeight, bmpwidth, bmpheight);
 }

 desmid = CRect(x+m_offsetTitle1, y, x+width-bmpwidth+m_offsetTitle2, y+m_titleHeight);

 m_bmpTitle.Draw(pDC, x, y, &srcleft);
 m_bmpTitle.Fill(pDC, &desmid, &srcmid);
 m_bmpTitle.Draw(pDC, x+width-bmpwidth+m_offsetTitle2, y, &srcright);

 return TRUE;
}

BOOL CDialogSK::DrawFrame(CDC *pDC, int x, int y,int width, int height, int state)
{
 DrawTitle(pDC, x+m_borderLeftWidth, y, width-m_borderLeftWidth-m_borderRightWidth, state); 
 DrawLeft(pDC, x, y, height, state);
 DrawRight(pDC, x+width-m_borderRightWidth, y, height, state);
 DrawBottom(pDC, x+m_borderLeftWidth, y+height-m_borderBottomHeight, width-m_borderLeftWidth-m_borderRightWidth, state); 
 
 return TRUE;
}

BOOL CDialogSK::DrawBkDlg(CDC *pDC, int x, int y,int width, int height, int state)
{
 int bmpwidth, bmpheight;
 m_bmpBkDlg.Size(bmpwidth, bmpheight);
  
 RECT des, src;
 des = CRect(x,y, x+width, y+height);
 src = CRect(0, 0, bmpwidth, bmpheight);

 m_bmpBkDlg.Fill(pDC, &des, &src);

 return TRUE;
}

BOOL CDialogSK::OnEraseBkgnd(CDC* pDC)

 CRect rtClient = CClientRect(m_hWnd);
  
 DrawFrame(pDC, rtClient.left, rtClient.top, rtClient.Width(), rtClient.Height(),0);
 DrawBkDlg(pDC, rtClient.left+m_borderLeftWidth, rtClient.top+m_titleHeight,
       rtClient.Width()-m_borderLeftWidth-m_borderRightWidth,
       rtClient.Height()-m_titleHeight-m_borderBottomHeight,
             0);


 return TRUE;

}

呵呵,就这么多了,这里不方便贴图,要不可以看到效果的,呵呵,欢迎指教。

posted on 2006-12-26 21:49 erran 阅读(1314) 评论(0)  编辑 收藏 引用 所属分类: WinCE

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理