📄 myview1.cpp
字号:
// StringListView.cpp : implementation file
//
#include "stdafx.h"
#include "Tab2.h"
#include "MyView1.h"
#include "Tab2Doc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyView1
IMPLEMENT_DYNCREATE(CMyView1, CListView)
CMyView1::CMyView1()
{
m_Increase=0;
}
CMyView1::~CMyView1()
{
}
BEGIN_MESSAGE_MAP(CMyView1, CListView)
//{{AFX_MSG_MAP(CMyView1)
ON_WM_TIMER()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyView1 drawing
void CMyView1::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CMyView1 diagnostics
#ifdef _DEBUG
void CMyView1::AssertValid() const
{
CListView::AssertValid();
}
void CMyView1::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyView1 message handlers
void CMyView1::OnInitialUpdate()
{
CListView::OnInitialUpdate();
LV_COLUMN lvcolumn;
LV_ITEM lvitem;
CListCtrl &rListCtrl = GetListCtrl();
lvcolumn.mask=LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
lvcolumn.fmt=LVCFMT_CENTER;
lvcolumn.cx=80;
lvcolumn.iSubItem=0;
lvcolumn.pszText="Column 1";
rListCtrl.InsertColumn(0,&lvcolumn);
lvcolumn.iSubItem=1;
lvcolumn.pszText="Column 2";
rListCtrl.InsertColumn(1,&lvcolumn);
CString str;
str.Format("%d ",m_Increase);
lvitem.mask=LVIF_TEXT;
lvitem.iItem= 0;
lvitem.pszText=str.GetBuffer(10);
lvitem.iSubItem= 0;
rListCtrl.InsertItem(&lvitem);
lvitem.iSubItem= 1;
rListCtrl.SetItem(&lvitem);
SetTimer(1,500,NULL);
}
void CMyView1::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==1)
{
LV_ITEM lvitem;
m_Increase=((CTab2Doc*)GetDocument())->m_Accumulater++;
CListCtrl &ListCtrl = GetListCtrl();
CString str;
str.Format("%d ",m_Increase);
lvitem.mask=LVIF_TEXT;
lvitem.iItem= 0;
lvitem.iSubItem= 1;
lvitem.pszText=str.GetBuffer(5);
ListCtrl.SetItem(&lvitem);
}
}
BOOL CMyView1::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
cs.style |= LVS_SHOWSELALWAYS | LVS_REPORT;
return CListView::PreCreateWindow(cs);
}
int CMyView1::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListView::OnCreate(lpCreateStruct) == -1)
return -1;
// set list control's style to hilight the entire row
DWORD dwStyle = SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE);
/*设置ListView的风格*/
dwStyle |= LVS_EX_FULLROWSELECT /*整行选择*/
|LVS_EX_GRIDLINES /*加入横竖线*/
|LVS_EX_HEADERDRAGDROP;/*拖拉*/
SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, (LPARAM)dwStyle);
return 0;
}
BOOL CMyView1::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
KillTimer(1);
return CListView::DestroyWindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -