LeftView.cpp
上传用户:zcy791212
上传日期:2013-03-06
资源大小:196k
文件大小:4k
源码类别:

Modem编程

开发平台:

Visual C++

  1. // LeftView.cpp : implementation of the CLeftView class
  2. //
  3. #include "stdafx.h"
  4. #include "vc_demo.h"
  5. #include "mainfrm.h"
  6. #include "vc_demoDoc.h"
  7. #include "LeftView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CLeftView
  15. IMPLEMENT_DYNCREATE(CLeftView, CTreeView)
  16. BEGIN_MESSAGE_MAP(CLeftView, CTreeView)
  17. //{{AFX_MSG_MAP(CLeftView)
  18. ON_WM_SHOWWINDOW()
  19. ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
  20. //}}AFX_MSG_MAP
  21. END_MESSAGE_MAP()
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CLeftView construction/destruction
  24. CLeftView::CLeftView()
  25. {
  26. // TODO: add construction code here
  27. }
  28. CLeftView::~CLeftView()
  29. {
  30. }
  31. BOOL CLeftView::PreCreateWindow(CREATESTRUCT& cs)
  32. {
  33. // TODO: Modify the Window class or styles here by modifying
  34. //  the CREATESTRUCT cs
  35. cs.style=cs.style
  36.             | TVS_HASLINES  
  37. | TVS_LINESATROOT 
  38. | TVS_HASBUTTONS;
  39. return CTreeView::PreCreateWindow(cs);
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CLeftView drawing
  43. void CLeftView::OnDraw(CDC* pDC)
  44. {
  45. CVc_demoDoc* pDoc = GetDocument();
  46. ASSERT_VALID(pDoc);
  47. // TODO: add draw code for native data here
  48. }
  49. void CLeftView::OnInitialUpdate()
  50. {
  51. CTreeView::OnInitialUpdate();
  52. // TODO: You may populate your TreeView with items by directly accessing
  53. //  its tree control through a call to GetTreeCtrl().
  54. }
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CLeftView diagnostics
  57. #ifdef _DEBUG
  58. void CLeftView::AssertValid() const
  59. {
  60. CTreeView::AssertValid();
  61. }
  62. void CLeftView::Dump(CDumpContext& dc) const
  63. {
  64. CTreeView::Dump(dc);
  65. }
  66. CVc_demoDoc* CLeftView::GetDocument() // non-debug version is inline
  67. {
  68. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVc_demoDoc)));
  69. return (CVc_demoDoc*)m_pDocument;
  70. }
  71. #endif //_DEBUG
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CLeftView message handlers
  74. void CLeftView::OnShowWindow(BOOL bShow, UINT nStatus) 
  75. {
  76. CTreeView::OnShowWindow(bShow, nStatus);
  77. // TODO: Add your message handler code here
  78.     setTreeStyle();
  79. }
  80. void CLeftView::setTreeStyle()
  81. {
  82. CTreeCtrl &treectrl=this->GetTreeCtrl();
  83. treectrl.SetBkColor(0xF1C7ED);
  84. treectrl.SetTextColor(0xA20000);
  85. CImageList img;
  86. img.Create(IDB_TREE, 16, 0, RGB(244, 247, 14));
  87. treectrl.SetImageList(&img,TVSIL_NORMAL);
  88.     img.Detach();
  89. treectrl.InsertItem("在线Modem",0,1,TVI_ROOT,TVI_LAST);
  90. }
  91. void CLeftView::ClearAllItem()
  92. {
  93. CTreeCtrl &tc=GetTreeCtrl();
  94. tc.DeleteAllItems();
  95. tc.InsertItem("在线Modem",0,1,TVI_ROOT,TVI_LAST);
  96. }
  97. void CLeftView::InsertUserItem(char *szUserId)
  98. {
  99. CTreeCtrl &tc=GetTreeCtrl();
  100. tc.InsertItem(szUserId,2,2,tc.GetFirstVisibleItem(),TVI_LAST);
  101. }
  102. void CLeftView::DeleteUserItem(char *szUserId)
  103. {
  104. CTreeCtrl &tc=GetTreeCtrl();
  105. HTREEITEM hti;
  106. hti=tc.GetChildItem(tc.GetFirstVisibleItem());
  107. while (hti)
  108. {
  109. if (0==tc.GetItemText(hti).Compare(szUserId))
  110. {
  111. tc.DeleteItem(hti);
  112. break;
  113. }
  114. }
  115. }
  116. void CLeftView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) 
  117. {
  118. // TODO: Add your control notification handler code here
  119. CTreeCtrl &tc=this->GetTreeCtrl();
  120. CString STreeItem;
  121. if (tc.GetSelectedItem()) 
  122. {
  123. STreeItem=tc.GetItemText(tc.GetSelectedItem());
  124. if (11==STreeItem.GetLength())
  125. {
  126. ((CMainFrame *)::AfxGetMainWnd())->SetUserId(STreeItem.GetBuffer(0));
  127. ::PostMessage(((CMainFrame *)::AfxGetMainWnd())->m_hWnd,ID_MISENDDATA,0,0);
  128. }
  129. else
  130. ((CMainFrame *)::AfxGetMainWnd())->SetUserId("");
  131. }
  132. *pResult = 0;
  133. }