ex21view.cpp

来自「一些VC++的经典实例」· C++ 代码 · 共 134 行

CPP
134
字号
// ex21View.cpp : implementation of the CEx21View class
//

#include "stdafx.h"
#include "ex21.h"

#include "ex21Doc.h"
#include "ex21View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEx21View

IMPLEMENT_DYNCREATE(CEx21View, CFormView)

BEGIN_MESSAGE_MAP(CEx21View, CFormView)
	//{{AFX_MSG_MAP(CEx21View)
	ON_COMMAND(ID_RECORD_UPDATE, OnRecordUpdate)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CEx21View construction/destruction

CEx21View::CEx21View()
	: CFormView(CEx21View::IDD)
{
	//{{AFX_DATA_INIT(CEx21View)
	m_vName = _T("");
	m_vMail = _T("");
	//}}AFX_DATA_INIT
	// TODO: add construction code here
}

CEx21View::~CEx21View()
{
}

void CEx21View::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEx21View)
	DDX_Text(pDX, IDC_EDIT1, m_vName);
	DDX_Text(pDX, IDC_EDIT2, m_vMail);
	//}}AFX_DATA_MAP
}

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

	return CFormView::PreCreateWindow(cs);
}

void CEx21View::OnInitialUpdate()
{
	CEx21Doc * pDoc=GetDocument();
	m_vName=pDoc->m_Friend.m_Name;
	m_vMail=pDoc->m_Friend.m_Mail;
	UpdateData(FALSE);
	
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
}

/////////////////////////////////////////////////////////////////////////////
// CEx21View printing

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

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CEx21View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CEx21View message handlers

void CEx21View::OnRecordUpdate() 
{
	// TODO: Add your command handler code here
	UpdateData(TRUE);
	CEx21Doc * pDoc=GetDocument();
	pDoc->m_Friend.m_Name=m_vName;
	pDoc->m_Friend.m_Mail=m_vMail;
	pDoc->SetModifiedFlag();
}

⌨️ 快捷键说明

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