【VC开源代码栏目提醒】:本文主要为网学会员提供CPaint_3View.cpp,希望对需要CPaint_3View.cpp网友有所帮助,学习一下!
// CPaint_3View.cpp : implementation of the CCPaint_3View class
//
#include "stdafx.h"
#include "CPaint_3.h"
#include "CPaint_3Doc.h"
#include "CPaint_3View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCPaint_3View
IMPLEMENT_DYNCREATE(CCPaint_3View, CView)
BEGIN_MESSAGE_MAP(CCPaint_3View, CView)
//{{AFX_MSG_MAP(CCPaint_3View)
ON_COMMAND(IDM_DIAN, OnDian)
ON_COMMAND(IDM_JUXING, OnJuxing)
ON_COMMAND(IDM_TUOYUAN, OnTuoyuan)
ON_COMMAND(IDM_ZHIXIAN, OnZhixian)
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()
/////////////////////////////////////////////////////////////////////////////
// CCPaint_3View construction/destruction
CCPaint_3View::CCPaint_3View()
{
// TODO: add construction code here
m_type=0;
m_point=0;
}
CCPaint_3View::~CCPaint_3View()
{
}
BOOL CCPaint_3View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCPaint_3View drawing
void CCPaint_3View::OnDraw(CDC* pDC)
{
CCPaint_3Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCPaint_3View printing
BOOL CCPaint_3View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCPaint_3View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCPaint_3View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCPaint_3View diagnostics
#ifdef _DEBUG
void CCPaint_3View::AssertValid() const
{
CView::AssertValid();
}
void CCPaint_3View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCPaint_3Doc* CCPaint_3View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCPaint_3Doc)));
return (CCPaint_3Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCPaint_3View message handlers
void CCPaint_3View::OnDian()
{
// TODO: Add your command handler code here
m_type=1;
}
void CCPaint_3View::OnJuxing()
{
// TODO: Add your command handler code here
m_type=3;
}
void CCPaint_3View::OnTuoyuan()
{
// TODO: Add your command handler code here
m_type=4;
}
void CCPaint_3View::OnZhixian()
{
// TODO: Add your command handler code here
m_type=2;
}
void CCPaint_3View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_point=point;
CView::OnLButtonDown(nFlags, point);
}
void CCPaint_3View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CPen pen(PS_SOLID,1,RGB(255,0,0));
dc.SelectObject(&pen);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
dc.SelectObject(pBrush);
switch(m_type)
{
case 1:
dc.SetPixel(point,RGB(255,0,0));
break;
case 2:
dc.MoveTo(m_point);
dc.LineTo(point);
break;
case 3:
dc.Rectangle(CRect(m_point,point)); //画一个矩形
break;
case 4:
dc.Ellipse(CRect(m_point,point));
break;
}
CView::OnLButtonUp(nFlags, point);
}
上一篇:
CPaint_3Doc.cpp
下一篇:
爱情只不过就是,爱与不爱