TREEVIEWCLASS.CPP
上传用户:gzfeiyu199
上传日期:2021-09-15
资源大小:68k
文件大小:3k
源码类别:

编辑框

开发平台:

Visual C++

  1. // TreeViewClass.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Demo_DevStudio.h"
  5. #include "TreeViewClass.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CTreeViewClass
  13. IMPLEMENT_DYNCREATE(CTreeViewClass, CTreeView)
  14. CTreeViewClass::CTreeViewClass()
  15. {
  16. }
  17. CTreeViewClass::~CTreeViewClass()
  18. {
  19. }
  20. BEGIN_MESSAGE_MAP(CTreeViewClass, CTreeView)
  21. //{{AFX_MSG_MAP(CTreeViewClass)
  22. ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemexpanding)
  23. ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
  24. ON_WM_CREATE()
  25. //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CTreeViewClass drawing
  29. void CTreeViewClass::OnDraw(CDC* pDC)
  30. {
  31. CDocument* pDoc = GetDocument();
  32. // TODO: add draw code here
  33. }
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CTreeViewClass diagnostics
  36. #ifdef _DEBUG
  37. void CTreeViewClass::AssertValid() const
  38. {
  39. CTreeView::AssertValid();
  40. }
  41. void CTreeViewClass::Dump(CDumpContext& dc) const
  42. {
  43. CTreeView::Dump(dc);
  44. }
  45. #endif //_DEBUG
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CTreeViewClass message handlers
  48. void CTreeViewClass::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult) 
  49. {
  50. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  51. // TODO: Add your control notification handler code here
  52. *pResult = 0;
  53. }
  54. void CTreeViewClass::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) 
  55. {
  56. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  57. // TODO: Add your control notification handler code here
  58. *pResult = 0;
  59. }
  60. static CString csTree[] =
  61. {
  62. _T("Demo classes"),
  63. _T("CClassName"),
  64. _T("Globals")
  65. };
  66. int CTreeViewClass::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  67. {
  68. if (CTreeView::OnCreate(lpCreateStruct) == -1)
  69. return -1;
  70. // TODO: Add your specialized creation code here
  71. m_TreeCtrl = &GetTreeCtrl();
  72. // Create the image list for the tree control
  73. m_ImageList.Create (IDB_IL_CLASS, 16, 1, RGB(0,255,0));
  74. m_TreeCtrl->SetImageList (&m_ImageList, TVSIL_NORMAL);
  75. // Add the parent item
  76. HTREEITEM htItem = m_TreeCtrl->InsertItem(csTree[0]);
  77. m_TreeCtrl->SetItemState( htItem, TVIS_BOLD, TVIS_BOLD );
  78. // Add children
  79. for( int i = 1; i < 8; i++ ) {
  80. m_TreeCtrl->InsertItem (csTree[1], 1, 1, htItem, TVI_LAST);
  81. }
  82. // Add children
  83. m_TreeCtrl->InsertItem (csTree[2], 2, 3, htItem, TVI_LAST);
  84. m_TreeCtrl->Expand(htItem, TVE_EXPAND);
  85. return 0;
  86. }
  87. BOOL CTreeViewClass::PreCreateWindow(CREATESTRUCT& cs) 
  88. {
  89. // TODO: Add your specialized code here and/or call the base class
  90. cs.style |= TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT;
  91. return CTreeView::PreCreateWindow(cs);
  92. }