TreeViewEx.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:6k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // TreeViewEx.cpp : implementation of the CTreeViewEx class
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "CaptionBar.h"
  22. #include "ListViewExDoc.h"
  23. #include "TreeViewEx.h"
  24. #include "MainFrm.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CTreeViewEx
  32. IMPLEMENT_DYNCREATE(CTreeViewEx, CView)
  33. BEGIN_MESSAGE_MAP(CTreeViewEx, CView)
  34. //{{AFX_MSG_MAP(CTreeViewEx)
  35. ON_WM_CREATE()
  36. ON_WM_WINDOWPOSCHANGED()
  37. //}}AFX_MSG_MAP
  38. // Standard printing commands
  39. ON_BN_CLICKED(IDC_CAPT_BUTTON, OnCaptButton)
  40. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  41. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  42. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CTreeViewEx construction/destruction
  46. CTreeViewEx::CTreeViewEx()
  47. {
  48. }
  49. CTreeViewEx::~CTreeViewEx()
  50. {
  51. m_ilTreeIcons.DeleteImageList();
  52. }
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CTreeViewEx drawing
  55. void CTreeViewEx::OnDraw(CDC*)
  56. {
  57. }
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CTreeViewEx printing
  60. BOOL CTreeViewEx::OnPreparePrinting(CPrintInfo* pInfo)
  61. {
  62. // default preparation
  63. return DoPreparePrinting(pInfo);
  64. }
  65. void CTreeViewEx::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  66. {
  67. // TODO: add extra initialization before printing
  68. }
  69. void CTreeViewEx::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  70. {
  71. // TODO: add cleanup after printing
  72. }
  73. void CTreeViewEx::OnInitialUpdate()
  74. {
  75. CView::OnInitialUpdate();
  76. // TODO: You may populate your TreeView with items by directly accessing
  77. //  its tree control through a call to m_wndTreeCtrl.
  78. }
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CTreeViewEx diagnostics
  81. #ifdef _DEBUG
  82. void CTreeViewEx::AssertValid() const
  83. {
  84. CView::AssertValid();
  85. }
  86. void CTreeViewEx::Dump(CDumpContext& dc) const
  87. {
  88. CView::Dump(dc);
  89. }
  90. CListViewExDoc* CTreeViewEx::GetDocument() // non-debug version is inline
  91. {
  92. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CListViewExDoc)));
  93. return (CListViewExDoc*)m_pDocument;
  94. }
  95. #endif //_DEBUG
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CTreeViewEx message handlers
  98. int CTreeViewEx::OnCreate(LPCREATESTRUCT lpCreateStruct)
  99. {
  100. if (CView::OnCreate(lpCreateStruct) == -1)
  101. return -1;
  102. // Create the caption.
  103. if (!m_wndCaption.Create( this, _T("Folder List"), CPWS_EX_RAISED_EDGE | CPWS_EX_CLOSEBUTTON,
  104. WS_VISIBLE | SS_CENTER | SS_CENTERIMAGE, CRect(0,0,0,0), IDC_CAPT_BUTTON ))
  105. {
  106. TRACE0( "Unable to create caption.n" );
  107. return -1;
  108. }
  109. // create the tree control.
  110. if (!m_wndTreeCtrl.Create (WS_VISIBLE|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS|TVS_SHOWSELALWAYS,
  111. CRect(0,0,0,0), this, IDC_TREE_VIEW))
  112. {
  113. TRACE0( "Unable to create tree control.n" );
  114. return -1;
  115. }
  116. // create the image lists used by the caption and tree controls.
  117. if (!InitializeImageLists())
  118. return -1;
  119. // fill the tree control.
  120. if (!InitilalizeTreeControl())
  121. return -1;
  122. return 0;
  123. }
  124. void CTreeViewEx::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
  125. {
  126. CView::OnWindowPosChanged(lpwndpos);
  127. // Move the caption and tree control to their correct locations.
  128. if( ::IsWindow( m_wndCaption.m_hWnd ) )
  129. {
  130. ::SetWindowPos( m_wndCaption.m_hWnd, NULL, 0, 0, lpwndpos->cx, 19,
  131. SWP_NOZORDER | SWP_NOACTIVATE );
  132. }
  133. if( ::IsWindow( m_wndTreeCtrl.m_hWnd ) )
  134. {
  135. ::SetWindowPos( m_wndTreeCtrl.m_hWnd, NULL, 0, 19, lpwndpos->cx, lpwndpos->cy-19,
  136. SWP_NOZORDER | SWP_NOACTIVATE );
  137. }
  138. }
  139. void CTreeViewEx::OnCaptButton()
  140. {
  141. CMainFrame* pFrameWnd = (CMainFrame*)GetParentFrame();
  142. ASSERT_KINDOF (CMainFrame, pFrameWnd);
  143. pFrameWnd->CloseTreeViewPane();
  144. }
  145. BOOL CTreeViewEx::PreCreateWindow(CREATESTRUCT& cs)
  146. {
  147. if( !CView::PreCreateWindow( cs ))
  148. return FALSE;
  149. // TODO: Modify the Window class or styles here by modifying
  150. //  the CREATESTRUCT cs
  151. cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
  152. return TRUE;
  153. }
  154. BOOL CTreeViewEx::InitilalizeTreeControl()
  155. {
  156. // Set the tree controls image list.
  157. m_wndTreeCtrl.SetImageList (&m_ilTreeIcons, TVSIL_NORMAL);
  158. // TODO: Add items to the tree control.
  159. HTREEITEM htItem = m_wndTreeCtrl.InsertItem(_T("Parent Item"));
  160. // Add children
  161. int i;
  162. for(i = 1; i < 5; i++ ) {
  163. m_wndTreeCtrl.InsertItem (_T("Child of Parent Item"), 0, 0, htItem, TVI_LAST);
  164. }
  165. m_wndTreeCtrl.Expand(htItem, TVE_EXPAND);
  166. m_wndTreeCtrl.EnableMultiSelect(FALSE);
  167. return TRUE;
  168. }
  169. BOOL CTreeViewEx::InitializeImageLists()
  170. {
  171. // Create the image list used by the tree control.
  172. if (!m_ilTreeIcons.Create(16, 16, ILC_MASK|ILC_COLOR24, 2, 1))
  173. return FALSE;
  174. // TODO: Load your icons that you want displayed in the tree
  175. // control here, then add them to the image list.
  176. HICON hIcon = AfxGetApp()->LoadIcon(IDR_CAPTIOTYPE);
  177. m_ilTreeIcons.Add(hIcon);
  178. return TRUE;
  179. }