myserializeview.cpp
来自「文件包含了很多VC实例」· C++ 代码 · 共 164 行
CPP
164 行
// mySerializeView.cpp : implementation of the CMySerializeView class
//
#include "stdafx.h"
#include "mySerialize.h"
#include "mySerializeDoc.h"
#include "mySerializeView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMySerializeView
#include "Worker.h"
IMPLEMENT_DYNCREATE(CMySerializeView, CFormView)
BEGIN_MESSAGE_MAP(CMySerializeView, CFormView)
//{{AFX_MSG_MAP(CMySerializeView)
ON_BN_CLICKED(IDC_BUTTON1, OnInsert)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMySerializeView construction/destruction
CMySerializeView::CMySerializeView()
: CFormView(CMySerializeView::IDD)
{
//{{AFX_DATA_INIT(CMySerializeView)
m_strName = _T("");
m_nMoney = 0;
//}}AFX_DATA_INIT
// TODO: add construction code here
m_position = NULL;
}
CMySerializeView::~CMySerializeView()
{
}
void CMySerializeView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMySerializeView)
DDX_Text(pDX, IDC_EDIT1, m_strName);
DDX_Text(pDX, IDC_EDIT2, m_nMoney);
//}}AFX_DATA_MAP
}
BOOL CMySerializeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CMySerializeView::OnInitialUpdate()
{
m_pList = GetDocument()->GetList();
CFormView::OnInitialUpdate();
}
/////////////////////////////////////////////////////////////////////////////
// CMySerializeView printing
BOOL CMySerializeView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMySerializeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMySerializeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CMySerializeView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CMySerializeView diagnostics
#ifdef _DEBUG
void CMySerializeView::AssertValid() const
{
CFormView::AssertValid();
}
void CMySerializeView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CMySerializeDoc* CMySerializeView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMySerializeDoc)));
return (CMySerializeDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMySerializeView message handlers
void CMySerializeView::GetEntry(POSITION position)
{
if (position)
{
CWorker* pworker = m_pList->GetAt(position);
m_strName = pworker->m_strName;
m_nMoney = pworker->m_nMoney;
}
else
{
return;
}
UpdateData(FALSE);
}
void CMySerializeView::OnInsert()
{
InsertEntry(m_position);
GetDocument()->SetModifiedFlag();
GetDocument()->UpdateAllViews(this);
}
void CMySerializeView::InsertEntry(POSITION position)
{
if (UpdateData(TRUE))
{
CWorker* pWorker = new CWorker;
pWorker->m_strName = m_strName;
pWorker->m_nMoney = m_nMoney;
m_position = m_pList->InsertAfter(m_position, pWorker);
}
}
void CMySerializeView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
m_position = m_pList->GetHeadPosition();
GetEntry(m_position); // initial data for view
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?