SIDEPANE.CPP
上传用户:rxhxxy
上传日期:2007-01-02
资源大小:72k
文件大小:5k
源码类别:

TreeView控件

开发平台:

Visual C++

  1. // sidepane.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "treemenudemo.h"
  5. #include "sidepane.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. //_____________________________________
  12. //                                     |
  13. //           CSidePane                 |
  14. //_____________________________________|
  15. //
  16. // 
  17. //
  18. //
  19. #define BORDER  2
  20. #define IDC_COOLTREECTRL 1111
  21. #define NUM_ITEMS 9
  22. #define NUM_SUB 3
  23. static _TCHAR *_gszItem[NUM_ITEMS] = 
  24. {
  25. _T("Fifi"), _T("Babs Bunny"), _T("Buster Bunny"),
  26. _T("Concorde"), _T("Cyote"), _T("Dizzy Devil"), 
  27. _T("Elmyra"), _T("Hampton"), _T("Plucky Duck")
  28. };
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CSidePane
  31. CSidePane::CSidePane()
  32. {
  33. m_clrBtnHilight = ::GetSysColor(COLOR_BTNHILIGHT);
  34. m_clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
  35. m_iPaneCaptionY = ::GetSystemMetrics(SM_CYCAPTION);
  36. m_pControl = NULL;
  37. }
  38. CSidePane::~CSidePane()
  39. {
  40. }
  41. BEGIN_MESSAGE_MAP(CSidePane, CSizingControlBar)
  42.     //{{AFX_MSG_MAP(CSidePane)
  43.     ON_WM_CREATE()
  44.     ON_WM_SIZE()
  45. ON_WM_NCPAINT()
  46. ON_WM_PAINT()
  47.     //}}AFX_MSG_MAP
  48. ON_MESSAGE(TMFN_HIDE, OnHide)
  49. ON_MESSAGE(TMFN_CAPTIONDRAG, OnCaptionDrag)
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CSidePane message handlers
  53. int CSidePane::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  54. {
  55.     if (CSizingControlBar::OnCreate(lpCreateStruct) == -1)
  56.         return -1;
  57. m_TreeFrame.Create(CRect(0,0,0,0), this, 100);
  58. m_TreeFrame.CalcLayout();
  59. m_pControl = &m_TreeFrame;
  60. m_pControl->SubclassDlgItem(IDC_COOLTREECTRL, this);
  61. m_pControl->GetTreeMenuCtrl()->SetItemHeight(35);
  62. m_pControl->GetTreeMenuCtrl()->SetBorder(TVSBF_XBORDER|TVSBF_YBORDER, 2, 0);
  63. m_pControl->GetTreeMenuCtrl()->SetBkColor(GetSysColor (COLOR_3DFACE));
  64. m_pControl->ShowSideBevels();
  65. // ImageList
  66. m_ImageList.Create(IDB_TINYTOON, 32, 1, RGB(255,0,255));
  67.     
  68.     // Attach ImageList to TreeView
  69.     if (m_ImageList)
  70.         m_pControl->GetTreeMenuCtrl()->SetImageList((HIMAGELIST)m_ImageList,TVSIL_NORMAL);
  71. TVITEM tvi, tvi1;
  72. TVINSERTSTRUCT tvis;
  73. HTREEITEM hPrev;
  74. tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_CHILDREN;
  75. tvi.hItem = NULL;
  76. tvi.cchTextMax = 64;     
  77. tvi.pszText = _T("Tiny Toons");
  78. tvi.iImage = 0;
  79. tvi.iSelectedImage = 0;
  80. tvis.hParent = TVI_ROOT;
  81. tvis.hInsertAfter = TVI_LAST;
  82. tvis.item = tvi;
  83. hPrev = m_pControl->GetTreeMenuCtrl()->InsertItem(&tvis);
  84. int i;
  85. for(i = 0; i < NUM_SUB; i++)
  86. {
  87. tvi1.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
  88. tvi1.cchTextMax = 64; 
  89. tvi1.pszText = _gszItem[i];
  90. tvi1.iImage = i+1;
  91. tvi1.iSelectedImage = i+1;
  92. tvis.hParent = hPrev;
  93. tvis.hInsertAfter = TVI_LAST;
  94. tvis.item = tvi1;
  95. m_pControl->GetTreeMenuCtrl()->InsertItem(&tvis);
  96. }
  97. tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_CHILDREN;
  98. tvi.hItem = NULL;
  99. tvi.pszText = _T("Tiny Toons 2");
  100. tvi.iImage = 0;
  101. tvi.iSelectedImage = 0;
  102. tvis.hParent = TVI_ROOT;
  103. tvis.hInsertAfter = TVI_LAST;
  104. tvis.item = tvi;
  105. hPrev = m_pControl->GetTreeMenuCtrl()->InsertItem(&tvis);
  106. for(i = 0; i < NUM_SUB; i++)
  107. {
  108. tvi1.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
  109. tvi1.pszText = _gszItem[3+i];
  110. tvi1.iImage = i+4;
  111. tvi1.iSelectedImage = i+4;
  112. tvis.hParent = hPrev;
  113. tvis.hInsertAfter = TVI_LAST;
  114. tvis.item = tvi1;
  115. m_pControl->GetTreeMenuCtrl()->InsertItem(&tvis);
  116. }
  117. tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_CHILDREN;
  118. tvi.hItem = NULL;
  119. tvi.pszText = _T("Tiny Toons 3");
  120. tvi.iImage = 0;
  121. tvi.iSelectedImage = 0;
  122. tvis.hParent = TVI_ROOT;
  123. tvis.hInsertAfter = TVI_LAST;
  124. tvis.item = tvi;
  125. hPrev = m_pControl->GetTreeMenuCtrl()->InsertItem(&tvis);
  126. for(i = 0; i < NUM_SUB; i++)
  127. {
  128. tvi1.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
  129. tvi1.pszText = _gszItem[6+i];
  130. tvi1.iImage = i+7;
  131. tvi1.iSelectedImage = i+7;
  132. tvis.hParent = hPrev;
  133. tvis.hInsertAfter = TVI_LAST;
  134. tvis.item = tvi1;
  135. m_pControl->GetTreeMenuCtrl()->InsertItem(&tvis);
  136. }
  137. CString s;
  138. for(i = 0; i < NUM_SUB*2; i++)
  139. {
  140. s.Format("Bookmark No: %i", i+1);
  141. tvi1.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
  142. tvi1.pszText = s.GetBuffer(64);
  143. tvi.hItem = NULL;
  144. tvi1.iImage = i+1;
  145. tvi1.iSelectedImage = i+4;
  146. tvis.hParent = TVI_ROOT;
  147. tvis.hInsertAfter = TVI_LAST;
  148. tvis.item = tvi1;
  149. m_pControl->GetTreeMenuCtrl()->InsertItem(&tvis);
  150. s.ReleaseBuffer();
  151. }
  152.     return 0;
  153. }
  154. void CSidePane::OnNcPaint() 
  155. {
  156. CControlBar::EraseNonClient();
  157. }
  158. void CSidePane::OnPaint() 
  159. {
  160. CPaintDC dc(this);
  161. CControlBar::OnPaint();
  162. }
  163. void CSidePane::OnSize(UINT nType, int cx, int cy) 
  164. {
  165.     CSizingControlBar::OnSize(nType, cx, cy);
  166.     if (IsWindow(m_pControl->GetSafeHwnd()))
  167. PositionControls() ;
  168. }
  169. void CSidePane::PositionControls() 
  170. {
  171. CRect rc;
  172.     GetClientRect(rc);
  173. if (m_pControl)  
  174. {
  175.     m_pControl->MoveWindow(rc.left, rc.top, rc.right, rc.bottom);
  176. m_pControl->CalcLayout(TRUE);
  177. }
  178. }
  179. void CSidePane::OnHide() 
  180. {
  181. ShowPane(FALSE);
  182. }
  183. void CSidePane::OnCaptionDrag(UINT nFlags, CPoint point) 
  184. {
  185. CPoint pt; 
  186. GetCursorPos(&pt);
  187. ScreenToClient(&pt);
  188. CSizingControlBar::OnLButtonDown(nFlags, pt);
  189. }