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

📄 myview3.cpp

📁 VC++中Tab View的多种实现方法
💻 CPP
字号:
// IntListView.cpp : implementation file
//

#include "stdafx.h"
#include "Tab2.h"
#include "Tab2Doc.h"
#include "MyView3.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyView3

IMPLEMENT_DYNCREATE(CMyView3, CListView)

CMyView3::CMyView3()
{
}

CMyView3::~CMyView3()
{
}


BEGIN_MESSAGE_MAP(CMyView3, CListView)
	//{{AFX_MSG_MAP(CMyView3)
	ON_WM_TIMER()
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyView3 drawing

void CMyView3::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CMyView3 diagnostics

#ifdef _DEBUG
void CMyView3::AssertValid() const
{
	CListView::AssertValid();
}

void CMyView3::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyView3 message handlers

BOOL CMyView3::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);
}

void CMyView3::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="Column1";
	rListCtrl.InsertColumn(0,&lvcolumn);

    lvcolumn.iSubItem=1;
    lvcolumn.pszText="Column2";
	rListCtrl.InsertColumn(1,&lvcolumn);

    lvcolumn.iSubItem=2;
    lvcolumn.pszText="Column3";
	rListCtrl.InsertColumn(2,&lvcolumn);


	CString str;
	str.Format("%d ",0);
	lvitem.mask=LVIF_TEXT;
    lvitem.pszText=str.GetBuffer(10);

    lvitem.iItem= 0;
    lvitem.iSubItem= 0;
    rListCtrl.InsertItem(&lvitem);

    lvitem.iItem= 0;
    lvitem.iSubItem= 1;
    rListCtrl.SetItem(&lvitem);	

    lvitem.iItem= 0;
    lvitem.iSubItem= 2;
    rListCtrl.SetItem(&lvitem);	

	//启动定时器
	SetTimer(2,500,NULL);
}

void CMyView3::OnTimer(UINT nIDEvent) 
{
    
	unsigned int m_Increase;
	LV_ITEM lvitem;
	CString str;

	if(nIDEvent==2)
	{
	    m_Increase=((CTab2Doc*)GetDocument())->m_Accumulater++;

	    CListCtrl &ListCtrl = GetListCtrl();

	    str.Format("%d ",m_Increase);
	    lvitem.mask=LVIF_TEXT;
        lvitem.iItem= 0;
        lvitem.iSubItem= 1;
        lvitem.pszText=str.GetBuffer(5);
        ListCtrl.SetItem(&lvitem);	
	}
}


BOOL CMyView3::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	KillTimer(2);

	return CListView::DestroyWindow();
}

int CMyView3::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;
}

⌨️ 快捷键说明

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