RTStatic.cpp
上传用户:qhonly
上传日期:2013-06-10
资源大小:487k
文件大小:2k
源码类别:

界面编程

开发平台:

Visual C++

  1. // RTStatic.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "RTStatic.h"
  5. #include "RTDraw.h"
  6. // CRTStatic
  7. IMPLEMENT_DYNAMIC(CRTStatic, CStatic)
  8. CRTStatic::CRTStatic()
  9. {
  10. }
  11. CRTStatic::~CRTStatic()
  12. {
  13. }
  14. CBitmap* CRTStatic::m_StaticBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  15. UINT     CRTStatic::m_StaticBitmapDrawMode[5] = {0,0,0,0,0};
  16. BOOL     CRTStatic::m_IsEnableSkin = FALSE;
  17. BOOL     CRTStatic::m_IsBackTransparent = FALSE;
  18. BEGIN_MESSAGE_MAP(CRTStatic, CStatic)
  19. ON_WM_ERASEBKGND()
  20. ON_WM_PAINT()
  21. END_MESSAGE_MAP()
  22. // CRTStatic 消息处理程序
  23. BOOL CRTStatic::OnEraseBkgnd(CDC* pDC)
  24. {
  25. if(m_StaticBitmap[0] == NULL || !m_IsEnableSkin)
  26. return CStatic::OnEraseBkgnd(pDC);
  27. return TRUE;
  28. }
  29. void CRTStatic::OnPaint()
  30. {
  31. if(!m_IsEnableSkin)return CStatic::OnPaint();
  32. CRect rcWnd;
  33. GetClientRect(&rcWnd);
  34. CPaintDC ptDC(this);
  35. CDC defDC;
  36. defDC.CreateCompatibleDC(&ptDC);
  37. CBitmap  defBmp;
  38. CBitmap* defOld;
  39. defBmp.CreateCompatibleBitmap(&ptDC,rcWnd.right,rcWnd.bottom);
  40. defOld = defDC.SelectObject(&defBmp);
  41. COLORREF TransparentColor = GetSysColor(COLOR_3DFACE);
  42. CBrush br(TransparentColor);
  43. defDC.FillRect(&rcWnd,&br);
  44. DefWindowProc(WM_ERASEBKGND, (WPARAM)defDC.m_hDC , 0);
  45. DefWindowProc(WM_PAINT, (WPARAM)defDC.m_hDC , 0);
  46. DWORD style = GetStyle();
  47. if(!m_IsBackTransparent && (style & BS_GROUPBOX) != BS_GROUPBOX)
  48. {
  49. CRTDraw::RTDrawBitmap(&ptDC,&rcWnd,m_StaticBitmap[BMP_BACK],m_StaticBitmapDrawMode[BMP_BACK]);
  50. }
  51. ptDC.TransparentBlt(rcWnd.left,rcWnd.top,rcWnd.Width(),rcWnd.Height(),&defDC,rcWnd.left,rcWnd.top,rcWnd.Width(),rcWnd.Height(),TransparentColor);
  52. defDC.SelectObject(defOld);
  53. }
  54. void CRTStatic::SetBitmap(CBitmap* StaticBitmap[],UINT DrawMode[])
  55. {
  56. for(int i = 0; i < 5; i ++)
  57. {
  58. m_StaticBitmap[i]=StaticBitmap[i];
  59. m_StaticBitmapDrawMode[i] = DrawMode[i];
  60. }
  61. }
  62. void CRTStatic::EnableSkin(BOOL IsEnable,BOOL BackTransparent)
  63. {
  64. m_IsEnableSkin = IsEnable;
  65. m_IsBackTransparent = BackTransparent;
  66. }