<repo_name>AME1314/Life<file_sep>/MyPaint/resource.h
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by MyPaint.rc
//
#define IDD_ABOUTBOX                    100
#define IDR_MAINFRAME                   128
#define IDR_MYPAINTYPE                  129
#define IDR_Paint                       140
#define ID_PAINTCURVE                   32778
#define ID_PAINTLINE                    32781
#define ID_PAINTOVAL                    32782
#define ID_PAINTRECTANGLE               32783
#define ID_PAINTOVAL_SOLID              32784
#define ID_PAINTRECTANGLE_SOLID         32785
#define ID_PAINTREASER                  32786
#define ID_PAINTFILL                    32787
#define ID_PAINTRED                     32788
#define ID_PAINTGREEN                   32789
#define ID_PAINTBLUE                    32790
#define ID_PAINTCOLOR                   32791

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS                     1
#define _APS_NEXT_RESOURCE_VALUE        142
#define _APS_NEXT_COMMAND_VALUE         32792
#define _APS_NEXT_CONTROL_VALUE         1000
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif
<file_sep>/MyPaint/FillColor.h
// FillColor.h: interface for the CFillColor class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_FILLCOLOR_H__FF1A07FD_D834_48CE_A9BA_D6B7BC2AF3BE__INCLUDED_)
#define AFX_FILLCOLOR_H__FF1A07FD_D834_48CE_A9BA_D6B7BC2AF3BE__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "P2.h"
class CFillColor  
{
public:
	typedef struct LNode{
		struct LNode *front;
		CPoint FillPoint;
		struct LNode *next;
	}LNode;
public:
	CFillColor();
	virtual ~CFillColor();
	LNode*p;
	CPoint OriginalP;
	void InitList_L(LNode*);
	void DestoryList_L(LNode*);
	void ListInsert_L(LNode*,CPoint,LNode*);
	void ListDelete_L(LNode*,LNode*);
	void ListFillStart(CDC*,CPoint,CRGB);
	void ListFillColor(CDC*,LNode*,CPoint,CRGB,LNode*);
};


#endif // !defined(AFX_FILLCOLOR_H__FF1A07FD_D834_48CE_A9BA_D6B7BC2AF3BE__INCLUDED_)
<file_sep>/MyPaint/RGB.cpp
// RGB.cpp: implementation of the CRGB class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MyPaint.h"
#include "RGB.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CRGB::CRGB()
{
	this->red=0.0;
	this->green=0.0;
	this->blue=0.0;
}
CRGB::CRGB(double r,double g,double b)
{
	this->red=r;
	this->green=g;
	this->blue=b;
}
CRGB::~CRGB()
{
	
}
CRGB operator +(CRGB &c1,CRGB &c2)
{
	CRGB c;
	c.red=c1.red+c2.red;
	c.green=c1.green+c2.green;
	c.blue=c1.blue+c2.blue;
	return c;
}
CRGB operator *(double k,CRGB &c1)
{
	CRGB c;
	c.red=k*c1.red;
	c.green=k*c1.green;
	c.blue=k*c1.blue;
	return c;
}
<file_sep>/MyPaint/Circle.h
// Circle.h: interface for the CCircle class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_CIRCLE_H__D2ABBED0_0D5D_4100_BAE3_C0716952BBC7__INCLUDED_)
#define AFX_CIRCLE_H__D2ABBED0_0D5D_4100_BAE3_C0716952BBC7__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include"RGB.h"
#include"P2.h"
class CCircle  
{
public:
	CCircle();
	virtual ~CCircle();
	void Mbellipse(CDC*,CP2,CP2);
	void EllipsePoint(CDC*,double,double,CP2);
};

#endif // !defined(AFX_CIRCLE_H__D2ABBED0_0D5D_4100_BAE3_C0716952BBC7__INCLUDED_)
<file_sep>/MyPaint/Circle.cpp
// Circle.cpp: implementation of the CCircle class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MyPaint.h"
#include "Circle.h"
#define ROUND(x) ( (int)(x + 0.5) )
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCircle::CCircle()
{

}

CCircle::~CCircle()
{

}
void CCircle::Mbellipse(CDC*pDC,CP2 p1,CP2 p2)//椭圆的Bresenham算法
{
	double x,y,d1,d2;
	x=0;y=p1.y;
	d1=p1.y*p1.y+p1.x*p1.x*(-p1.y+0.25);
	EllipsePoint(pDC,x,y,p2);
	while(p1.y*p1.y*(x+1)<p1.x*p1.x*(y-0.5))//椭圆AC弧段
	{
		if (d1<0)
		{
			d1+=p1.y*p1.y*(2*x+3);
		}
		else
		{
			d1+=p1.y*p1.y*(2*x+3)+p1.x*p1.x*(-2*y+2);
			y--;
		}
		x++;
		EllipsePoint(pDC,x,y,p2);
	}
	d2=p1.y*p1.y*(x+0.5)*(x+0.5)+p1.x*p1.x*(y-1)*(y-1)-p1.x*p1.x*p1.y*p1.y;//椭圆CB弧段
	while(y>0)
	{
		if (d2<0)
		{
			d2+=p1.y*p1.y*(2*x+2)+p1.x*p1.x*(-2*y+3);
			x++;
		}
		else
		{
			d2+=p1.x*p1.x*(-2*y+3);
			
		}
		y--;
		EllipsePoint(pDC,x,y,p2);
	}
}
void CCircle::EllipsePoint(CDC*pDC,double x,double y,CP2 p2)//四分法画椭圆
{
	COLORREF  rgb=RGB(p2.c.red,p2.c.green,p2.c.blue);//定义椭圆的颜色
	pDC->SetPixel(ROUND(x+p2.x),ROUND(y+p2.y),rgb);
	pDC->SetPixel(ROUND(-x+p2.x),ROUND(y+p2.y),rgb);
	pDC->SetPixel(ROUND(x+p2.x),ROUND(-y+p2.y),rgb);
	pDC->SetPixel(ROUND(-x+p2.x),ROUND(-y+p2.y),rgb);
}
<file_sep>/MyPaint/RGB.h
// RGB.h: interface for the CRGB class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_RGB_H__BB668063_548B_4156_A9BA_0C64E3554CE1__INCLUDED_)
#define AFX_RGB_H__BB668063_548B_4156_A9BA_0C64E3554CE1__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CRGB  
{
public:
	CRGB();
	CRGB(double,double,double);
	friend CRGB operator +(CRGB&,CRGB &);
	friend CRGB operator *(double,CRGB &);
	virtual ~CRGB();
public:
	double red;
	double green;
	double blue;
};


#endif // !defined(AFX_RGB_H__BB668063_548B_4156_A9BA_0C64E3554CE1__INCLUDED_)
<file_sep>/MyPaint/MyPaintView.cpp
// MyPaintView.cpp : implementation of the CMyPaintView class
//

#include "stdafx.h"
#include "MyPaint.h"
#include "math.h"
#include "MyPaintDoc.h"
#include "MyPaintView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyPaintView

IMPLEMENT_DYNCREATE(CMyPaintView, CView)

BEGIN_MESSAGE_MAP(CMyPaintView, CView)
	//{{AFX_MSG_MAP(CMyPaintView)
	ON_COMMAND(ID_PAINTLINE, OnPaintline)
	ON_COMMAND(ID_PAINTGREEN, OnPaintgreen)
	ON_COMMAND(ID_PAINTBLUE, OnPaintblue)
	ON_COMMAND(ID_PAINTCOLOR, OnPaintcolor)
	ON_COMMAND(ID_PAINTCURVE, OnPaintcurve)
	ON_COMMAND(ID_PAINTFILL, OnPaintfill)
	ON_COMMAND(ID_PAINTOVAL, OnPaintoval)
	ON_COMMAND(ID_PAINTOVAL_SOLID, OnPaintovalSolid)
	ON_COMMAND(ID_PAINTREASER, OnPaintreaser)
	ON_COMMAND(ID_PAINTRECTANGLE, OnPaintrectangle)
	ON_COMMAND(ID_PAINTRECTANGLE_SOLID, OnPaintrectangleSolid)
	ON_COMMAND(ID_PAINTRED, OnPaintred)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	ON_COMMAND(ID_FILE_SAVE, OnFileSave)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyPaintView construction/destruction

CMyPaintView::CMyPaintView()
{
	// TODO: add construction code here
	m_DrawType = 1;//默认初始绘图状态为绘制直线段
	m_isDraw = true;//当前处于绘图状态
	m_IsDrawIng=false;
	m_hCross=AfxGetApp()->LoadStandardCursor(IDC_CROSS);//定义m_hCross鼠标形状设为十字形
}

CMyPaintView::~CMyPaintView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMyPaintView drawing

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

/////////////////////////////////////////////////////////////////////////////
// CMyPaintView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyPaintView diagnostics

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

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

CMyPaintDoc* CMyPaintView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyPaintDoc)));
	return (CMyPaintDoc*)m_pDocument;
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyPaintView message handlers

void CMyPaintView::OnPaintline() 
{
	// TODO: Add your command handler code here
	m_DrawType = 2;//2表示绘制直线段
	m_isDraw = true;//初始状态为允许左键点下
	m_IsDrawIng=false;//初始状态为绘图状态
	m_endpoint=m_OriginPoint;//初始化起始点与结束点

}

void CMyPaintView::OnPaintred() 
{
	// TODO: Add your command handler code here
	rgbr=255;
	rgbg=0;
	rgbb=0; //颜色变量
}

void CMyPaintView::OnPaintgreen() 
{
	// TODO: Add your command handler code here
	rgbr=0;
	rgbg=255;
	rgbb=0; //颜色变量
}

void CMyPaintView::OnPaintblue() 
{
	// TODO: Add your command handler code here
	rgbr=0;
	rgbg=0;
	rgbb=255; //颜色变量
}

void CMyPaintView::OnPaintcolor() 
{
	// TODO: Add your command handler code here
	CColorDialog dlg;
	dlg.m_cc.Flags|=CC_RGBINIT|CC_FULLOPEN;
	dlg.m_cc.rgbResult=m_clr;
	if (IDOK==dlg.DoModal())
	{
		m_clr=dlg.m_cc.rgbResult;
	}
	rgbr=GetRValue(m_clr);//将所选颜色分离并放入相应变量中
	rgbb=GetBValue(m_clr);
	rgbg=GetGValue(m_clr);
}

void CMyPaintView::OnPaintcurve() 
{
	// TODO: Add your command handler code here
	m_DrawType = 1;//1表示画笔
	m_isDraw = true;//初始状态为允许左键点下
	m_IsDrawIng=false;//初始状态为绘图状态

}

void CMyPaintView::OnPaintfill() 
{
	// TODO: Add your command handler code here
	m_DrawType=6;//6表示种子填充  
	m_isDraw=true;//当前处于绘图状态  
	m_IsDrawIng=false;  
}

void CMyPaintView::OnPaintoval() 
{
	// TODO: Add your command handler code here
	m_DrawType = 3;//3表示椭圆
	m_isDraw=true;//初始状态为允许左键点下
	m_IsDrawIng=false;//初始状态为绘图状态
}

void CMyPaintView::OnPaintovalSolid() 
{
	// TODO: Add your command handler code here
	m_DrawType=7;//7表示椭圆区域
	m_isDraw=true;//当前处于绘图状态
	m_IsDrawIng=false;
}

void CMyPaintView::OnPaintreaser() 
{
	// TODO: Add your command handler code here
	m_DrawType=5;//5表示橡皮擦
	m_isDraw=true;//初始状态为允许左键点下
	m_IsDrawIng=false;//初始状态为绘图状态
}

void CMyPaintView::OnPaintrectangle() 
{
	// TODO: Add your command handler code here
	m_DrawType=4;//4表示矩形
	m_isDraw=true;//初始状态为允许左键点下
	m_IsDrawIng=false;//初始状态为绘图状态

}

void CMyPaintView::OnPaintrectangleSolid() 
{
	// TODO: Add your command handler code here
	m_DrawType=8;//8表示矩形区域
	m_isDraw=true;//当前处于绘图状态
	m_IsDrawIng=false;
}

void CMyPaintView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	SetCapture();		//将鼠标消息发送到视窗口
	CRect rect;
	GetClientRect(&rect);	//得到客户窗口的大小
	ClientToScreen(&rect);	//将当前窗口坐标转换成屏幕坐标
	ClipCursor(&rect);		//把鼠标限定在指定的矩形区域内(矩形内，也就是当前窗口内)
	SetCursor(m_hCross);	//把鼠标指针形状设为十字形

	if (m_isDraw)
	{	
		m_IsDrawIng=true;//将程序运行状态变为TURE
		m_OriginPoint.x=point.x;//初始化m_OriginPoint
		m_OriginPoint.y=point.y;	
		m_OriginPoint.c.red=rgbr;
		m_OriginPoint.c.blue=rgbb;
		m_OriginPoint.c.green=rgbg;	
		m_StartPoint=point;//初始化m_StartPoint
		m_EndPoint=point;//初始化m_EndPoint
	}
	if (m_DrawType==5)
	{
		CClientDC dc(this);	
		CPen * pOldPen;  //保存画笔
		CPen SolidPen(PS_SOLID,20,RGB(255,255,255));  //定义画笔
		pOldPen=dc.SelectObject(&SolidPen);  //
		dc.SetROP2(R2_COPYPEN);		//设置绘画模式 
		dc.MoveTo(m_StartPoint);	//这两行代码从起点到鼠标当前位置画线
		dc.LineTo(point);
		m_StartPoint=point;
	}

	CView::OnLButtonDown(nFlags, point);
}

void CMyPaintView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if (m_IsDrawIng&&m_DrawType==1)//画笔
	{
		DrawMouseMove(nFlags,point);
	}
	if (m_IsDrawIng&&m_DrawType==2)//直线段
	{
		DrawMouseMove(nFlags,point);
	}
	if (m_IsDrawIng&&m_DrawType==5)//橡皮  
	{  
        DrawMouseMove(nFlags,point);  
	}  
	if (m_IsDrawIng&&m_DrawType==7)//椭圆区域
	{
		DrawMouseMove(nFlags,point);
	}
	if (m_IsDrawIng&&m_DrawType==8)//矩形区域
	{
		DrawMouseMove(nFlags,point);
	}
	CView::OnMouseMove(nFlags, point);
}

void CMyPaintView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	ReleaseCapture();  
	ClipCursor(NULL);  
	if (m_IsDrawIng)
	{
		CClientDC dc(this);//构造设备环境对象
		m_IsDrawIng=false;//将程序状态变为FALSE
		m_endpoint.c.red=rgbr;
		m_endpoint.c.blue=rgbb;
		m_endpoint.c.green=rgbg;
		if (m_DrawType==2)
		{
			DrawLButtonUp(nFlags,point);
		}
		if (m_DrawType==3)
		{	
			DrawLButtonUp(nFlags,point);
		}
		if (m_DrawType==4)
		{
			DrawLButtonUp(nFlags,point);
		}
		if (m_DrawType==6)
		{
			DrawLButtonUp(nFlags,point);
		}

	}
	CView::OnLButtonUp(nFlags, point);
}
void CMyPaintView::DrawLButtonUp(UINT nFlags,CPoint point)
{
	if (m_DrawType==2)//直线段
	{	
		m_endpoint.x=point.x;
		m_endpoint.y=point.y;
		CLine dc;
		CDC*pDC=GetDC();
		dc.MoveTo(pDC,m_OriginPoint);//从点m_OriginPoint画到点m_endpoint
		dc.LineTo(pDC,m_endpoint);
	}
	if (m_DrawType==3)//椭圆
	{	
		CDC*pDC=GetDC();
		CCircle dc;
		m_endpoint.x=fabs(point.x-m_OriginPoint.x)/2;//将点m_endpoint设为椭圆的中心点
		m_endpoint.y=fabs(point.y-m_OriginPoint.y)/2;
		if (m_OriginPoint.x>point.x) //判断当前点与初始点的位置关系，并将m_OriginPoint设为椭圆的A与B。
		{		
			m_OriginPoint.x=m_OriginPoint.x-m_endpoint.x;
		}
		if (m_OriginPoint.y>point.y)
		{	
			m_OriginPoint.y=m_OriginPoint.y-m_endpoint.y;
		}
		if (m_OriginPoint.x<point.x)
		{	
			m_OriginPoint.x=m_OriginPoint.x+m_endpoint.x;
		}
		if (m_OriginPoint.y<point.y)
		{	
			m_OriginPoint.y=m_OriginPoint.y+m_endpoint.y;
		}
		if (nFlags==MK_SHIFT)//在摁下SHIFT后画出的图像为圆形
	{
			m_endpoint.y=m_endpoint.x;
		}
		
		dc.Mbellipse(pDC,m_endpoint,m_OriginPoint);
	}
	if (m_DrawType==4)//矩形
	{	if (m_OriginPoint.x!=point.x&&m_OriginPoint.y!=point.y)//如果初始点等于当前点则不执行该程序
		{		
			CDC *pDC=GetDC();
			CLine dc;
			CP2 a,b,c,d;//设矩阵的四个顶点分别为a、b、c、d
			a.c=m_OriginPoint.c;//初始化abcd
			b.c=m_OriginPoint.c;
			c.c=m_OriginPoint.c;
			d.c=m_OriginPoint.c;
			a=m_OriginPoint;//初始化a为初始点
			b.x=m_OriginPoint.x;
			c.y=m_OriginPoint.y;
			CP2 dt;
			dt.x=fabs(m_OriginPoint.x-point.x);//计算矩阵的长于宽
			dt.y=fabs(m_OriginPoint.y-point.y);	
			if (nFlags==MK_SHIFT)//在摁下SHIFT后图形为正方形
			{
			dt.x=dt.y;
			}
			if (m_OriginPoint.x>point.x)//判断初始点与当前点的位置关系
			{		
				c.x=m_OriginPoint.x-dt.x;
				d.x=a.x-dt.x;
			}
			if (m_OriginPoint.y>point.y)
			{	
				b.y=m_OriginPoint.y-dt.y;
				d.y=a.y-dt.y;
			}
			if (m_OriginPoint.x<point.x)
			{	
				c.x=m_OriginPoint.x+dt.x;
				d.x=a.x+dt.x;
			}
			if (m_OriginPoint.y<point.y)
			{	
				b.y=m_OriginPoint.y+dt.y;
				d.y=a.y+dt.y;
			}
			dc.MoveTo(pDC,a);//将矩阵实现
			dc.LineTo(pDC,b);
			dc.MoveTo(pDC,a);
			dc.LineTo(pDC,c);
			dc.MoveTo(pDC,b);
			dc.LineTo(pDC,d);
			dc.MoveTo(pDC,c);
			dc.LineTo(pDC,d);
		}
	}
	if (m_DrawType==6)//填充
	{
		CRect Rect;
		GetClientRect(&Rect);
		CDC *pDC=GetDC();
		CFillColor color;
		CRGB c;
		c.red=rgbr;
		c.green=rgbg;
		c.blue=rgbb;								  				
		color.ListFillStart(pDC,point,c);
		m_IsDrawIng=false;
	}
}
void CMyPaintView::DrawMouseMove(UINT nFlags,CPoint point)
{

CClientDC dc(this);//构造设备环境对象
	if (m_IsDrawIng&&m_DrawType==1)//判断鼠标移动的同时鼠标左键按下，并且要绘制的是画笔
	{
		CP2 p;					
		p.x=point.x;		//初始化画笔信息
		p.y=point.y;
		p.c.red=rgbr;
		p.c.blue=rgbb;
		p.c.green=rgbg;
		if (m_IsDrawIng)
		{	
			CLine dc;	//绘制画笔
			CDC*pDC=GetDC();
			dc.MoveTo(pDC,m_OriginPoint);
			dc.LineTo(pDC,p);
		}
		m_OriginPoint.x=point.x;
		m_OriginPoint.y=point.y;
	}
	if ( m_IsDrawIng&& m_DrawType == 2)	//判断鼠标移动的同时鼠标左键按下，并且要绘制的是直线段
	{
		CPen * pOldPen;  //保存画笔
		CPen SolidPen(PS_SOLID,1,RGB(rgbr,rgbg,rgbb));  //定义画笔
		pOldPen=dc.SelectObject(&SolidPen);  //
		dc.SetROP2(R2_MERGEPENNOT);//设置绘图模式为R2_MERGEPENNOT，重新绘制前一个鼠标移动消息处理函数绘制的直线段，因为绘图模式的原因，结果是擦除了该线段
		dc.MoveTo(m_StartPoint);
		dc.LineTo(m_EndPoint);
		dc.MoveTo(m_StartPoint);//绘制新的直线段
		dc.LineTo(point);
		m_EndPoint = point;	//保存新的直线段终点
	}
	if (m_IsDrawIng&&m_DrawType==5)  
    {  
        CClientDC dc(this);   
        CPen * pOldPen;  //保存画笔  
        CPen SolidPen(PS_SOLID,20,RGB(255,255,255));  //定义画笔  
        pOldPen=dc.SelectObject(&SolidPen);  //  
        dc.SetROP2(R2_COPYPEN);     //设置绘画模式   
        dc.MoveTo(m_StartPoint);    //这两行代码从起点到鼠标当前位置画线  
        dc.LineTo(point);  
        m_StartPoint=point;       
    }  
	if (m_IsDrawIng&&m_DrawType==7)//椭圆区域
	{
		CClientDC dc(this);	//设备上下
		CPen * pOldPen;//保存画笔
		CPen SolidPen(PS_SOLID,1,RGB(rgbr,rgbg,rgbb));//定义画笔
		pOldPen=dc.SelectObject(&SolidPen);
		dc.SetROP2(R2_NOT);//设置绘画模式R2_NOT用与背景色相反的颜色绘图 
		dc.SetROP2(R2_WHITE);		
		dc.MoveTo(m_StartPoint);//这两行代码是擦除从起点（鼠标按下点）到
		dc.Ellipse(m_StartPoint.x,m_StartPoint.y,m_EndPoint.x,m_EndPoint.y);		//上次鼠标移动到的位置之间的临时线
		dc.SetROP2(R2_COPYPEN);	
		dc.MoveTo(m_StartPoint);//这两行代码从起点到鼠标当前位置画线
		dc.Ellipse(m_StartPoint.x,m_StartPoint.y,point.x,point.y);
		  m_EndPoint=point;//鼠标当前位置在下一次鼠标移动事件看来就是"旧位置"
	}
	if (m_IsDrawIng&&m_DrawType==8)//矩形区域
	{
		CClientDC dc(this);	//设备上下
		CPen * pOldPen;  //保存画笔
		CPen SolidPen(PS_SOLID,1,RGB(rgbr,rgbg,rgbb));  //定义画笔
		pOldPen=dc.SelectObject(&SolidPen);  
		dc.SetROP2(R2_NOT);//设置绘画模式   R2_NOT用与背景色相反的颜色绘图 
		dc.SetROP2(R2_WHITE); 		
		dc.MoveTo(m_StartPoint);
		dc.Rectangle(m_StartPoint.x,m_StartPoint.y,m_EndPoint.x,m_EndPoint.y);	//上次鼠标移动到的位置之间的临时线
		dc.SetROP2(R2_COPYPEN);	
		dc.MoveTo(m_StartPoint);	//这两行代码从起点到鼠标当前位置画线
		dc.Rectangle(m_StartPoint.x,m_StartPoint.y,point.x,point.y);
		m_EndPoint=point;	//鼠标当前位置在下一次鼠标移动事件看来就是"旧位置"
	}
}

void CMyPaintView::OnFileSave() 
{
	// TODO: Add your command handler code here
	CClientDC dc(this);
	CDC memDC;
	CRect rect;
	GetClientRect(rect);
	memDC.CreateCompatibleDC(&dc);
	CBitmap bm;
	int Width=rect.Width();
	int Height=rect.Height();
	bm.CreateCompatibleBitmap(&dc,Width,Height);
	CBitmap* pOld=memDC.SelectObject(&bm);
	memDC.BitBlt(0,0,Width,Height,&dc,0,0,SRCCOPY);
	memDC.SelectObject(pOld);
	BITMAP btm;
	bm.GetBitmap(&btm);
	DWORD size=btm.bmWidthBytes* btm.bmHeight;
	LPSTR lpData=(LPSTR)GlobalAllocPtr(GPTR,size);//分配内存空间
	BITMAPFILEHEADER bfh;
	////////////////////////////////////
	BITMAPINFOHEADER bih;
	bih.biBitCount=btm.bmBitsPixel;
	bih.biClrImportant=0;
	bih.biClrUsed=0;
	bih.biCompression=0;
	bih.biHeight=btm.bmHeight;
	bih.biPlanes=1;
	bih.biSize=sizeof(BITMAPINFOHEADER);
	bih.biSizeImage=size;
	bih.biWidth=btm.bmWidth;
	bih.biXPelsPerMeter=0;
	bih.biYPelsPerMeter=0;
	GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
	bfh.bfReserved1=bfh.bfReserved2=0;
	bfh.bfType=((WORD)('M'<<8)|'B');
	bfh.bfSize=54+size;
	bfh.bfOffBits=54;
	CFileDialog dlg(false,_T("BMP"),_T("*.bmp"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"位图文件(*.bmp|*.bmp|",NULL);
	if (dlg.DoModal()!=IDOK)
	{
		return;
	}
	CString filename=dlg.GetFileName()+".bmp";
	CFile bf;
	CString ss=dlg.GetPathName();
	if (bf.Open(ss,CFile::modeCreate|CFile::modeWrite))
	{
		bf.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER));
		bf.WriteHuge(&bih,sizeof(BITMAPINFOHEADER));
		bf.WriteHuge(lpData,size);
		bf.Close();
		AfxMessageBox("保存成功");
	}
	GlobalFreePtr(lpData);
}
<file_sep>/MyPaint/FillColor.cpp
// FillColor.cpp: implementation of the CFillColor class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MyPaint.h"
#include "FillColor.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFillColor::CFillColor()
{

}

CFillColor::~CFillColor()
{

}
void CFillColor::InitList_L(LNode *L){
	L=new LNode;
	L->front=NULL;
	L->next=NULL;
}
void CFillColor::DestoryList_L(LNode *L){
	while (L)
	{
		LNode*q=L;
		L=L->next;
		delete q;
	}
}
void CFillColor::ListInsert_L(LNode*L,CPoint P0,LNode*p){
	LNode* s;
	s=new LNode;
	s->FillPoint=P0;
	s->next=NULL;
	s->front=p;
	p->next=s;
	p=p->next;
}
void CFillColor::ListDelete_L(LNode*L,LNode*p){
	p=p->front;
	delete p->next;
	p->next=NULL;
}
void CFillColor::ListFillStart(CDC*pDC,CPoint P0,CRGB c){
	LNode*L=new LNode;
	InitList_L(L);
	p=L;
	OriginalP=P0;
	ListInsert_L(L,P0,p);
	ListFillColor(pDC,L,P0,c,p);
	pDC->SetPixel(P0.x,P0.y,(c.red,c.green,c.blue));
	DestoryList_L(L);
}
void CFillColor::ListFillColor(CDC*pDC,LNode*L,CPoint p1,CRGB c,LNode*p){
	if(pDC->GetPixel(OriginalP.x,OriginalP.y)==pDC->GetPixel(p1.x,p1.y+1)){
		p1.y++;if(p1!=OriginalP){
			pDC->SetPixel(p1.x,p1.y,(c.red,c.green,c.blue));
			ListInsert_L(L,p1,p);
			ListFillColor(pDC,L,p1,c,p);
		}
	}
	if(pDC->GetPixel(OriginalP.x,OriginalP.y)==pDC->GetPixel(p1.x-1,p1.y)){
		p1.x--;if(p1!=OriginalP){
			pDC->SetPixel(p1.x,p1.y,(c.red,c.green,c.blue));
			ListInsert_L(L,p1,p);
			ListFillColor(pDC,L,p1,c,p);
		}
	}
	if(pDC->GetPixel(OriginalP.x,OriginalP.y)==pDC->GetPixel(p1.x,p1.y-1)){
		p1.y--;if(p1!=OriginalP){
			pDC->SetPixel(p1.x,p1.y,(c.red,c.green,c.blue));
			ListInsert_L(L,p1,p);
			ListFillColor(pDC,L,p1,c,p);
		}
	}
	if(pDC->GetPixel(OriginalP.x,OriginalP.y)==pDC->GetPixel(p1.x+1,p1.y)){
		p1.x++;if(p1!=OriginalP){
			pDC->SetPixel(p1.x,p1.y,(c.red,c.green,c.blue));
			ListInsert_L(L,p1,p);
			ListFillColor(pDC,L,p1,c,p);
		}
	}
}
<file_sep>/MyPaint/Line.h
// Line.h: interface for the CLine class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_LINE_H__056C4294_E768_4BB2_A176_5855D3BBB204__INCLUDED_)
#define AFX_LINE_H__056C4294_E768_4BB2_A176_5855D3BBB204__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include"RGB.h"
#include"P2.h"
class CLine  
{
public:
	CLine();
	virtual ~CLine();
	void MoveTo(CDC*,CP2);
	void MoveTo(CDC*,double,double,CRGB);
	void LineTo(CDC*,CP2);
	void LineTo(CDC*,double,double,CRGB);
	CRGB Interpolation(double,double,double,CRGB,CRGB);
public:
	CP2 P0;
	CP2 P1;
};


#endif // !defined(AFX_LINE_H__056C4294_E768_4BB2_A176_5855D3BBB204__INCLUDED_)
<file_sep>/MyPaint/MyPaintView.h
// MyPaintView.h : interface of the CMyPaintView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_MYPAINTVIEW_H__C1CF4C07_BF88_4697_8FEE_5C962C3B43A4__INCLUDED_)
#define AFX_MYPAINTVIEW_H__C1CF4C07_BF88_4697_8FEE_5C962C3B43A4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "P2.h"
#include "Line.h"
#include "Circle.h"
#include "RGB.h"
#include "FillColor.h"
#include "WINDOWSX.H"
class CMyPaintView : public CView
{
protected: // create from serialization only
	CMyPaintView();
	DECLARE_DYNCREATE(CMyPaintView)

// Attributes
public:
	CMyPaintDoc* GetDocument();
	void DrawMouseMove(UINT,CPoint);
	void DrawLButtonUp(UINT,CPoint);
// Operations
public:
	int m_DrawType;
	bool m_isDraw;
	bool m_IsDrawIng;
	CP2 m_OriginPoint;
	CP2 m_endpoint;
	CPoint m_StartPoint;
	CPoint m_EndPoint;
	int rgbr;
	int rgbg;
	int rgbb;
	COLORREF m_clr;
	HCURSOR m_hCross;
// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMyPaintView)
	public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	protected:
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CMyPaintView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CMyPaintView)
	afx_msg void OnPaintline();
	afx_msg void OnPaintgreen();
	afx_msg void OnPaintblue();
	afx_msg void OnPaintcolor();
	afx_msg void OnPaintcurve();
	afx_msg void OnPaintfill();
	afx_msg void OnPaintoval();
	afx_msg void OnPaintovalSolid();
	afx_msg void OnPaintreaser();
	afx_msg void OnPaintrectangle();
	afx_msg void OnPaintrectangleSolid();
	afx_msg void OnPaintred();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnFileSave();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG  // debug version in MyPaintView.cpp
inline CMyPaintDoc* CMyPaintView::GetDocument()
   { return (CMyPaintDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MYPAINTVIEW_H__C1CF4C07_BF88_4697_8FEE_5C962C3B43A4__INCLUDED_)
