📄 huatuview.cpp
字号:
// huatuView.cpp : implementation of the CHuatuView class
//
#include "stdafx.h"
#include "huatu.h"
#include "huatuDoc.h"
#include "huatuView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHuatuView
IMPLEMENT_DYNCREATE(CHuatuView, CView)
BEGIN_MESSAGE_MAP(CHuatuView, CView)
//{{AFX_MSG_MAP(CHuatuView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CHuatuView construction/destruction
CHuatuView::CHuatuView()
{
// TODO: add construction code here
}
CHuatuView::~CHuatuView()
{
}
BOOL CHuatuView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CHuatuView drawing
void CHuatuView::OnDraw(CDC* pDC)
{
CHuatuDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CPoint pointfrom,pointto;
UINT udrawtype;
for(int i=0;i<=pDoc->m_nrectindex;i++)
{ pointfrom=pDoc->m_srectangles[i].pointfrom;
pointto=pDoc->m_srectangles[i].pointto;
udrawtype=pDoc->m_srectangles[i].udrawtype;
switch(udrawtype)
{ case 1:
pDC->Rectangle(pointfrom.x,pointfrom.y,pointto.x,pointto.y);
break;
case 2:
pDC->MoveTo(pointfrom.x,pointfrom.y);
pDC->LineTo(pointto.x,pointto.y);
break;
case 3:
CRect CirRect(pointfrom,pointto);
CPoint pointcir(pointfrom.x,(pointfrom.y+pointto.y)/2);
//CPoint pointcir((pointfrom.x+pointto.x)/2,(pointfrom.y+pointto.y)/2);
//CRect Rectangle(pointfrom.x,pointfrom.y,(pointfrom.x+20),(pointfrom.y+20));
pDC->Arc(CirRect,pointcir,pointcir);
//pDC->Ellipse(Rectangle);
break;
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CHuatuView printing
BOOL CHuatuView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CHuatuView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CHuatuView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CHuatuView diagnostics
#ifdef _DEBUG
void CHuatuView::AssertValid() const
{
CView::AssertValid();
}
void CHuatuView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CHuatuDoc* CHuatuView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHuatuDoc)));
return (CHuatuDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHuatuView message handlers
void CHuatuView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CHuatuDoc *pDoc=GetDocument();
UINT udrawtype=pDoc->m_udrawtype;
if(udrawtype>=1 && udrawtype<=3)
{ if(pDoc->m_nrectindex<99)
{ pDoc->m_blbuttondown=true;
pDoc->m_nrectindex++;
pDoc->m_srectangles[pDoc->m_nrectindex].pointfrom=point;
pDoc->m_srectangles[pDoc->m_nrectindex].udrawtype=udrawtype;
pDoc->SetModifiedFlag();
}
else
MessageBox("绘制的矩形已达到100个,不能再绘制矩形!");
}
CView::OnLButtonDown(nFlags, point);
}
void CHuatuView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CHuatuDoc *pDoc=GetDocument();
pDoc->m_blbuttondown=false;
CView::OnLButtonUp(nFlags, point);
}
void CHuatuView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CHuatuDoc *pDoc=GetDocument();
if(pDoc->m_blbuttondown==true)
{
{ pDoc->m_srectangles[pDoc->m_nrectindex].pointto=point;
pDoc->UpdateAllViews(NULL);
}
}
CView::OnMouseMove(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -