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

📄 ex5_1view.cpp

📁 科大通讯录~可以输入、修改通讯录中的数据
💻 CPP
字号:
// EX5_1View.cpp : implementation of the CEX5_1View class
//

#include "stdafx.h"
#include "EX5_1.h"

#include "EX5_1Doc.h"
#include "EX5_1View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEX5_1View

IMPLEMENT_DYNCREATE(CEX5_1View, CFormView)

BEGIN_MESSAGE_MAP(CEX5_1View, CFormView)
	//{{AFX_MSG_MAP(CEX5_1View)
	ON_COMMAND(ID_OUTPUT, OnOutput)
	ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CEX5_1View construction/destruction

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

}

CEX5_1View::~CEX5_1View()
{
}

void CEX5_1View::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEX5_1View)
	DDX_Control(pDX, IDC_LIST1, m_List1);
	DDX_Control(pDX, IDC_TREE1, m_TREE1);
	//}}AFX_DATA_MAP
}

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

	return CFormView::PreCreateWindow(cs);
}

void CEX5_1View::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
    
	m_List1.DeleteColumn(0);
	m_List1.InsertColumn(0,"姓名",LVCFMT_CENTER,100,-1);
    m_List1.DeleteColumn(1);
	m_List1.InsertColumn(1,"单位",LVCFMT_CENTER,100);
	m_List1.DeleteColumn(2);
	m_List1.InsertColumn(2,"住址",LVCFMT_CENTER,100);
	m_List1.DeleteColumn(3);
	m_List1.InsertColumn(3,"电话",LVCFMT_CENTER,100);
	m_List1.DeleteColumn(4);
	m_List1.InsertColumn(4,"邮箱",LVCFMT_CENTER,100);
	tv.hParent=NULL;
	tv.item.mask=TVIF_TEXT;
	//////////添加头结点
	tv.item.pszText="科大通讯录";
	HTREEITEM hDad=m_TREE1.InsertItem(&tv);
	//////////添加第1层
    tv.hParent=hDad;
	tv.item.pszText="电子技术学院";
	hDZXY=m_TREE1.InsertItem(&tv);
	tv.item.pszText="化学工程学院";
	hHGXY=m_TREE1.InsertItem(&tv);
	tv.item.pszText="环境工程学院";
	hHJXY=m_TREE1.InsertItem(&tv);
	tv.item.pszText="材料工程学院";
	hCLXY=m_TREE1.InsertItem(&tv);
	tv.item.pszText="网络工程学院";
	hWLXY=m_TREE1.InsertItem(&tv);
	tv.item.pszText="生物工程学院";
	hSGXY=m_TREE1.InsertItem(&tv);
    CFrameWnd* pMain=(CFrameWnd*)AfxGetApp()->m_pMainWnd;
	pMain->SetTitle("科大通讯录");

}

/////////////////////////////////////////////////////////////////////////////
// CEX5_1View printing

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

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CEX5_1View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CEX5_1View message handlers

void CEX5_1View::OnOutput() 
{
	// TODO: Add your command handler code here
CEX5_1Doc* pDoc=GetDocument();
	CAddressList* pArray;
	int ArraySize=pDoc->m_AddressList.GetSize();
	if(ArraySize!=0)
	{
		CString temp;
		m_List1.DeleteAllItems();
		for(int i=0;i<ArraySize;i++)
		{
			pArray=pDoc->m_AddressList.GetAt(i);
			m_List1.InsertItem(i,pArray->m_Name);
			m_List1.SetItemText(i,1,pArray->m_Unit);
	        m_List1.SetItemText(i,2,pArray->m_Address);
		    m_List1.SetItemText(i,3,pArray->m_Phone);
			m_List1.SetItemText(i,4,pArray->m_Email);
		}
	}
	else
	{
		MessageBox("你没有输入数据","警告!",0);
	}	
}

void CEX5_1View::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
		CTreeCtrl* pTree=(CTreeCtrl*)GetDlgItem(IDC_TREE1);
	HTREEITEM hSelected=pNMTreeView->itemNew.hItem;
	if(hSelected!=NULL)
	{
		char text[32];
		TV_ITEM item;
		item.mask=TVIF_HANDLE|TVIF_TEXT;
		item.hItem=hSelected;
		item.pszText=text;
		item.cchTextMax=32;
		pTree->GetItem(&item);
		DispListView(item.pszText);
	}
	*pResult = 0;
}

void CEX5_1View::DispListView(CString temp)
{
    CEX5_1Doc* pDoc=GetDocument();
	int Counter=0;
	m_List1.DeleteAllItems();
	int ListViewCount=pDoc->m_AddressList.GetSize();
	if(ListViewCount>0)
	{
         CAddressList* pArray;
		 for(int i=0;i<ListViewCount;i++)
		 {
			 pArray=pDoc->m_AddressList.GetAt(i);
			 if(pArray->m_Unit==temp)
			 {
                  m_List1.InsertItem(Counter,pArray->m_Name);
				  m_List1.SetItemText(Counter,1,pArray->m_Unit);
                  m_List1.SetItemText(Counter,2,pArray->m_Address);
				  m_List1.SetItemText(Counter,3,pArray->m_Phone);
				  m_List1.SetItemText(Counter,4,pArray->m_Email);
				  Counter++;
			 }
		 }
	}
}

⌨️ 快捷键说明

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