RtreeView.cpp
上传用户:shtiemo
上传日期:2017-12-29
资源大小:163k
文件大小:5k
开发平台:

Visual C++

  1. // RtreeView.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "PasRTDat.h"
  5. #include "RtreeView.h"
  6. #include "PwrNet.h"
  7. #include "PasRTDatDoc.h"
  8. #include "RtListView.h"
  9. #include "RTDatOpr.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CRtreeView
  17. IMPLEMENT_DYNCREATE(CRtreeView, CTreeView)
  18. CRtreeView::CRtreeView()
  19. {
  20. }
  21. CRtreeView::~CRtreeView()
  22. {
  23. }
  24. BEGIN_MESSAGE_MAP(CRtreeView, CTreeView)
  25. //{{AFX_MSG_MAP(CRtreeView)
  26. ON_WM_CREATE()
  27. ON_WM_LBUTTONDBLCLK()
  28. //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CRtreeView drawing
  32. void CRtreeView::OnDraw(CDC* pDC)
  33. {
  34. CDocument* pDoc = GetDocument();
  35. // TODO: add draw code here
  36. }
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CRtreeView diagnostics
  39. #ifdef _DEBUG
  40. void CRtreeView::AssertValid() const
  41. {
  42. CTreeView::AssertValid();
  43. }
  44. void CRtreeView::Dump(CDumpContext& dc) const
  45. {
  46. CTreeView::Dump(dc);
  47. }
  48. #endif //_DEBUG
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CRtreeView message handlers
  51. CPasRTDatDoc* CRtreeView::GetDoc()
  52. {
  53. return (CPasRTDatDoc*)GetDocument();
  54. }
  55. int CRtreeView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  56. {
  57. lpCreateStruct->style |= TVS_HASBUTTONS|TVS_HASLINES
  58. |TVS_LINESATROOT;
  59. if (CTreeView::OnCreate(lpCreateStruct) == -1)
  60. return -1;
  61. // TODO: Add your specialized creation code here
  62. GetDoc()->m_pTreeV = this;
  63. return 0;
  64. }
  65. #define     MAXITEMID 42
  66. void CRtreeView::OnInitialUpdate() 
  67. {
  68. CTreeView::OnInitialUpdate();
  69. FillTree();
  70. // TODO: Add your specialized code here and/or call the base class
  71. }
  72. void CRtreeView::FillTree()
  73. {
  74. CBitmap bitmap;
  75. //CRTNETApp *pApp;
  76. UINT iItem;
  77. int nParentItem[ITEM_DEEP];
  78. UINT nBitmapClose[ITEM_DEEP] = {
  79. IDB_ROOTCLOSE, // 0
  80. IDB_FIRSTCLOSE, // 1
  81. IDB_SECONDCLOSE, // 2
  82. };
  83. UINT nBitmapOpen[ITEM_DEEP] = {
  84. IDB_ROOTOPEN, // 0
  85. IDB_FIRSTOPEN, // 1
  86. IDB_SECONDOPEN, // 2
  87. };
  88. m_imagelist.Create(16, 16, TRUE/*bMask*/, MAXITEMID, MAXITEMID);
  89. for (UINT i = 0; i < ITEM_DEEP; i++)  // load bitmaps for dog, bird and fish
  90. {
  91. bitmap.LoadBitmap(nBitmapClose[i]);
  92. m_imagelist.Add(&bitmap, (COLORREF)0xFFFFFF);
  93. bitmap.DeleteObject();
  94. bitmap.LoadBitmap(nBitmapOpen[i]);
  95. m_imagelist.Add(&bitmap, (COLORREF)0xFFFFFF);
  96. bitmap.DeleteObject();
  97. }
  98. GetTreeCtrl().SetImageList(&m_imagelist, TVSIL_NORMAL);
  99. iItem = 0;
  100. nParentItem[0] = iItem;
  101. CString SQL,CZmingzi,Rootname;
  102. CPwrNet PwrNet;
  103. if (PwrNet.Open(CRecordset::forwardOnly, NULL, CRecordset::readOnly))
  104. {
  105. CZmingzi = PwrNet.m_MingZi;
  106. PwrNet.Close();
  107. }
  108. /*CRecordset m_rec(GetDoc()->m_pSet);
  109. CString SQL,CZmingzi,Rootname;
  110. SQL.Format("select * from DianWang");
  111. if (m_rec.Open(CRecordset::forwardOnly ,SQL,CRecordset::readOnly))
  112. {
  113. m_rec.GetFieldValue("MingZi",CZmingzi);
  114. }
  115. m_rec.Close();*/
  116. Rootname = CZmingzi + " RTDAT 监视一览";
  117. AddOneItem( 0, -1, 0, Rootname.GetBuffer(32), iItem++ );
  118. {
  119. nParentItem[1] = iItem;
  120. AddOneItem( 1, nParentItem[0], 1, _T("RTU 信息一览"), iItem++ );
  121. {
  122. AddOneItem( 2, nParentItem[1], 11, _T("RTU 遥测一览"), iItem++ );
  123. AddOneItem( 2, nParentItem[1], 12, _T("RTU 遥信一览"), iItem++ );
  124. }
  125. }
  126. SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) | TVS_SHOWSELALWAYS | TVS_DISABLEDRAGDROP | TVS_LINESATROOT | TVS_HASLINES | TVS_HASBUTTONS );
  127. SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
  128. }
  129. void CRtreeView::AddOneItem( int nGrade, int nParentItem, LPARAM lParam, char* szItemName, UINT iItem )
  130. {
  131. TV_INSERTSTRUCT tvstruct;
  132. if ( nParentItem == -1 )
  133. {
  134. tvstruct.hParent = NULL;
  135. }
  136. else
  137. {
  138. tvstruct.hParent = m_rghItem[nParentItem];
  139. }
  140. tvstruct.item.lParam = lParam;
  141. tvstruct.hInsertAfter = TVI_LAST;
  142. tvstruct.item.iImage = 2*nGrade;
  143. tvstruct.item.iSelectedImage = 2*nGrade+1;
  144. tvstruct.item.pszText = szItemName;
  145. tvstruct.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM;
  146. m_rghItem[iItem] = GetTreeCtrl().InsertItem(&tvstruct);
  147. }
  148. void CRtreeView::OnLButtonDblClk(UINT nFlags, CPoint point) 
  149. {
  150. // TODO: Add your message handler code here and/or call default
  151. HTREEITEM hTreeItem;
  152. CString NodeName;
  153. int start,Infonum;
  154. CTreeCtrl &pTreeCtrl =  GetTreeCtrl();
  155. hTreeItem = pTreeCtrl.GetSelectedItem();
  156. if (hTreeItem)
  157. {
  158. NodeName = pTreeCtrl.GetItemText(hTreeItem);
  159. }
  160. if(NodeName=="RTU 遥测一览")
  161. {
  162. GetDoc()->m_pListV->InitialList();
  163. if (gRtuID == 9999)
  164. {
  165. start = 0;
  166. Infonum = YCInfoAry1.GetSize();
  167. }
  168. else
  169. {
  170. start = GetRTUYXYCStartIdx(gRtuID,1);
  171. if (start < 0)
  172. {
  173. start = 0;
  174. Infonum = 0;
  175. }
  176. else
  177. Infonum = GetRTUYCYXNum(gRtuID,1,start);
  178. }
  179. GetDoc()->m_pListV->FillListYC(start, Infonum);
  180. }
  181. else if (NodeName=="RTU 遥信一览")
  182. {
  183. GetDoc()->m_pListV->InitialList();
  184. if (gRtuID == 9999)
  185. {
  186. start = 0;
  187. Infonum = YXInfoAry1.GetSize();
  188. }
  189. else
  190. {
  191. start = GetRTUYXYCStartIdx(gRtuID,2);
  192. if (start < 0)
  193. {
  194. start = 0;
  195. Infonum = 0;
  196. }
  197. else
  198. Infonum = GetRTUYCYXNum(gRtuID,2,start);
  199. }
  200. GetDoc()->m_pListV->FillListYX(start, Infonum);
  201. }
  202. CTreeView::OnLButtonDblClk(nFlags, point);
  203. }