TestView.cpp
// Test1View.cpp: CTest1View 类的实现
//
#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义,并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "Test1.h"
#endif
#include "Test1Doc.h"
#include "Test1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CTest1View
IMPLEMENT_DYNCREATE(CTest1View, CView)
BEGIN_MESSAGE_MAP(CTest1View, 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()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
// CTest1View 构造/析构
CTest1View::CTest1View() noexcept
{
// TODO: 在此处添加构造代码
}
CTest1View::~CTest1View()
{
}
BOOL CTest1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
return CView::PreCreateWindow(cs);
}
// CTest1View 绘图
void CTest1View::OnDraw(CDC* /*pDC*/)
{
CTest1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
}
// CTest1View 打印
BOOL CTest1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void CTest1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加额外的打印前进行的初始化过程
}
void CTest1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加打印后进行的清理过程
}
// CTest1View 诊断
#ifdef _DEBUG
void CTest1View::AssertValid() const
{
CView::AssertValid();
}
void CTest1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTest1Doc* CTest1View::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTest1Doc)));
return (CTest1Doc*)m_pDocument;
}
#endif //_DEBUG
// CTest1View 消息处理程序
void CTest1View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
p0 = point;
CView::OnLButtonDown(nFlags, point);
}
void CTest1View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
p1 = point;
CDC* pDC = GetDC();
pDC->MoveTo(p0.x, p0.y);
//pDC->LineTo(p1.x, p1.y);//画直线
//pDC->Rectangle(p0.x,p0.y, p1.x,p1.y);//画矩形
pDC->Ellipse(p0.x, p0.y, p1.x, p1.y);
CView::OnLButtonUp(nFlags, point);
}
TestView.h
// Test1View.h: CTest1View 类的接口
//
#pragma once
class CTest1View : public CView
{
protected: // 仅从序列化创建
CTest1View() noexcept;
DECLARE_DYNCREATE(CTest1View)
// 特性
public:
CTest1Doc* GetDocument() const;
// 操作
public:
// 重写
public:
virtual void OnDraw(CDC* pDC); // 重写以绘制该视图
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
// 实现
public:
virtual ~CTest1View();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
CPoint p0, p1;
// 生成的消息映射函数
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
};
#ifndef _DEBUG // Test1View.cpp 中的调试版本
inline CTest1Doc* CTest1View::GetDocument() const
{ return reinterpret_cast<CTest1Doc*>(m_pDocument); }
#endif