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

界面编程

开发平台:

Visual C++

  1. // RTEdit.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "RTEdit.h"
  5. #include "RTDraw.h"
  6. // CRTEdit
  7. IMPLEMENT_DYNAMIC(CRTEdit, CEdit)
  8. CRTEdit::CRTEdit()
  9. {
  10. }
  11. CRTEdit::~CRTEdit()
  12. {
  13. }
  14. BEGIN_MESSAGE_MAP(CRTEdit, CEdit)
  15. ON_WM_ERASEBKGND()
  16. ON_WM_PAINT()
  17. ON_WM_LBUTTONDOWN()
  18. ON_WM_MOUSEMOVE()
  19. ON_WM_KILLFOCUS()
  20. ON_WM_LBUTTONUP()
  21. ON_WM_SETFOCUS()
  22. END_MESSAGE_MAP()
  23. CBitmap * CRTEdit::m_BackBitmap[5] = {NULL,NULL,NULL,NULL};
  24. UINT      CRTEdit::m_BackBitmapDrawMode[5] = {0,0,0,0,0};
  25. BOOL      CRTEdit::m_bEnableSkin = TRUE;
  26. // CRTEdit 消息处理程序
  27. BOOL CRTEdit::OnEraseBkgnd(CDC* pDC)
  28. {
  29. if(!m_bEnableSkin) return CEdit::OnEraseBkgnd(pDC);
  30. return TRUE;
  31. }
  32. void CRTEdit::SetBackBitmap(CBitmap* pBack[],UINT DrawMode[])
  33. {
  34. for(int i = 0;i < 5; i++)
  35. {
  36. m_BackBitmap[i] = pBack[i];
  37. m_BackBitmapDrawMode[i] = DrawMode[i];
  38. }
  39. }
  40. void CRTEdit::EnableSkin(BOOL IsEnable)
  41. {
  42. m_bEnableSkin = IsEnable;
  43. }
  44. void CRTEdit::OnPaint()
  45. {
  46. if(!m_bEnableSkin)return CEdit::OnPaint();
  47. if(m_BackBitmap[BMP_BACK] == NULL)
  48. return CEdit::OnPaint();
  49.     
  50. DrawText();
  51. CPaintDC dc(this);
  52. }
  53. void CRTEdit::OnLButtonDown(UINT nFlags, CPoint point)
  54. {
  55. CEdit::OnLButtonDown(nFlags, point);
  56. if(m_bEnableSkin)DrawText();
  57. }
  58. void CRTEdit::OnMouseMove(UINT nFlags, CPoint point)
  59. {
  60. if(nFlags == MK_LBUTTON)
  61. DrawText();
  62. CEdit::OnMouseMove(nFlags, point);
  63. }
  64. void CRTEdit::OnKillFocus(CWnd* pNewWnd)
  65. {
  66. CEdit::OnKillFocus(pNewWnd);
  67. if(m_bEnableSkin)DrawText();
  68. }
  69. void CRTEdit::OnLButtonUp(UINT nFlags, CPoint point)
  70. {
  71. CEdit::OnLButtonUp(nFlags, point);
  72. }
  73. void CRTEdit::OnSetFocus(CWnd* pOldWnd)
  74. {
  75. CEdit::OnSetFocus(pOldWnd);
  76. if(m_bEnableSkin)DrawText();
  77. }
  78. LRESULT CRTEdit::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  79. {
  80. if(m_bEnableSkin && ( message == WM_CUT || message == WM_PASTE || WM_CHAR))
  81. {
  82.         DrawText();
  83. }
  84. return CEdit::WindowProc(message, wParam, lParam);
  85. }
  86. void CRTEdit::DrawText(void)
  87. {
  88. if(m_BackBitmap[BMP_BACK] == NULL)
  89. return;
  90. CRect rcWnd;
  91. GetClientRect(&rcWnd);
  92. CClientDC ptDC(this);
  93. CDC defDC;
  94. CMemDC memDC(&ptDC,rcWnd);
  95. defDC.CreateCompatibleDC(&ptDC);
  96. CBitmap  defBmp;
  97. CBitmap* defOld;
  98. defBmp.CreateCompatibleBitmap(&ptDC,rcWnd.Width(),rcWnd.Height());
  99. defOld = defDC.SelectObject(&defBmp);
  100. DefWindowProc(WM_ERASEBKGND, (WPARAM)defDC.m_hDC , 0);
  101. DefWindowProc(WM_PAINT, (WPARAM)defDC.m_hDC , 0);
  102. CRTDraw::RTDrawBitmap(&memDC,&rcWnd,m_BackBitmap[BMP_BACK],m_BackBitmapDrawMode[BMP_BACK]);
  103. memDC.TransparentBlt(rcWnd.left,rcWnd.top,rcWnd.Width(),rcWnd.Height(),&defDC,rcWnd.left,rcWnd.top,rcWnd.Width(),rcWnd.Height(),GetSysColor(COLOR_WINDOW));
  104. defDC.SelectObject(defOld);
  105. }