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

界面编程

开发平台:

Visual C++

  1. // RTTreeCtrl.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "RTTreeCtrl.h"
  5. #include "RTDraw.h"
  6. // CRTTreeCtrl
  7. IMPLEMENT_DYNAMIC(CRTTreeCtrl, CTreeCtrl)
  8. CRTTreeCtrl::CRTTreeCtrl()
  9. {
  10. }
  11. CRTTreeCtrl::~CRTTreeCtrl()
  12. {
  13. }
  14. CBitmap* CRTTreeCtrl::m_BackBitmap[4] = {NULL,NULL,NULL,NULL};
  15. UINT     CRTTreeCtrl::m_BackBitmapDrawMode[4] = {0,0,0,0};
  16. BOOL     CRTTreeCtrl::m_IsEnableSkin = TRUE;
  17. BEGIN_MESSAGE_MAP(CRTTreeCtrl, CTreeCtrl)
  18. ON_WM_ERASEBKGND()
  19. ON_WM_PAINT()
  20. ON_WM_CREATE()
  21. ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnTvnItemexpanding)
  22. ON_NOTIFY_REFLECT(TVN_ITEMEXPANDED, OnTvnItemexpanded)
  23. END_MESSAGE_MAP()
  24. // CRTTreeCtrl 消息处理程序
  25. void CRTTreeCtrl::SetBackBitmap(CBitmap *pBack[],UINT DrawMode[])
  26. {
  27. for(int i = 0; i < 4; i++)
  28. {
  29. m_BackBitmap[i] = pBack[i];
  30. m_BackBitmapDrawMode[i] = DrawMode[i];
  31. }
  32. }
  33. void CRTTreeCtrl::EnableSkin(BOOL IsEnable)
  34. {
  35. m_IsEnableSkin = IsEnable;
  36. }
  37. BOOL CRTTreeCtrl::OnEraseBkgnd(CDC* pDC)
  38. {
  39. if(!m_IsEnableSkin)
  40. return CTreeCtrl::OnEraseBkgnd(pDC);
  41. return TRUE;
  42. }
  43. void CRTTreeCtrl::OnPaint()
  44. {
  45. int max = 0;
  46. int pos = 0;
  47. max = GetScrollLimit(SBS_VERT);
  48. pos = GetScrollPos(SBS_VERT);
  49. m_Container.SetVerRange(0,max);
  50. m_Container.SetVerPos(pos);
  51. max = GetScrollLimit(SBS_HORZ);
  52. pos = GetScrollPos(SBS_HORZ);
  53. m_Container.SetHorRange(0,max);
  54. m_Container.SetHorPos(pos);
  55. if(!m_IsEnableSkin)return CTreeCtrl::OnPaint();
  56.   
  57. CRect rcWnd;
  58. GetClientRect(&rcWnd);
  59. CClientDC ptDC(this);
  60. CDC defDC;
  61. CMemDC memDC(&ptDC,rcWnd);
  62. defDC.CreateCompatibleDC(&ptDC);
  63. CBitmap  defBmp;
  64. CBitmap* defOld;
  65. defBmp.CreateCompatibleBitmap(&ptDC,rcWnd.Width(),rcWnd.Height());
  66. defOld = defDC.SelectObject(&defBmp);
  67. DefWindowProc(WM_ERASEBKGND, (WPARAM)defDC.m_hDC , 0);
  68. DefWindowProc(WM_PAINT, (WPARAM)defDC.m_hDC , 0);
  69. CRTDraw::RTDrawBitmap(&memDC,&rcWnd,m_BackBitmap[BMP_BACK],m_BackBitmapDrawMode[BMP_BACK]);
  70. memDC.TransparentBlt(rcWnd.left,rcWnd.top,rcWnd.Width(),rcWnd.Height(),&defDC,rcWnd.left,rcWnd.top,rcWnd.Width(),rcWnd.Height(),GetSysColor(COLOR_WINDOW));
  71. CPaintDC dc(this);
  72. defDC.SelectObject(defOld);
  73. }
  74. CScrollBar* CRTTreeCtrl::GetScrollBarCtrl(int nBar) const
  75. {
  76. // TODO: 在此添加专用代码和/或调用基类
  77. return NULL;
  78. //return CTreeCtrl::GetScrollBarCtrl(nBar);
  79. }
  80. void CRTTreeCtrl::PreSubclassWindow()
  81. {
  82. m_Container.Create(this);
  83. CTreeCtrl::PreSubclassWindow();
  84. }
  85. int CRTTreeCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  86. {
  87. if (CTreeCtrl::OnCreate(lpCreateStruct) == -1)
  88. return -1;
  89. m_Container.Create(this);
  90. return 0;
  91. }
  92. void CRTTreeCtrl::OnTvnItemexpanding(NMHDR *pNMHDR, LRESULT *pResult)
  93. {
  94. LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
  95. SetRedraw(FALSE);
  96. *pResult = 0;
  97. }
  98. void CRTTreeCtrl::OnTvnItemexpanded(NMHDR *pNMHDR, LRESULT *pResult)
  99. {
  100. LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
  101. SetRedraw(TRUE);
  102. *pResult = 0;
  103. }
  104. LRESULT CRTTreeCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  105. {
  106. return CTreeCtrl::WindowProc(message, wParam, lParam);
  107. }