• 大小: 275KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: C/C++
  • 标签: 绘图板  

资源简介

MFC架构设计的绘图板小程序 只附上了源代码还有可执行文件 可以重绘、撤销、橡皮擦这些操作,通过调用重绘函数ondraw实现,有兴趣的请下载看看。

资源截图

代码片段和文件信息


// ChildView.cpp : CChildView 类的实现
//程序窗口功能全都在此文件
//绘制功能、设置画笔功能、撤销操作功能、橡皮功能

#include “stdafx.h“
#include “MFCApplication3.h“
#include “ChildView.h“
#include “Graph.h“
#include “PostMessageDlg.h“
#include 
using namespace std;

#ifdef _DEBUG
#define new DEBUG_NEW
#define DRAW_LINE 1
#define DRAW_ELLIPSE 2
#define DRAW_RECTANGLE 3
#endif


// CChildView

CChildView::CChildView()
{
flag=-1;do_flag=-1; i=0; pen_size=0; pen_color = RGB(000);a=0;
cho_pen[0].CreatePen(PS_SOLID 1 RGB(000));//w_cho_pen[0].CreatePen(PS_SOLID 10 RGB(000));
}

CChildView::~CChildView()
{
}


BEGIN_MESSAGE_MAP(CChildView CWnd)
ON_WM_PAINT()
ON_COMMAND(ID_LINE &CChildView::OnLine)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
// ON_COMMAND(ID_PEN &CChildView::OnPen)
ON_COMMAND(ID_ELLIPSE &CChildView::OnEllipse)
ON_COMMAND(ID_ENDPAINT &CChildView::OnEndpaint)
// ON_COMMAND(ID_SAVE &CChildView::OnSave)
//ON_COMMAND(ID_CLOSE &CChildView::OnClose)
ON_COMMAND(ID_ANYDRAW &CChildView::OnAnydraw)
ON_COMMAND(ID_RECTANGLE &CChildView::OnRectangle)
//ON_COMMAND(ID_SET_PEN &CChildView::OnSetPen)
ON_COMMAND(ID_pencolor &CChildView::Onpencolor)
ON_COMMAND(ID_pensize &CChildView::Onpensize)
ON_COMMAND(ID_CANCLE &CChildView::OnCancle)
ON_COMMAND(ID_ERASER &CChildView::OnEraser)
END_MESSAGE_MAP()



// CChildView 消息处理程序

BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;

cs.dwExstyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS 
::LoadCursor(NULL IDC_ARROW) reinterpret_cast(COLOR_WINDOW+1) NULL);

return TRUE;
}

void CChildView::OnPaint() 
{
CPaintDC dc(this); // 用于绘制的设备上下文

// TODO: 在此处添加消息处理程序代码
OnDraw(&dc);
// 不要为绘制消息而调用 CWnd::OnPaint()
}

void CChildView::OnDraw(CDC* pDC)                                                //真正完成重绘操作的函数
{
int n = ptr.GetSize(); 
for(int j=0; j {
CPen pen;pen.CreatePen(PS_SOLID ((CGraph*)ptr.GetAt(j))->m_cSize ((CGraph*)ptr.GetAt(j))->m_cColor);
pDC->Selectobject(&pen);
switch(((CGraph*)ptr.GetAt(j))->m_nDrawType)
{
case DRAW_LINE:                                                  //直线、涂鸦、橡皮的重绘
pDC->MoveTo(((CGraph*)ptr.GetAt(j))->m_ptOrigin);
pDC->LineTo(((CGraph*)ptr.GetAt(j))->m_ptEnd);
break;
case DRAW_ELLIPSE:                                               //椭圆重绘
pDC->Ellipse(((CGraph*)ptr.GetAt(j))->m_ptOrigin.x ((CGraph*)ptr.GetAt(j))->m_ptOrigin.y 
((CGraph*)ptr.GetAt(j))->m_ptEnd.x ((CGraph*)ptr.GetAt(j))->m_ptEnd.y);
break;
case DRAW_RECTANGLE:                                              //矩形重绘
pDC->Rectangle(((CGraph*)ptr.GetAt(j))->m_ptOrigin.x ((CGraph*)ptr.GetAt(j))->m_ptOrigin.y 
((CGraph*)ptr.GetAt(j))->m_ptEnd.x ((CGraph*)ptr.GetAt

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-01-12 22:54  Source\
     文件        7561  2015-01-10 02:26  Source\ChildView.cpp
     文件        1083  2015-01-10 01:45  Source\ChildView.h
     文件         302  2015-01-04 15:44  Source\Graph.cpp
     文件         283  2015-01-04 15:44  Source\Graph.h
     文件        1807  2014-12-27 10:31  Source\MainFrm.cpp
     文件         745  2014-12-27 10:31  Source\MainFrm.h
     文件        2603  2014-12-27 10:31  Source\MFCApplication3.cpp
     文件      203264  2015-01-10 01:47  Source\MFCApplication3.exe
     文件         574  2014-12-27 10:31  Source\MFCApplication3.h
     文件        8922  2015-01-10 01:15  Source\MFCApplication3.rc
     文件        1264  2015-01-10 01:16  Source\PostMessageDlg.cpp
     文件         529  2015-01-10 01:15  Source\PostMessageDlg.h
     文件        3350  2014-12-27 10:31  Source\ReadMe.txt
     文件        2509  2015-01-10 00:48  Source\resource.h
     文件         148  2014-12-27 10:31  Source\stdafx.cpp
     文件         856  2014-12-27 10:31  Source\stdafx.h
     文件         234  2014-12-27 10:31  Source\targetver.h
     文件      177105  2015-01-12 22:54  Source\windows程序设计作业.docx

评论

共有 条评论