?? ex5_1view.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 + -