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

📄 guoyue12_13view.cpp

📁 简单扼要的画图程序,基于MFC的程序实现画图的功能
💻 CPP
字号:
// guoyue12_13View.cpp : implementation of the CGuoyue12_13View class
//

#include "stdafx.h"
#include "guoyue12_13.h"

#include "guoyue12_13Doc.h"
#include "guoyue12_13View.h"
#include"MainFrm.h"
#include"SettingDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGuoyue12_13View

IMPLEMENT_DYNCREATE(CGuoyue12_13View, CView)

BEGIN_MESSAGE_MAP(CGuoyue12_13View, CView)
	//{{AFX_MSG_MAP(CGuoyue12_13View)
	ON_WM_MOUSEMOVE()
	ON_COMMAND(IDM_ELLIPSE, OnEllipse)
	ON_COMMAND(IDM_LINE, OnLine)
	ON_COMMAND(IDM_POINT, OnPoint)
	ON_COMMAND(IDM_RETANGLE, OnRetangle)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_COMMAND(IDM_SETTING, OnSetting)
	ON_COMMAND(IDM_COLOR, OnColor)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CGuoyue12_13View construction/destruction

CGuoyue12_13View::CGuoyue12_13View()
{
	m_nDrawtype=0;
	m_ptOrigin=0;
	m_nLineWidth=0;
	m_nLineStyle=0;
	m_cir=RGB(255,0,0);

	// TODO: add construction code here

}

CGuoyue12_13View::~CGuoyue12_13View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CGuoyue12_13View drawing

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

/////////////////////////////////////////////////////////////////////////////
// CGuoyue12_13View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CGuoyue12_13View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CGuoyue12_13View message handlers

//鼠标移动显示
void CGuoyue12_13View::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CString str;
	str.Format("x=%d,y=%d",point.x,point.y);
	((CMainFrame*)GetParent())->SetMessageText(str);
	
	CView::OnMouseMove(nFlags, point);
}


void CGuoyue12_13View::OnEllipse() 
{	
	m_nDrawtype=4;
	// TODO: Add your command handler code here
	
}

void CGuoyue12_13View::OnLine() 
{	
	m_nDrawtype=2;
	// TODO: Add your command handler code here
	
}

void CGuoyue12_13View::OnPoint() 
{
	// TODO: Add your command handler code here
	m_nDrawtype=1;
	
}

void CGuoyue12_13View::OnRetangle() 
{	
	m_nDrawtype=3;
	// TODO: Add your command handler code here
	
}


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

void CGuoyue12_13View::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CClientDC dc(this);
	CPen pen(m_nLineStyle,m_nLineWidth,	m_cir);
	dc.SelectObject(&pen);
	CBrush*pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
    dc.SelectObject(pBrush);
	switch(m_nDrawtype)
	{
	case 1:
		dc.SetPixel(point,	m_cir);
		break;
	case 2:
		dc.MoveTo(m_ptOrigin);
		dc.LineTo(point);
		break;
	case 3:
		dc.Rectangle(CRect(m_ptOrigin,point));
		break;
	case 4:
		dc.Ellipse(CRect(m_ptOrigin,point));
		break;
	}

	CView::OnLButtonUp(nFlags, point);
}

void CGuoyue12_13View::OnSetting() 
{
	// TODO: Add your command handler code here
	CSettingDlg dlg;
	dlg.m_nLineWidth=m_nLineWidth;
	dlg.m_nLineStyle=m_nLineStyle;
	if(IDOK==dlg.DoModal())
	{
		m_nLineWidth=dlg.m_nLineWidth;
		m_nLineStyle=dlg.m_nLineStyle;
	}
	
}

void CGuoyue12_13View::OnColor() 
{
	// TODO: Add your command handler code here
	CColorDialog dlg;
	dlg.m_cc.Flags|=CC_RGBINIT|CC_FULLOPEN;
	dlg.m_cc.rgbResult=m_cir;
	if(IDOK==dlg.DoModal())
	{
		m_cir=dlg.m_cc.rgbResult;
	}
	
}

⌨️ 快捷键说明

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