【VC开源代码栏目提醒】:网学会员在VC开源代码频道为大家收集整理了CDoc_1View.cpp提供大家参考,希望对大家有所帮助!
// CDoc_1View.cpp : implementation of the CCDoc_1View class
//
#include "stdafx.h"
#include "CDoc_1.h"
#include "CDoc_1Doc.h"
#include "CDoc_1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCDoc_1View
IMPLEMENT_DYNCREATE(CCDoc_1View, CView)
BEGIN_MESSAGE_MAP(CCDoc_1View, CView)
//{{AFX_MSG_MAP(CCDoc_1View)
ON_COMMAND(IDM_READ, OnRead)
ON_COMMAND(IDM_WRITE, OnWrite)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCDoc_1View construction/destruction
CCDoc_1View::CCDoc_1View()
{
// TODO: add construction code here
}
CCDoc_1View::~CCDoc_1View()
{
}
BOOL CCDoc_1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCDoc_1View drawing
void CCDoc_1View::OnDraw(CDC* pDC)
{
CCDoc_1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCDoc_1View printing
BOOL CCDoc_1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCDoc_1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCDoc_1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCDoc_1View diagnostics
#ifdef _DEBUG
void CCDoc_1View::AssertValid() const
{
CView::AssertValid();
}
void CCDoc_1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCDoc_1Doc* CCDoc_1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCDoc_1Doc)));
return (CCDoc_1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCDoc_1View message handlers
void CCDoc_1View::OnRead()
{
// TODO: Add your command handler code here
CFile file("hello.txt",CFile::modeRead);
CArchive arv(&file,CArchive::load);
int age;
CString str,str2;
arv>>str>>age;
str2.Format("%s %d",str,age);
MessageBox(str2);
}
void CCDoc_1View::OnWrite()
{
// TODO: Add your command handler code here
CFile file("hello.txt",CFile::modeCreate|CFile::modeWrite);
CArchive arv(&file,CArchive::store);
CString str("My age is");
int age=22;
arv<<str<<age;
}