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

编辑框

开发平台:

Visual C++

  1. // TreeViewFile.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Demo_DevStudio.h"
  5. #include "TreeViewFile.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CTreeViewFile
  13. IMPLEMENT_DYNCREATE(CTreeViewFile, CTreeView)
  14. CTreeViewFile::CTreeViewFile()
  15. {
  16. }
  17. CTreeViewFile::~CTreeViewFile()
  18. {
  19. }
  20. BEGIN_MESSAGE_MAP(CTreeViewFile, CTreeView)
  21. //{{AFX_MSG_MAP(CTreeViewFile)
  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. // CTreeViewFile drawing
  29. void CTreeViewFile::OnDraw(CDC* pDC)
  30. {
  31. CDocument* pDoc = GetDocument();
  32. // TODO: add draw code here
  33. }
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CTreeViewFile diagnostics
  36. #ifdef _DEBUG
  37. void CTreeViewFile::AssertValid() const
  38. {
  39. CTreeView::AssertValid();
  40. }
  41. void CTreeViewFile::Dump(CDumpContext& dc) const
  42. {
  43. CTreeView::Dump(dc);
  44. }
  45. #endif //_DEBUG
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CTreeViewFile message handlers
  48. void CTreeViewFile::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 CTreeViewFile::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("Workspace 'demo': 1 project(s)"),
  63. _T("Demo files"),
  64. _T("File Folder")
  65. };
  66. int CTreeViewFile::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_FILE, 16, 1, RGB(0,255,0));
  74. m_TreeCtrl->SetImageList (&m_ImageList, TVSIL_NORMAL);
  75. // add the parent item, make it bold
  76. HTREEITEM htiParent = m_TreeCtrl->InsertItem (csTree[0]);
  77. HTREEITEM htiChild; // child item
  78. htiChild = m_TreeCtrl->InsertItem (csTree[1], 1, 1, htiParent, TVI_LAST);
  79. m_TreeCtrl->SetItemState (htiChild, TVIS_BOLD, TVIS_BOLD);
  80. // add the children of the parent item
  81. for (int i = 1; i < 4; i++) {
  82. m_TreeCtrl->InsertItem (csTree[2], 2, 3, htiChild, TVI_LAST);
  83. }
  84. m_TreeCtrl->Expand (htiParent, TVE_EXPAND);
  85. m_TreeCtrl->Expand (htiChild, TVE_EXPAND);
  86. return 0;
  87. }
  88. BOOL CTreeViewFile::PreCreateWindow(CREATESTRUCT& cs) 
  89. {
  90. // TODO: Add your specialized code here and/or call the base class
  91. cs.style |= TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT;
  92. return CTreeView::PreCreateWindow(cs);
  93. }