【VC开源代码栏目提醒】:以下是网学会员为您推荐的VC开源代码-ex31View.cpp,希望本篇文章对您学习有所帮助。
// ex31View.cpp : Cex31View 类的实现
//
#include "stdafx.h"
#include "ex31.h"
#include "ex31Doc.h"
#include "ex31View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Cex31View
IMPLEMENT_DYNCREATE(Cex31View, CView)
BEGIN_MESSAGE_MAP(Cex31View, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
// Cex31View 构造/销毁
Cex31View::Cex31View(): m_rect(10,10, 100, 100)
{
// TODO: 在此处添加构造代码
m_nColor = LTGRAY_BRUSH;
}
Cex31View::~Cex31View()
{
}
BOOL Cex31View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
// 样式
return CView::PreCreateWindow(cs);
}
// Cex31View 绘制
void Cex31View::OnDraw(CDC* pDC)
{
pDC->SelectStockObject(m_nColor); //打开 (CDC* /* pDC */) 中的 pDC
pDC->Rectangle(m_rect);
}
// Cex31View 打印
BOOL Cex31View::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void Cex31View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 打印前添加额外的初始化
}
void Cex31View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 打印后添加清除过程
}
// Cex31View 诊断
#ifdef _DEBUG
void Cex31View::AssertValid() const
{
CView::AssertValid();
}
void Cex31View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
Cex31Doc* Cex31View::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(Cex31Doc)));
return (Cex31Doc*)m_pDocument;
}
#endif //_DEBUG
// Cex31View 消息处理
程序 void Cex31View::OnLButtonDown(UINT nFlags, CPoint point)
{
if (m_rect.PtInRect(point))
{
if (m_nColor == LTGRAY_BRUSH) m_nColor = WHITE_BRUSH;
else m_nColor = LTGRAY_BRUSH;
InvalidateRect(m_rect);
}
}