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

界面编程

开发平台:

Visual C++

  1. // RTCheckBox.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "RTDraw.h"
  5. #include "RTCheckBox.h"
  6. // CRTCheckBox
  7. IMPLEMENT_DYNAMIC(CRTCheckBox, CButton)
  8. CRTCheckBox::CRTCheckBox()
  9. {
  10. }
  11. CRTCheckBox::~CRTCheckBox()
  12. {
  13. }
  14. CBitmap* CRTCheckBox::m_StaticBitmap[5] = {NULL,NULL,NULL,NULL,NULL};
  15. UINT     CRTCheckBox::m_StaticBitmapDrawMode[5] = {0,0,0,0,0};
  16. BOOL     CRTCheckBox::m_IsEnableSkin = FALSE;
  17. BOOL     CRTCheckBox::m_IsBackTransparent = FALSE;
  18. BEGIN_MESSAGE_MAP(CRTCheckBox, CButton)
  19. ON_WM_PAINT()
  20. ON_WM_ERASEBKGND()
  21. END_MESSAGE_MAP()
  22. // CRTCheckBox 消息处理程序
  23. void CRTCheckBox::SetBitmap(CBitmap* StaticBitmap[],UINT DrawMode[])
  24. {
  25. for(int i = 0; i < 5; i ++)
  26. {
  27. m_StaticBitmap[i]=StaticBitmap[i];
  28. m_StaticBitmapDrawMode[i] = DrawMode[i];
  29. }
  30. }
  31. void CRTCheckBox::EnableSkin(BOOL IsEnable,BOOL BackTransparent)
  32. {
  33. m_IsEnableSkin = IsEnable;
  34. m_IsBackTransparent = BackTransparent;
  35. }
  36. void CRTCheckBox::OnPaint()
  37. {
  38. if(!m_IsEnableSkin)return CButton::OnPaint();
  39. DWORD style = GetStyle();
  40. if((style & BS_CHECKBOX) != BS_CHECKBOX && (style & BS_AUTOCHECKBOX) != BS_AUTOCHECKBOX)
  41. return CButton::OnPaint();
  42. CRect rcWnd;
  43. GetClientRect(&rcWnd);
  44. CPaintDC ptDC(this);
  45. CMemDC memDC(&ptDC,rcWnd);
  46. CDC defDC;
  47. defDC.CreateCompatibleDC(&ptDC);
  48. CBitmap  defBmp;
  49. CBitmap* defOld;
  50. defBmp.CreateCompatibleBitmap(&ptDC,rcWnd.right,rcWnd.bottom);
  51. defOld = defDC.SelectObject(&defBmp);
  52. COLORREF TransparentColor = GetSysColor(COLOR_3DFACE);
  53. CBrush br(TransparentColor);
  54. defDC.FillRect(&rcWnd,&br);
  55. DefWindowProc(WM_ERASEBKGND, (WPARAM)defDC.m_hDC , 0);
  56. DefWindowProc(WM_PAINT, (WPARAM)defDC.m_hDC , 0);
  57. if(!m_IsBackTransparent)
  58. {
  59. CRTDraw::RTDrawBitmap(&memDC,&rcWnd,m_StaticBitmap[BMP_BACK],m_StaticBitmapDrawMode[BMP_BACK]);
  60. }
  61. memDC.TransparentBlt(rcWnd.left,rcWnd.top,rcWnd.Width(),rcWnd.Height(),&defDC,rcWnd.left,rcWnd.top,rcWnd.Width(),rcWnd.Height(),TransparentColor);
  62. return;
  63. CRect rtIcon;
  64. TEXTMETRIC tm;
  65. ptDC.GetTextMetrics(&tm);
  66. int height = tm.tmHeight;
  67. rtIcon.left = rcWnd.left;
  68. rtIcon.top = rcWnd.top + (rcWnd.Height() - height)/2;
  69. rtIcon.bottom = rtIcon.top + height;
  70. rtIcon.right = rtIcon.left + height;
  71. if((style & WS_DISABLED) == WS_DISABLED)
  72. CRTDraw::RTDrawBitmap(&memDC,&rtIcon,m_StaticBitmap[BMP_DISABLE],m_StaticBitmapDrawMode[BMP_DISABLE]);
  73. int check = GetCheck();
  74. if(check == BST_CHECKED)
  75. CRTDraw::RTDrawBitmap(&memDC,&rtIcon,m_StaticBitmap[BMP_CHECK],m_StaticBitmapDrawMode[BMP_CHECK]);
  76. else
  77. CRTDraw::RTDrawBitmap(&memDC,&rtIcon,m_StaticBitmap[BMP_UNCHECK],m_StaticBitmapDrawMode[BMP_UNCHECK]);
  78. defDC.SelectObject(defOld);
  79. }
  80. BOOL CRTCheckBox::OnEraseBkgnd(CDC* pDC)
  81. {
  82. if(!m_IsEnableSkin)return CButton::OnEraseBkgnd(pDC);
  83. return TRUE;
  84. }
  85. LRESULT CRTCheckBox::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  86. {
  87. LRESULT result = CButton::WindowProc(message, wParam, lParam);
  88. //if(message == BM_SETCHECK)
  89. //{
  90. // Invalidate();
  91. //}
  92. //
  93. return result;
  94. }