PppView.cpp
Upload User: kjzhanglin
Upload Date: 2021-07-11
Package Size: 31k
Code Size: 4k
Category:

TreeView

Development Platform:

Visual C++

  1. // PppView.cpp : implementation of the CPppView class
  2. // Download by http://www.codefans.net
  3. #include "stdafx.h"
  4. #include "Ppp.h"
  5. #include "PppDoc.h"
  6. #include "PppView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CPppView
  14. IMPLEMENT_DYNCREATE(CPppView, CFormView)
  15. BEGIN_MESSAGE_MAP(CPppView, CFormView)
  16. //{{AFX_MSG_MAP(CPppView)
  17. ON_NOTIFY(TVN_SELCHANGING, IDC_TREE1, OnSelchangingTree1)
  18. //}}AFX_MSG_MAP
  19. // Standard printing commands
  20. ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
  21. ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
  22. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
  23. END_MESSAGE_MAP()
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CPppView construction/destruction
  26. CPppView::CPppView()
  27. : CFormView(CPppView::IDD)
  28. {
  29. //{{AFX_DATA_INIT(CPppView)
  30. // NOTE: the ClassWizard will add member initialization here
  31. //}}AFX_DATA_INIT
  32. // TODO: add construction code here
  33. }
  34. CPppView::~CPppView()
  35. {
  36. }
  37. void CPppView::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CFormView::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CPppView)
  41. DDX_Control(pDX, IDC_TREE1, m_treectrl);
  42. //}}AFX_DATA_MAP
  43. }
  44. BOOL CPppView::PreCreateWindow(CREATESTRUCT& cs)
  45. {
  46. // TODO: Modify the Window class or styles here by modifying
  47. //  the CREATESTRUCT cs
  48. return CFormView::PreCreateWindow(cs);
  49. }
  50. void CPppView::OnInitialUpdate()
  51. {
  52. CFormView::OnInitialUpdate();
  53. //GetParentFrame()->RecalcLayout();
  54. //ResizeParentToFit();
  55. CPppDoc* pDoc = (CPppDoc*)GetDocument();
  56. m_ShengSet=&pDoc->m_ShengSet;
  57. TV_INSERTSTRUCT tvinsert;
  58. tvinsert.hParent = NULL;
  59. tvinsert.item.mask = TVIF_TEXT;
  60. tvinsert.item.pszText = "全国";
  61. HTREEITEM hDad = m_treectrl.InsertItem(&tvinsert);
  62.    if (m_ShengSet->IsOpen())
  63.     m_ShengSet->Close();
  64.    m_ShengSet->Open();
  65.    m_ShengSet->MoveFirst();
  66.     CString c1;
  67.    char buff[80];
  68.    while(!m_ShengSet->IsEOF())
  69. c1=m_ShengSet->m_column1;
  70. wsprintf(buff,"%s",c1);
  71. tvinsert.item.pszText = buff;
  72.        tvinsert.hParent = hDad;
  73.    m_treectrl.InsertItem(&tvinsert);
  74.   
  75.    m_ShengSet->MoveNext();
  76.   
  77.    }
  78. }
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CPppView printing
  81. BOOL CPppView::OnPreparePrinting(CPrintInfo* pInfo)
  82. {
  83. // default preparation
  84. return DoPreparePrinting(pInfo);
  85. }
  86. void CPppView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  87. {
  88. // TODO: add extra initialization before printing
  89. }
  90. void CPppView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  91. {
  92. // TODO: add cleanup after printing
  93. }
  94. void CPppView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
  95. {
  96. // TODO: add customized printing code here
  97. }
  98. /////////////////////////////////////////////////////////////////////////////
  99. // CPppView diagnostics
  100. #ifdef _DEBUG
  101. void CPppView::AssertValid() const
  102. {
  103. CFormView::AssertValid();
  104. }
  105. void CPppView::Dump(CDumpContext& dc) const
  106. {
  107. CFormView::Dump(dc);
  108. }
  109. CPppDoc* CPppView::GetDocument() // non-debug version is inline
  110. {
  111. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPppDoc)));
  112. return (CPppDoc*)m_pDocument;
  113. }
  114. #endif //_DEBUG
  115. /////////////////////////////////////////////////////////////////////////////
  116. // CPppView message handlers
  117. void CPppView::OnSelchangingTree1(NMHDR* pNMHDR, LRESULT* pResult) 
  118. {
  119. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  120. // TODO: Add your control notification handler code here
  121. CTreeCtrl* pTree2 = (CTreeCtrl*) GetDlgItem(IDC_TREE1);
  122.     HTREEITEM hSelected = pNMTreeView->itemNew.hItem;
  123. CPppDoc* pDoc = (CPppDoc*)GetDocument();
  124. CString hParentName;
  125. HTREEITEM hParent=pTree2->GetParentItem(hSelected);
  126.     if(hSelected!=NULL)
  127. {
  128.   pDoc->Name=pTree2->GetItemText(hSelected);
  129.      }
  130. *pResult = 0;
  131. }