⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pppview.cpp

📁 利用TreeCtr控件访问数据库
💻 CPP
字号:
// PppView.cpp : implementation of the CPppView class
//

#include "stdafx.h"
#include "Ppp.h"

#include "PppDoc.h"
#include "PppView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPppView

IMPLEMENT_DYNCREATE(CPppView, CFormView)

BEGIN_MESSAGE_MAP(CPppView, CFormView)
	//{{AFX_MSG_MAP(CPppView)
	ON_NOTIFY(TVN_SELCHANGING, IDC_TREE1, OnSelchangingTree1)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPppView construction/destruction

CPppView::CPppView()
	: CFormView(CPppView::IDD)
{
	//{{AFX_DATA_INIT(CPppView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CPppView::~CPppView()
{
}

void CPppView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPppView)
	DDX_Control(pDX, IDC_TREE1, m_treectrl);
	//}}AFX_DATA_MAP
}

BOOL CPppView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CPppView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	//GetParentFrame()->RecalcLayout();
	//ResizeParentToFit();
	CPppDoc* pDoc = (CPppDoc*)GetDocument();

	m_ShengSet=&pDoc->m_ShengSet;
	
	TV_INSERTSTRUCT tvinsert;
	tvinsert.hParent = NULL;
	tvinsert.item.mask = TVIF_TEXT;	

	tvinsert.item.pszText = "全国";
	HTREEITEM hDad = m_treectrl.InsertItem(&tvinsert);
   if (m_ShengSet->IsOpen())
	    m_ShengSet->Close();
   m_ShengSet->Open();
   m_ShengSet->MoveFirst();

    CString c1;
	
   char buff[80];
   while(!m_ShengSet->IsEOF())
	{ 
		c1=m_ShengSet->m_column1;
		wsprintf(buff,"%s",c1);
		tvinsert.item.pszText = buff;
       tvinsert.hParent = hDad;
	   m_treectrl.InsertItem(&tvinsert);
  
	   m_ShengSet->MoveNext();
	  
   }

}

/////////////////////////////////////////////////////////////////////////////
// CPppView printing

BOOL CPppView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CPppView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CPppView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CPppView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CPppView diagnostics

#ifdef _DEBUG
void CPppView::AssertValid() const
{
	CFormView::AssertValid();
}

void CPppView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CPppDoc* CPppView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPppDoc)));
	return (CPppDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPppView message handlers

void CPppView::OnSelchangingTree1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	CTreeCtrl* pTree2 = (CTreeCtrl*) GetDlgItem(IDC_TREE1);
    HTREEITEM hSelected = pNMTreeView->itemNew.hItem;
	CPppDoc* pDoc = (CPppDoc*)GetDocument();
	CString hParentName;
	HTREEITEM hParent=pTree2->GetParentItem(hSelected);	
    if(hSelected!=NULL)
	{
		  pDoc->Name=pTree2->GetItemText(hSelected);
     }	

	*pResult = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -