📄 drawtestview.cpp
字号:
// DrawTestView.cpp : implementation of the CDrawTestView class
//
#include "stdafx.h"
#include "DrawTest.h"
#include "DrawTestDoc.h"
#include "DrawTestView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDrawTestView
IMPLEMENT_DYNCREATE(CDrawTestView, CView)
BEGIN_MESSAGE_MAP(CDrawTestView, CView)
//{{AFX_MSG_MAP(CDrawTestView)
ON_COMMAND(IDM_LINTTYPE, OnLinttype)
ON_COMMAND(IDM_LINEWIDTH, OnLinewidth)
ON_COMMAND(IDM_LINECOLOR, OnLinecolor)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CDrawTestView construction/destruction
CDrawTestView::CDrawTestView()
{
// TODO: add construction code here
m_lineType=2;
m_lineColor=RGB(0,0,255);
m_lineWidth=1;
m_fill=FALSE;
}
CDrawTestView::~CDrawTestView()
{
}
BOOL CDrawTestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDrawTestView drawing
void CDrawTestView::OnDraw(CDC* pDC)
{
CDrawTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int n;
n=m_obArray.GetSize();
for(int i=0;i<n;i++)
{
((CGraph*)m_obArray.GetAt(i))->Draw(pDC);
}
}
/////////////////////////////////////////////////////////////////////////////
// CDrawTestView printing
BOOL CDrawTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDrawTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDrawTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDrawTestView diagnostics
#ifdef _DEBUG
void CDrawTestView::AssertValid() const
{
CView::AssertValid();
}
void CDrawTestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CDrawTestDoc* CDrawTestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDrawTestDoc)));
return (CDrawTestDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDrawTestView message handlers
void CDrawTestView::OnLinttype()
{
// TODO: Add your command handler code here
CDlgLinetype dlg;
m_fill=FALSE;
if(IDOK==dlg.DoModal())
{
m_lineType=dlg.m_lineType;
switch(m_lineType)
{
case 3:
if(IDOK==MessageBox("需要填充矩形么?","填充矩形?",MB_OKCANCEL))
m_fill=TRUE;
break;
case 4:
if(IDOK==MessageBox("需要填充椭圆么?","填充椭圆?",MB_OKCANCEL))
m_fill=TRUE;
break;
}
}
}
void CDrawTestView::OnLinewidth()
{
// TODO: Add your command handler code here
CDlgLinewidth dlg;
if(IDOK==dlg.DoModal())
m_lineWidth=dlg.m_lineWidth;
}
void CDrawTestView::OnLinecolor()
{
// TODO: Add your command handler code here
CColorDialog dlg;
if(IDOK==dlg.DoModal())
{
m_lineColor=dlg.GetColor();
}
}
void CDrawTestView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptOrg=point;
CView::OnLButtonDown(nFlags, point);
}
void CDrawTestView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CBrush* pOldbrush=(CBrush*)dc.SelectStockObject(NULL_BRUSH);
CPen pen;
pen.CreatePen(PS_SOLID,m_lineWidth,m_lineColor);
CPen* pOldpen=dc.SelectObject(&pen);
switch(m_lineType)
{
case 1:
dc.SetPixel(point,m_lineColor);
break;
case 2:
dc.MoveTo(m_ptOrg);
dc.LineTo(point);
break;
case 3:
dc.Rectangle(CRect(m_ptOrg,point));
if(m_fill)
{
dc.FillSolidRect(CRect(m_ptOrg,point),m_lineColor);
}
break;
case 4:
dc.Ellipse(CRect(m_ptOrg,point));
if(m_fill)
{
CBrush pBrush(m_lineColor);
CRgn rgn;
rgn.CreateEllipticRgn(m_ptOrg.x,m_ptOrg.y,point.x,point.y);
dc.FillRgn(&rgn,&pBrush);
}
break;
// default:
// break;
}
dc.SelectObject(pOldpen);
dc.SelectObject(pOldbrush);
m_ptEnd=point;
CGraph *pGraph=new CGraph(m_lineType,m_ptOrg,m_ptEnd,m_lineColor,m_lineWidth,m_fill);
m_obArray.Add(pGraph);
CView::OnLButtonUp(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -