📄 inforlistview.cpp
字号:
// InforListView.cpp : implementation file
//
#include "stdafx.h"
#include "Ch10Demo3.h"
#include "InforListView.h"
#include"Ch10Demo3Doc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInforListView
IMPLEMENT_DYNCREATE(CInforListView, CListView)
CInforListView::CInforListView()
{
}
CInforListView::~CInforListView()
{
}
BEGIN_MESSAGE_MAP(CInforListView, CListView)
//{{AFX_MSG_MAP(CInforListView)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInforListView drawing
void CInforListView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CInforListView diagnostics
#ifdef _DEBUG
void CInforListView::AssertValid() const
{
CListView::AssertValid();
}
void CInforListView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CInforListView message handlers
BOOL CInforListView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
cs.style=cs.style|LVS_REPORT; //设置成报告列表显示
return CListView::PreCreateWindow(cs);
}
void CInforListView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CString m_ColumnLabelStr[] ={"起点","终点","类型"}; //表头字段
CListCtrl& listctrl=GetListCtrl();//获取列表视控件
LVCOLUMN col;
col.mask = LVCF_WIDTH;
if(!listctrl.GetColumn(0,&col))//列表视图控件没有创建列
{
listctrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_UNDERLINEHOT); //列表风格
int width[3]={80,80,110}; //各列的初始宽度
for(int i=0; i<3; i++)
{
listctrl.InsertColumn(i, m_ColumnLabelStr[i], LVCFMT_LEFT, width[i]); //设置表头
}
}
}
void CInforListView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
CCh10Demo3Doc* pDoc =(CCh10Demo3Doc*)GetDocument(); //获取文档指针
CListCtrl& listctrl=GetListCtrl(); //获取列表控件
listctrl.DeleteAllItems(); //删除所有项
CString str1,str2,str3;
if(!pDoc->m_graphlist.IsEmpty()) //链表不为空
{
POSITION pos = pDoc->m_graphlist.GetHeadPosition(); //获取链表头的位置
for (int i=0;i<pDoc->m_graphlist.GetCount();i++) //遍历链表
{
CGraph* m_pGraph= (CGraph*)pDoc->m_graphlist.GetNext(pos);
str1.Format("(%d,%d)",m_pGraph->m_star.x,m_pGraph->m_star.y);//起点坐标
str2.Format("(%d,%d)",m_pGraph->m_end.x,m_pGraph->m_end.y);//终点坐标
switch (m_pGraph->m_type)
{
case 0:
str3="直线";
break;
case 1:
str3="矩形";
break;
case 2:
str3="椭圆";
break;
}
listctrl.InsertItem(i,str1);//添加数据
listctrl.SetItemText(i,1,str2);
listctrl.SetItemText(i,2,str3);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -