mydocvview.cpp
来自「文件包含了很多VC实例」· C++ 代码 · 共 185 行
CPP
185 行
// myDocVView.cpp : implementation of the CMyDocVView class
//
#include "stdafx.h"
#include "myDocV.h"
#include "myDocVDoc.h"
#include "myDocVView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyDocVView
IMPLEMENT_DYNCREATE(CMyDocVView, CFormView)
BEGIN_MESSAGE_MAP(CMyDocVView, CFormView)
//{{AFX_MSG_MAP(CMyDocVView)
ON_BN_CLICKED(IDC_BUTTON1, OnInsert)
ON_BN_CLICKED(IDC_BUTTON2, OnForward)
ON_BN_CLICKED(IDC_BUTTON3, OnNext)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMyDocVView construction/destruction
CMyDocVView::CMyDocVView()
: CFormView(CMyDocVView::IDD)
{
//{{AFX_DATA_INIT(CMyDocVView)
m_strName = _T("");
m_nMoney = 0;
//}}AFX_DATA_INIT
// TODO: add construction code here
m_position = NULL;
}
CMyDocVView::~CMyDocVView()
{
}
void CMyDocVView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDocVView)
DDX_Text(pDX, IDC_EDIT1, m_strName);
DDX_Text(pDX, IDC_EDIT2, m_nMoney);
//}}AFX_DATA_MAP
}
BOOL CMyDocVView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CMyDocVView::OnInitialUpdate()
{
m_pList = GetDocument()->GetList();
CFormView::OnInitialUpdate();
//GetParentFrame()->RecalcLayout();
//ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CMyDocVView printing
BOOL CMyDocVView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyDocVView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyDocVView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CMyDocVView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CMyDocVView diagnostics
#ifdef _DEBUG
void CMyDocVView::AssertValid() const
{
CFormView::AssertValid();
}
void CMyDocVView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CMyDocVDoc* CMyDocVView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDocVDoc)));
return (CMyDocVDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyDocVView message handlers
void CMyDocVView::OnInsert()
{
InsertEntry(m_position);
GetDocument()->SetModifiedFlag();
GetDocument()->UpdateAllViews(this);
}
void CMyDocVView::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 CMyDocVView::OnForward()
{
POSITION pos;
if ((pos = m_position) != NULL) {
m_pList->GetPrev(pos);
if (pos) {
GetEntry(pos);
m_position = pos;
}
}
}
void CMyDocVView::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 CMyDocVView::OnNext()
{
POSITION pos;
if ((pos = m_position) != NULL)
{
m_pList->GetNext(pos);
if (pos)
{
GetEntry(pos);
m_position = pos;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?