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

界面编程

开发平台:

Visual C++

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