📄 demo_01view.cpp
字号:
// Demo_01View.cpp : implementation of the CDemo_01View class
//
#include "stdafx.h"
#include "Demo_01.h"
#include "Demo_01Doc.h"
#include "Demo_01View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//------------ Demo_01 add -------------------
enum {COLUMN_TYPE, COLUMN_ITEM, COLUMN_MSG, COLUMN_DATA};
//------------- end of add ------------------
/////////////////////////////////////////////////////////////////////////////
// CDemo_01View
IMPLEMENT_DYNCREATE(CDemo_01View, CListView)
BEGIN_MESSAGE_MAP(CDemo_01View, CListView)
//{{AFX_MSG_MAP(CDemo_01View)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDemo_01View construction/destruction
CDemo_01View::CDemo_01View()
{
// TODO: add construction code here
// set the CListCtrl attributes
//------------ Demo_01 add -------------------
m_dwDefaultStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_REPORT;
//------------- end of add ------------------
}
CDemo_01View::~CDemo_01View()
{
}
BOOL CDemo_01View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDemo_01View drawing
void CDemo_01View::OnDraw(CDC* pDC)
{
CDemo_01Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CDemo_01View::OnInitialUpdate()
{
CListView::OnInitialUpdate();
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
//------------ Demo_01 add -------------------
// to create a listview and insert some list column and row
CListCtrl& list = GetListCtrl();
list.DeleteAllItems();
while( list.DeleteColumn( 0 ) )
;
// set checkbox and full-line
list.SetExtendedStyle(LVS_EX_FULLROWSELECT);
list.InsertColumn( COLUMN_TYPE, _T("Type"), LVCFMT_LEFT, 80, 0 );
list.InsertColumn( COLUMN_ITEM, _T("Status"), LVCFMT_LEFT, 150, 0 );
list.InsertColumn( COLUMN_MSG, _T("Message"), LVCFMT_LEFT, 250, 1 );
list.InsertColumn( COLUMN_DATA , _T("Data"), LVCFMT_LEFT, 100, 2 );
CString msg;
msg.Format(_T("Program"));
list.InsertItem(0, msg);
msg.Format(_T("Demo_01"));
list.SetItemText(0, COLUMN_ITEM, msg);
msg.Format(_T("Program Start...."));
list.SetItemText(0, COLUMN_MSG, msg);
msg.Format(_T("0"));
list.SetItemText(0, COLUMN_DATA, msg);
msg.Format(_T("Date/Time"));
list.InsertItem(1, msg);
msg.Format(_T("COM2:"));
list.InsertItem(2, msg);
msg.Format(_T("COM3:"));
list.InsertItem(3, msg);
msg.Format(_T("TCP/IP"));
list.InsertItem(4, msg);
//------------- end of add ------------------
}
/////////////////////////////////////////////////////////////////////////////
// CDemo_01View diagnostics
#ifdef _DEBUG
void CDemo_01View::AssertValid() const
{
CListView::AssertValid();
}
void CDemo_01View::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CDemo_01Doc* CDemo_01View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDemo_01Doc)));
return (CDemo_01Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDemo_01View message handlers
//****************************************************************************
//----------------- Demo_01 add -------------------
int CDemo_01View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
// set up View Windows handle for Document program
CDemo_01Doc* pDoc = GetDocument();
pDoc->SetDemoView( this );
return 0;
}
//****************************************************************************
void CDemo_01View::SetListItem(int row, int itemno, CString msg)
{
CListCtrl& list = GetListCtrl();
list.SetItemText(row, itemno, msg);
}
//--------------- end of add ----------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -