⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zfview.cpp

📁 简单的画图程序
💻 CPP
字号:
// zfView.cpp : implementation of the CZfView class
//

#include "stdafx.h"
#include "zf.h"

#include "zfDoc.h"
#include "zfView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CZfView

IMPLEMENT_DYNCREATE(CZfView, CView)

BEGIN_MESSAGE_MAP(CZfView, CView)
	//{{AFX_MSG_MAP(CZfView)
	ON_WM_LBUTTONDOWN()
	ON_WM_CANCELMODE()
	ON_WM_LBUTTONUP()
	ON_WM_CAPTURECHANGED()
	ON_COMMAND(IDM_POINT, OnPoint)
	ON_COMMAND(IDM_LINE, OnLine)
	ON_COMMAND(IDM_CIRCLE, OnCircle)
	ON_COMMAND(IDM_CRECT, OnCrect)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CZfView construction/destruction

CZfView::CZfView()
{
	// TODO: add construction code here
   type =0;
   point1=0;
}

CZfView::~CZfView()
{
}

BOOL CZfView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CZfView drawing

void CZfView::OnDraw(CDC* pDC)
{
	CZfDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CZfView printing

BOOL CZfView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CZfView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CZfView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CZfView diagnostics

#ifdef _DEBUG
void CZfView::AssertValid() const
{
	CView::AssertValid();
}

void CZfView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CZfDoc* CZfView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CZfDoc)));
	return (CZfDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CZfView message handlers

void CZfView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	point1=point;

	CView::OnLButtonDown(nFlags, point);
}

void CZfView::OnCancelMode() 
{
	CView::OnCancelMode();
	
	// TODO: Add your message handler code here
	
}

void CZfView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CClientDC dc(this);
	CPen  pen1;
 	pen1.CreatePen(4,6,col1);
    dc.SelectObject(&pen1);
	switch(type)
	{
	case 1: dc.SetPixel(point,col1);
		break;
	case 2: dc.MoveTo(point1);
		   dc.LineTo(point);
		   break;
	case 3: dc.Ellipse(CRect(point1,point));
		break;
	case 4:  dc.Rectangle(CRect(point1,point));
		break;
	}
	//dc.MoveTo(point1);
	//dc.LineTo(point);
	CView::OnLButtonUp(nFlags, point);
}

void CZfView::OnCaptureChanged(CWnd *pWnd) 
{
	// TODO: Add your message handler code here
	
	CView::OnCaptureChanged(pWnd);
}

void CZfView::OnPoint() 
{
	// TODO: Add your command handler code here
	type=1;
	CColorDialog d1_color;
	d1_color.DoModal();
	col1=d1_color.GetColor();
}

void CZfView::OnLine() 
{
	// TODO: Add your command handler code here
		type=2;
	CColorDialog d1_color;
	d1_color.DoModal();
	col1=d1_color.GetColor();
}

void CZfView::OnCircle() 
{
	// TODO: Add your command handler code here
		type=3;
	CColorDialog d1_color;
	d1_color.DoModal();
	col1=d1_color.GetColor();
}

void CZfView::OnCrect() 
{
	// TODO: Add your command handler code here
		type=4;
	CColorDialog d1_color;
	d1_color.DoModal();
	col1=d1_color.GetColor();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -