mymdiview.cpp

来自「文件包含了很多VC实例」· C++ 代码 · 共 161 行

CPP
161
字号
// myMDIView.cpp : implementation of the CMyMDIView class
//

#include "stdafx.h"
#include "myMDI.h"

#include "myMDIDoc.h"
#include "myMDIView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyMDIView

IMPLEMENT_DYNCREATE(CMyMDIView, CFormView)

BEGIN_MESSAGE_MAP(CMyMDIView, CFormView)
	//{{AFX_MSG_MAP(CMyMDIView)
	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()

/////////////////////////////////////////////////////////////////////////////
// CMyMDIView construction/destruction

CMyMDIView::CMyMDIView()
	: CFormView(CMyMDIView::IDD)
{
	//{{AFX_DATA_INIT(CMyMDIView)
	m_strName = _T("");
	m_nMoney = 0;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CMyMDIView::~CMyMDIView()
{
}

void CMyMDIView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyMDIView)
	DDX_Text(pDX, IDC_EDIT1, m_strName);
	DDX_Text(pDX, IDC_EDIT2, m_nMoney);
	//}}AFX_DATA_MAP
}

BOOL CMyMDIView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CMyMDIView::OnInitialUpdate()
{
	m_pList = GetDocument()->GetList();
	CFormView::OnInitialUpdate();
}

/////////////////////////////////////////////////////////////////////////////
// CMyMDIView printing

BOOL CMyMDIView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMyMDIView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMyMDIView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CMyMDIView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CMyMDIView diagnostics

#ifdef _DEBUG
void CMyMDIView::AssertValid() const
{
	CFormView::AssertValid();
}

void CMyMDIView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CMyMDIDoc* CMyMDIView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyMDIDoc)));
	return (CMyMDIDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyMDIView message handlers

void CMyMDIView::OnInsert() 
{
    InsertEntry(m_position);
    GetDocument()->SetModifiedFlag();
    GetDocument()->UpdateAllViews(this);	
}


void CMyMDIView::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 CMyMDIView::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 CMyMDIView::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 + -
显示快捷键?