图形学

大家好,我是一童;好久不见,今天分享MFC实现图形学的相关知识点,就不分享工程包了,直接上主代码,仅供读者参考学习,虽然做的很low;
其中包括
一、主菜单的菜单项
基本图形绘制、图形变换、自由曲线绘制、图形裁剪或图形填充
二 、级子菜单基本图形绘制
1.直线绘制:
1)Bresenham绘制直线
2)DDA绘制直线
3)改进的Bresenham绘制直线
4)系统库函数绘制直线——直线线宽、线形设计
2.Bresenham绘制圆
3.Bresenham绘制椭圆
4.矩形的绘制
5.多边形的绘制
6.圆弧的绘制
三、二级子菜单图形变换
1.基本图形变换
1)平移变换
2)比例变换
3)错切变换
4)对称变换
5) 旋转变换
2.复合变换:
1)复合平移变换
2)复合比例变换
3)复合旋转变换
3.相对任意参考点的变换
4.相对任意直线的变换
四、二级子菜单自由曲线绘制
1.Bezier 曲线绘制
1)1次Bezier曲线
2)2次Bezier曲线
3)3次Bezier曲线
2. 3次B样条曲线
3. Hermite三次样条曲线
4.曲线的拼接设计
二级菜单图形裁剪或图形填充

/CPaintingView//

// PaintingView.cpp : implementation of the CPaintingView class
//

#include "stdafx.h"
#include "Painting.h"


#include "math.h"
#include "MyDlg.h"

#include "PaintingDoc.h"
#include "PaintingView.h"

#define nctlPoints 5   //控制点数
#define nPoints 100    //每段曲线上的点数

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

/
// CPaintingView

IMPLEMENT_DYNCREATE(CPaintingView, CView)

BEGIN_MESSAGE_MAP(CPaintingView, CView)
	//{{AFX_MSG_MAP(CPaintingView)
	ON_COMMAND(ID_DRAW_Bresenham_Line, OnDRAWBresenhamLine)
	ON_COMMAND(ID_DRAW_DDA, OnDrawDda)
	ON_COMMAND(ID_DRAW_MidBresenham_Line, OnDRAWMidBresenhamLine)
	ON_COMMAND(ID_SystemDrawLine, OnSystemDrawLine)
	ON_COMMAND(ID_DRAW_Circle, OnDRAWCircle)
	ON_COMMAND(ID_DRAW_Bresenham_Ellipse, OnDRAWBresenhamEllipse)
	ON_COMMAND(ID_DRAW_Rectangle, OnDRAWRectangle)
	ON_COMMAND(ID_DRAW_Polygon, OnDRAWPolygon)
	ON_COMMAND(ID_DRAW_Arc, OnDRAWArc)
	ON_COMMAND(ID_Translation, OnTranslation)
	ON_COMMAND(ID_Proport, OnProport)
	ON_COMMAND(ID_Shear, OnShear)
	ON_COMMAND(ID_X, OnX)
	ON_COMMAND(ID_Y, OnY)
	ON_COMMAND(ID_XY, OnXy)
	ON_COMMAND(ID_X_Y, OnXY)
	ON_COMMAND(ID_O, OnO)
	ON_COMMAND(ID_Rotate, OnRotate)
	ON_COMMAND(ID_R_Trans, OnRTrans)
	ON_COMMAND(ID_R_Pro, OnRPro)
	ON_COMMAND(ID_MENUITEM32791, OnMenuitem32791)
	ON_COMMAND(ID_xuanz, Onxuanz)
	ON_COMMAND(ID_bili, Onbili)
	ON_COMMAND(ID_YXX, OnYxx)
	ON_COMMAND(ID_yxxx, Onyxxx)
	ON_COMMAND(ID_Bezier1, OnBezier1)
	ON_COMMAND(ID_Bezier2, OnBezier2)
	ON_COMMAND(ID_Bezier3, OnBezier3)
	ON_COMMAND(ID_B, OnB)
	ON_COMMAND(ID_H, OnH)
	ON_COMMAND(ID_P, OnP)
	ON_COMMAND(ID_Pol, OnPol)
	ON_WM_LBUTTONDBLCLK()
	ON_WM_CANCELMODE()
	ON_COMMAND(ID_Cuttinig, OnCuttinig)
	//}}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()

/
// CPaintingView construction/destruction

CPaintingView::CPaintingView()
{
	// TODO: add construction code here
}

CPaintingView::~CPaintingView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/
// CPaintingView drawing

void CPaintingView::OnDraw(CDC* pDC)
{
	CPaintingDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
		pDC->SetMapMode(4);
	CRect rc;
	GetClientRect(&rc);
	pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
	pDC->MoveTo(-rc.right,0);
	pDC->LineTo(rc.right,0);
	pDC->MoveTo(0,rc.bottom);
	pDC->LineTo(0,-rc.bottom);

	pDC->TextOut(rc.right/3.2,-10,"X轴");
	pDC->MoveTo(rc.right/2.95,19);
	pDC->LineTo(rc.right/2.85,0);
	pDC->MoveTo(rc.right/2.95,-19);
	pDC->LineTo(rc.right/2.85,0);

	pDC->TextOut(20,rc.bottom/3,"Y轴");
    pDC->MoveTo(13,rc.bottom/3.1);
	pDC->LineTo(0,rc.bottom/2.8);
	pDC->MoveTo(-13,rc.bottom/3.1);
	pDC->LineTo(0,rc.bottom/2.8);
	pDC->TextOut(-10.5,-2.5 ,"O");
	pDC->TextOut(rc.right/3.5,rc.bottom/3 ,"第一象限");		
	pDC->TextOut(-rc.right/3,rc.bottom/3 ,"第二象限");
	pDC->TextOut(-rc.right/3,-rc.bottom/3.5 ,"第三象限");
	pDC->TextOut(rc.right/3.5,-rc.bottom/3.5,"第四象限");

	switch(m_nDrawType1)
	{
	case 1:BresenhamLine(190,15,350,300,pDC);
	pDC->TextOut(rc.right/4,rc.bottom/5 ,"Bresebham算法");break;
	case 2:DDALine(100, 10, 200, 210, pDC);
		pDC->TextOut(rc.right/7,rc.bottom/3 ,"DDA算法");break;
	case 3:MidBresenhamLine(10, 10, 170, 110, pDC);
	pDC->TextOut(rc.right/22,rc.bottom/3.4 ,"中点Bresenham算法");break;
	case 4:Show_Line(pDC);break;
	case 5:MidBresenhamCircle(50, pDC);
	pDC->TextOut(-rc.right/7,rc.bottom/4,"中点Bresebham算法画圆");break;
	case 6:	MidBresenhamEllipse(70,40,pDC);
	pDC->TextOut(-rc.right/6.3,-rc.bottom/4,"中点Bresebham算法画椭圆");break;
	case 7:pDC->Rectangle(50,50,200,200);pDC->TextOut(rc.right/6,rc.bottom/4,"矩形");break;
	case 8:Polygon(pDC);pDC->TextOut(rc.right/6,rc.bottom/4,"多边形");break;
	case 9:ArcTo(pDC);pDC->TextOut(rc.right/5,rc.bottom/4,"圆弧");break;
	}
	switch(m_nDrawType2)
	{
	case 1:Show_MoveTrans(pDC);	pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(-rc.right/5,rc.bottom/6.2 ,"平移变换");break;
	case 2:Show_Movebili(pDC);	pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(rc.right/8,rc.bottom/8 ,"比例变换");break;
	case 3:Show_Shear(pDC);	pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(rc.right/7,rc.bottom/3.5 ,"错切变换");break;
	case 4:Show_SymX(pDC);	pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(rc.right/13.5,-rc.bottom/9.5 ,"X轴对称");break;
	case 5:Show_SymY(pDC);	pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(-rc.right/13.5,rc.bottom/3.5 ,"Y轴对称");break;
	case 6:Show_SymYX(pDC);pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(rc.right/10.5,rc.bottom/11.5 ,"Y=X轴对称");break;
	case 7:Show_SymY_X(pDC);pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(-rc.right/8.5,-rc.bottom/11.5 ,"Y=-X轴对称");break;
	case 8:Show_SymO(pDC);pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(-rc.right/8.5,-rc.bottom/11.5 ,"原点对称");break;
	case 9:Show_Movexuanzhuan(pDC);
		pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(rc.right/8,-rc.bottom/8.0 ,"旋转变换");break;
	case 10:Show_Trans(pDC);
		pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(rc.right/7.1,rc.bottom/4.0 ,"复合平移变换");break;
	case 11:Show_R_bili(pDC);
			pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(rc.right/7.1,rc.bottom/4.0 ,"复合比例变换");break;
	case 12:Show_xuanzhuan(pDC);
		pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(rc.right/8.1,-rc.bottom/6.0 ,"复合旋转变换");break;
	case 13:Show_Rela_xuanzhuan(pDC);
		pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(rc.right/8.1,-rc.bottom/6.0 ,"任意参考点旋转变换");break;
	case 14:Show_Rela_Bili(pDC);
			pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(rc.right/8.1,rc.bottom/6.0 ,"任意参考点比例变换");break;
	case 15:Show_Rela_Line_xy(pDC);
			pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(rc.right/8.1,rc.bottom/6.0 ,"参考Y=X 变换");break;
	case 16:Show_Rela_Line_x_y(pDC);
			pDC->TextOut(rc.right/22.5,rc.bottom/5.2 ,"原三角形");
		pDC->TextOut(rc.right/8.1,rc.bottom/6.0 ,"参考Y=-X 变换");break;

	}
	switch(m_nDrawType3)
	{
	case 1:	pDC->TextOut(-rc.right/7,rc.bottom/3,"一次Bezier曲线");
		Bezier1();break;
	case 2:pDC->TextOut(rc.right/5.9,rc.bottom/4,"二次Bezier曲线");
		Bezier2();break;
	case 3:pDC->TextOut(-rc.right/3,rc.bottom/6,"三次Bezier曲线");
		Bezier3();break;
	case 4:	pDC->TextOut(-rc.right/6,-rc.bottom/6,"三次B样条");
		Bline();break;
	case 5:	pDC->TextOut(-rc.right/5,rc.bottom/7,"H e r m i t e三次样条曲线");
	Hermite();break;
	case 6:pDC->TextOut(-rc.right/5,rc.bottom/7,"曲线拼接");
		LinkLine();break;
	}
}

/
// CPaintingView printing

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

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

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

/
// CPaintingView diagnostics

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

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

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

/
// CPaintingView message handlers





/

            //基本图形绘制
//



void CPaintingView::OnDRAWBresenhamLine() 
{
	// TODO: Add your command handler code here
	m_nDrawType1=1;
	//UpdateWindow();
	Invalidate();

}

void CPaintingView::OnDrawDda() 
{
	// TODO: Add your command handler code here
	m_nDrawType1=2;
	Invalidate();
}
void CPaintingView::OnDRAWMidBresenhamLine() 
{
	// TODO: Add your command handler code here
	m_nDrawType1=3;
	Invalidate();
}

void CPaintingView::BresenhamLine(int x0, int y0, int x1, int y1, CDC *pDC)//bresenham绘制直线
{
		int x,y,dx,dy,e;
	dx=x1-x0;
	dy=y1-y0;
	e=-dx;x=x0;y=y0;
	while(x<=x1)
	{
		pDC->SetPixel(x,y,RGB(128,42,42));
		x++;
		e=e+2*dy;
		if(e>0)
		{
			y++;
			e=e-2*dx;
		}
	}
}

void CPaintingView::DDALine(int x0, int y0, int x1, int y1, CDC *pDC)//DDA绘制直线
{
		int dx,dy,epsl,k;
	float x,y,xIncre,yIncre;
	dx = x1-x0;
	dy = y1-y0;
	x =(float) x0;
	y = (float) y0;
	if(abs(dx)>abs(dy))
		epsl = abs(dx);
	   else epsl = abs(dy);
	   xIncre =(float)dx /(float)epsl;
	   yIncre =(float)dy /(float)epsl;
	   for(k = 0; k<= epsl;k++)
	   {
			 int  a = (int)(x+0.5);
				int b = (int)(y+0.5);
			 pDC ->SetPixel(a,b,RGB(255,15,225));
			x+=xIncre;
			y+=yIncre;
	  
		}
}


void CPaintingView::MidBresenhamLine(int x0, int y0, int x1, int y1, CDC *pDC)//改进Bresenham绘制直线
{
		int dx,dy,d,UpIncre,DownIncre,x,y;
	if(x0>x1)
	{
		x=x0;x1=x0;x0=x;
		y=y0;y1=y0;y0=y;
	}
	x=x0;y=y1;
	dx=x1-x0;
	dy=y1-y0;
	d=dx-2*dy;
	UpIncre=2*dx-2*dy;DownIncre=-2*dy;
	while(x<=x1)
	{
		pDC->SetPixel(x,y,RGB(0,0,255));
		x++;
		if(d<0)
		{
			y++;
			d+=UpIncre;
		}
		else d+=DownIncre;
	}

}



void CPaintingView::OnSystemDrawLine() 
{
	// TODO: Add your command handler code here
	m_nDrawType1=4;
	Invalidate();
}

void CPaintingView::OnDRAWCircle() 
{
	// TODO: Add your command handler code here
		m_nDrawType1=5;
		Invalidate();
}

void CPaintingView::MidBresenhamCircle(int r, CDC *pDC)//圆
{
	int x,y,d;
	x=0;y=r;d=1-r;
	int x1=-150;
	int y1=100;
	while(x<y)
	{
		pDC->SetPixel(x+x1,y+y1,RGB(0,0,255));
		pDC->SetPixel(y+x1,x+y1,RGB(0,0,255));
		pDC->SetPixel(-x+x1,y+y1,RGB(0,0,255));
		pDC->SetPixel(-y+x1,x+y1,RGB(0,0,255));
		pDC->SetPixel(-x+x1,-y+y1,RGB(0,0,255));
		pDC->SetPixel(-y+x1,-x+y1,RGB(0,0,255));
		pDC->SetPixel(x+x1,-y+y1,RGB(0,0,255));
		pDC->SetPixel(y+x1,-x+y1,RGB(0,0,255));
		if(d<0)d+=2*x+3;
		else
		{
			d+=2*(x-y)+5;
			y--;
		}
		x++;
	}
}

void CPaintingView::OnDRAWBresenhamEllipse() 
{
	// TODO: Add your command handler code here
	m_nDrawType1=6;
	Invalidate();
}

void CPaintingView::MidBresenhamEllipse(int a, int b, CDC *pDC)//椭圆
{
	int x,y;
	double d1,d2;
	x=0;y=b;
	int x1=-150;
	int y1=-100;

	d1=b*b+a*a*(-b+0.25);
	pDC->SetPixel(x+x1,y+y1,RGB(255,97,0));
	pDC->SetPixel(-x+x1,-y+y1,RGB(255,97,0));
	pDC->SetPixel(-x+x1,y+y1,RGB(255,97,0));
	pDC->SetPixel(x+x1,-y+y1,RGB(255,97,0));
	while(b*b*(x+1)<a*a*(y-0.5))
	{
		if(d1<=0)
		{
			d1+=b*b*(2*x+3);
			x++;
		}
		else
		{
			d1+=b*b*(2*x+3)+a*a*(-2*y+2);
			x++;
			y--;
		}
		pDC->SetPixel(x+x1,y+y1,RGB(255,97,0));
		pDC->SetPixel(-x+x1,-y+y1,RGB(255,97,0));
		pDC->SetPixel(-x+x1,y+y1,RGB(255,97,0));
		pDC->SetPixel(x+x1,-y+y1,RGB(255,97,0));
	}
	d2=b*b*(x+0.5)*(x+0.5)+a*a*(y-1)*(y-1)-a*a*b*b;
	while(y>0)
	{
		if(d2<=0)
		{
			d2+=b*b*(2*x+2)+a*a*(-2*y+3);
			x++;
			y--;
		}
		else
		{
			d2+=a*a*(-2*y+3);
			y--;
		}
		pDC->SetPixel(x+x1,y+y1,RGB(255,97,0));
		pDC->SetPixel(-x+x1,-y+y1,RGB(255,97,0));
		pDC->SetPixel(-x+x1,y+y1,RGB(255,97,0));
		pDC->SetPixel(x+x1,-y+y1,RGB(255,97,0));
	}
}

void CPaintingView::OnDRAWRectangle() 
{
	// TODO: Add your command handler code here
	m_nDrawType1=7;
	Invalidate();
}

void CPaintingView::Polygon(CDC *pDC)//多边形
{
	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	pen.CreatePen(PS_SOLID,1,RGB(255,56,0));
	hPen=(HPEN)pDC->SelectObject(pen);
	POINT p[5];
	p[0].x=10;p[0].y=10;
	p[1].x=100;p[1].y=100;
	p[2].x=200;p[2].y=100;
	p[3].x=200;p[3].y=200;
	p[4].x=100;p[4].y=50;
	pDC->Polygon(p,5);
}

void CPaintingView::OnDRAWPolygon() 
{
	// TODO: Add your command handler code here

	m_nDrawType1=8;
	Invalidate();
}

void CPaintingView::OnDRAWArc() 
{
	// TODO: Add your command handler code here
	m_nDrawType1=9;
	Invalidate();
}

void CPaintingView::ArcTo(CDC *pDC)// 圆弧
{
	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
	hPen=(HPEN)pDC->SelectObject(pen);
	pDC->Arc(100,100,300,300,100,150,350,250);
	/*CRect r;
	r.left=100;r.top=100;
	r.right=350;r.bottom=300;
	POINT p1,p2;
	p1.x=100;p1.y=100;
	p2.x=250;p2.y=150;
	pDC->MoveTo(p1);
	pDC->ArcTo(r,p1,p2);*/
}





                        //图形变换
///





void CPaintingView::OnTranslation() 
{
	// TODO: Add your command handler code here
	m_nDrawType2=1;
	Invalidate();
}



//矩阵的乘法
//*********************

void CPaintingView::MutiTransMarix(double a[][3], double b[][3], double MutiResult[][3])
{
	{
for(int i=0;i<3;i++) MutiResult[0][i] = 0;
for(i=0; i<1;i++)
for(int j=0;j<3;j++)
for(int k=0;k<3;k++)
MutiResult[i][j] += a[i][k]*b[k][j];
	}
}

//平移变换
//**********************

CPoint CPaintingView::MoveTrans(double x, double y, double l, double m)
{
	double a[1][3] = {x,y,1};
	double result[1][3];
	double moveMarix[3][3] = {{1,0,0},{0,1,0},{l,m,1}};
	MutiTransMarix(a,moveMarix,result);
	return CPoint(result[0][0],result[0][1]);
}


显示

void CPaintingView::Show_MoveTrans(CDC *pDC)
{

	pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;

	
	// //平移变换
	pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
	hPen=(HPEN)pDC->SelectObject(pen);
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3;
	B1 = MoveTrans(A1.x,A1.y,-340,0);
	B2 = MoveTrans(A2.x,A2.y,-340,0);
	B3 = MoveTrans(A3.x,A3.y,-340,0);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);
}


void CPaintingView::OnProport() 
{
	// TODO: Add your command handler code here
	m_nDrawType2=2;
	Invalidate();
}


//比例变换
//******************


CPoint CPaintingView::Movebili(double x, double y, double l, double m)
{
	double a[1][3] = {x,y,1};
	double result[1][3];
	double moveMarix[3][3] = {{l,0,0},{0,m,0},{0,0,1}};
	MutiTransMarix(a,moveMarix,result);	return CPoint(result[0][0],result[0][1]);
}


void CPaintingView::Show_Movebili(CDC *pDC)
{
	pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;

	pen.CreatePen(PS_SOLID,1,RGB(180,205,34));
	hPen=(HPEN)pDC->SelectObject(pen);
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3;
	B1 = Movebili(A1.x,A1.y,1.2,1.2);
	B2 = Movebili(A2.x,A2.y,2.5,2.5);
	B3 = Movebili(A3.x,A3.y,1.3,0.9);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);

}


//错切变换
//*********************


void CPaintingView::OnShear() 
{
	// TODO: Add your command handler code here
	m_nDrawType2=3;
	Invalidate();	
}

CPoint CPaintingView::Shear(double x, double y, double b, double c)
{

	double a[1][3] = {x,y,1};
	double result[1][3];
	double moveMarix[3][3] = {{1,b,0},{c,1,0},{0,0,1}};
	MutiTransMarix(a,moveMarix,result);	return CPoint(result[0][0],result[0][1]);
}



void CPaintingView::Show_Shear(CDC *pDC)
{
	pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(205,199,45));
	hPen=(HPEN)pDC->SelectObject(pen);
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3;
	B1 = Shear(A1.x,A1.y,0.5,0.5);
	B2 = Shear(A2.x,A2.y,4.5,0.5);
	B3 = Shear(A3.x,A3.y,0.5,0.5);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);
}


///对称变换
//***********
	

//关于X轴
	//****************
void CPaintingView::OnX() 
{
	// TODO: Add your command handler code here
	m_nDrawType2=4;
	Invalidate();
}


CPoint CPaintingView::SymX(double x, double y)
{

	double a[1][3] = {x,y,1};
	double result[1][3];
	double moveMarix[3][3] = {{1,0,0},{0,-1,0},{0,0,1}};
	MutiTransMarix(a,moveMarix,result);	return CPoint(result[0][0],result[0][1]);
}

void CPaintingView::Show_SymX(CDC *pDC)
{
	pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3;
	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(150,100,34));
	hPen=(HPEN)pDC->SelectObject(pen);
	B1 = SymX(A1.x,A1.y);
	B2 = SymX(A2.x,A2.y);
	B3 = SymX(A3.x,A3.y);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);
	
}
//关于Y轴
	//****************


void CPaintingView::OnY() 
{
	// TODO: Add your command handler code here
		m_nDrawType2=5;
		Invalidate();
}

CPoint CPaintingView::SymY(double x, double y)
{
	double a[1][3] = {x,y,1};
	double result[1][3];
	double moveMarix[3][3] = {{-1,0,0},{0,1,0},{0,0,1}};
	MutiTransMarix(a,moveMarix,result);	return CPoint(result[0][0],result[0][1]);
}


void CPaintingView::Show_SymY(CDC *pDC)
{

		pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3;
	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(180,10,34));
	hPen=(HPEN)pDC->SelectObject(pen);
	B1 = SymY(A1.x,A1.y);
	B2 = SymY(A2.x,A2.y);
	B3 = SymY(A3.x,A3.y);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);
}

//关于Y=X轴
	//****************

void CPaintingView::OnXy() 
{
	// TODO: Add your command handler code here
	m_nDrawType2=6;
		Invalidate();
}



CPoint CPaintingView::SymYX(double x, double y)
{
	double a[1][3] = {x,y,1};
	double result[1][3];
	double moveMarix[3][3] = {{0,1,0},{1,0,0},{0,0,1}};
	MutiTransMarix(a,moveMarix,result);	return CPoint(result[0][0],result[0][1]);
}


void CPaintingView::Show_SymYX(CDC *pDC)
{
		pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3;
	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(10,135,134));
	hPen=(HPEN)pDC->SelectObject(pen);
	B1 = SymYX(A1.x,A1.y);
	B2 = SymYX(A2.x,A2.y);
	B3 = SymYX(A3.x,A3.y);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);
}

//关于Y=-X轴
	//****************


void CPaintingView::OnXY() 
{
	// TODO: Add your command handler code here
		m_nDrawType2=7;
		Invalidate();	
}

CPoint CPaintingView::SymY_X(double x, double y)
{
	double a[1][3] = {x,y,1};
	double result[1][3];
	double moveMarix[3][3] = {{0,-1,0},{-1,0,0},{0,0,1}};
	MutiTransMarix(a,moveMarix,result);	return CPoint(result[0][0],result[0][1]);
}

void CPaintingView::Show_SymY_X(CDC *pDC)
{
			pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3;
	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(220,15,34));
	hPen=(HPEN)pDC->SelectObject(pen);
	B1 = SymY_X(A1.x,A1.y);
	B2 = SymY_X(A2.x,A2.y);
	B3 = SymY_X(A3.x,A3.y);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);

}


//关于原点
	//****************
void CPaintingView::OnO() 
{
	// TODO: Add your command handler code here
	m_nDrawType2=8;
		Invalidate();
}

CPoint CPaintingView::SymO(double x, double y)
{
double a[1][3] = {x,y,1};
	double result[1][3];
	double moveMarix[3][3] = {{-1,0,0},{0,-1,0},{0,0,1}};
	MutiTransMarix(a,moveMarix,result);	return CPoint(result[0][0],result[0][1]);
}

void CPaintingView::Show_SymO(CDC *pDC)
{
	pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3;
	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(100,200,34));
	hPen=(HPEN)pDC->SelectObject(pen);
	B1 = SymO(A1.x,A1.y);
	B2 = SymO(A2.x,A2.y);
	B3 = SymO(A3.x,A3.y);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);

}


//旋转变换
	//****************

void CPaintingView::OnRotate() 
{
	// TODO: Add your command handler code here
		m_nDrawType2=9;
		Invalidate();
}

CPoint CPaintingView::Movexuanzhuan(double x, double y, double r)
{
	double a[1][3] = {x,y,1};
	double result[1][3];
	double moveMarix[3][3] = {{cos(r),sin(r),0,},{-sin(r),cos(r),0,},{0,0,1}};
	MutiTransMarix(a,moveMarix,result);	return CPoint(result[0][0],result[0][1]);
}

void CPaintingView::Show_Movexuanzhuan(CDC *pDC)
{
	pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3;
	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(200,20,34));
	hPen=(HPEN)pDC->SelectObject(pen);
	B1 = Movexuanzhuan(A1.x,A1.y,200);
	B2 = Movexuanzhuan(A2.x,A2.y,200);
	B3 = Movexuanzhuan(A3.x,A3.y,200);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);

}


//复合平移变换
//**********************
void CPaintingView::OnRTrans() 
{
	// TODO: Add your command handler code here
		m_nDrawType2=10;
		Invalidate();
}



CPoint CPaintingView::R_Trans(double a,double b,double x1, double y1,double x2, double y2)
{
	double A1[1][3]={a,b,1};
	double result1[1][3],result2[1][3],result3[1][3];
	double moveMarix1[3][3]={{1,0,0},{0,1,0},{x1,y1,1}};
	MutiTransMarix(A1,moveMarix1,result1);
	double A2[1][3]={result1[0][0],result1[0][1],1};
	double moveMarix2[3][3]={{1,0,0},{0,1,0},{x2,y2,1}};
	MutiTransMarix(A2,moveMarix2,result2);
	return CPoint(result2[0][0],result2[0][1]);

}

void CPaintingView::Show_Trans(CDC*pDC)
{
	pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	CPoint A1(0,0),A2(30,80),A3(180,150),A4(50,50),A5(20,20),B1,B2,B3;
	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(200,20,34));
	hPen=(HPEN)pDC->SelectObject(pen);
	B1 = R_Trans(A1.x,A1.y,A4.x,A4.y,A5.x,A5.y);
	B2 = R_Trans(A2.x,A2.y,A4.x,A4.y,A5.x,A5.y);
	B3 = R_Trans(A3.x,A3.y,A4.x,A4.y,A5.x,A5.y);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);

}


//复合比例变换
//**********************


void CPaintingView::OnRPro() 
{
	// TODO: Add your command handler code here
		m_nDrawType2=11;
		Invalidate();
}

CPoint CPaintingView::R_bili(double a,double b,double x1, double y1, double x2, double y2)
{
	double A1[1][3]={a,b,1};
	double result1[1][3],result2[1][3],result3[1][3];
	double moveMarix1[3][3]={{x1,0,0},{0,y1,0},{0,0,1}};
	MutiTransMarix(A1,moveMarix1,result1);
	double A2[1][3]={result1[0][0],result1[0][1],1};
	double moveMarix2[3][3]={{x2,0,0},{0,y2,0},{0,0,1}};
	MutiTransMarix(A2,moveMarix2,result2);
	return CPoint(result2[0][0],result2[0][1]);
}


void CPaintingView::Show_R_bili(CDC *pDC)
{
	
	pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3,C1(1,1),C2(2,2);
	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(20,210,134));
	hPen=(HPEN)pDC->SelectObject(pen);
	B1=R_bili(A1.x,A1.y,C1.x,C1.y,C2.x,C2.y);
	B2=R_bili(A2.x,A2.y,C1.x,C1.y,C2.x,C2.y);
	B3=R_bili(A3.x,A2.y,C1.x,C1.y,C2.x,C2.y);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);
}


//复合旋转变换

//



void CPaintingView::OnMenuitem32791() 
{
	// TODO: Add your command handler code here
	m_nDrawType2=12;
	Invalidate();
}



CPoint CPaintingView::R_Xuanzhuan(double x, double y, double r1, double r2)
{
	double A1[1][3]={x,y,1};
	double result1[1][3],result2[1][3],result3[1][3];
	double moveMarix1[3][3]={{cos(r1),sin(r1),0},{-sin(r1),cos(r1),0},{0,0,1}};
	MutiTransMarix(A1,moveMarix1,result1);
	double A2[1][3]={result1[0][0],result1[0][1],1};
	double moveMarix2[3][3]={{cos(r2),sin(r2),0},{-sin(r2),cos(r2),0},{0,0,1}};
	MutiTransMarix(A2,moveMarix2,result2);
	return CPoint(result2[0][0],result2[0][1]);
}

void CPaintingView::Show_xuanzhuan(CDC*pDC)
{
	
	pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3;
	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(120,10,134));
	hPen=(HPEN)pDC->SelectObject(pen);
	B1=R_Xuanzhuan(A1.x,A1.y,20,10);
	B2=R_Xuanzhuan(A2.x,A2.y,20,10);
	B3=R_Xuanzhuan(A3.x,A2.y,20,10);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);
}

///相对任意参考点二维几何变换

//旋转

void CPaintingView::Onxuanz() 
{
	// TODO: Add your command handler code here
	m_nDrawType2=13;
	Invalidate();
}


CPoint CPaintingView::Rela_xuanzhuan(double a, double b, double x, double y, double r)
{

	double A1[1][3]={a,b,1};
	double result1[1][3],result2[1][3],result3[1][3];
	double moveMarix1[3][3]={{1,0,0},{0,1,0},{-x,-y,1}};
	MutiTransMarix(A1,moveMarix1,result1);
	double A2[1][3]={result1[0][0],result1[0][1],1};
	double moveMarix2[3][3]={{cos(r),sin(r),0},{-sin(r),cos(r),0},{0,0,1}};
	MutiTransMarix(A2,moveMarix2,result2);
	double A3[1][3]={result2[0][0],result2[0][1],1};
	double moveMarix3[3][3]={{1,0,0},{0,1,0},{x,y,1}};
	MutiTransMarix(A3,moveMarix3,result3);
	return CPoint(result3[0][0],result3[0][1]);

}

void CPaintingView::Show_Rela_xuanzhuan(CDC *pDC)
{
	pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3,C(10,20);//参考点 C
	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(120,10,134));
	hPen=(HPEN)pDC->SelectObject(pen);
	B1=Rela_xuanzhuan(A1.x,A1.y,C.x,C.y,30);
	B2=Rela_xuanzhuan(A2.x,A2.y,C.x,C.y,30);
	B3=Rela_xuanzhuan(A3.x,A2.y,C.x,C.y,30);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);
}

//比例


void CPaintingView::Onbili() 
{
	// TODO: Add your command handler code here
	m_nDrawType2=14;
	Invalidate();
}



CPoint CPaintingView::Rela_Bili(double a, double b, double x, double y, double n, double m)
{
	double A1[1][3]={a,b,1};
	double result1[1][3],result2[1][3],result3[1][3];
	double moveMarix1[3][3]={{1,0,0},{0,1,0},{-x,-y,1}};
	MutiTransMarix(A1,moveMarix1,result1);
	double A2[1][3]={result1[0][0],result1[0][1],1};
	double moveMarix2[3][3]={{n,0,0},{0,m,0},{0,0,1}};
	MutiTransMarix(A2,moveMarix2,result2);
	double A3[1][3]={result2[0][0],result2[0][1],1};
	double moveMarix3[3][3]={{1,0,0},{0,1,0},{x,y,1}};
	MutiTransMarix(A3,moveMarix3,result3);
	return CPoint(result3[0][0],result3[0][1]);
}

void CPaintingView::Show_Rela_Bili(CDC *pDC)
{
	pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3,C1(-50,-20),C2(2,2);//参考点 C1,///C2比例参数
	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(10,100,134));
	hPen=(HPEN)pDC->SelectObject(pen);
	B1=Rela_Bili(A1.x,A1.y,C1.x,C1.y,C2.x,C2.y);
	B2=Rela_Bili(A2.x,A2.y,C1.x,C1.y,C2.x,C2.y);
	B3=Rela_Bili(A3.x,A2.y,C1.x,C1.y,C2.x,C2.y);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);
}


///相对任意直线的二维变换

//相对Y=X

void CPaintingView::OnYxx() 
{
	// TODO: Add your command handler code here
		m_nDrawType2=15;
	Invalidate();
}


CPoint CPaintingView::Rela_Line_xy(double a, double b, double x,double y,double r)
{
	double A1[1][3]={a,b,1};
	double result1[1][3],result2[1][3],result3[1][3];
	double moveMarix1[3][3]={{cos(-r),sin(-r),0},{-sin(-r),cos(-r),0},{0,0,1}};
	MutiTransMarix(A1,moveMarix1,result1);
	double A2[1][3]={result1[0][0],result1[0][1],1};
	double moveMarix2[3][3]={{0,x,0},{y,0,0},{0,0,1}};
	MutiTransMarix(A2,moveMarix2,result2);
	double A3[1][3]={result2[0][0],result2[0][1],1};
	double moveMarix3[3][3]={{cos(r),sin(r),0},{-sin(r),cos(r),0},{0,0,1}};
	MutiTransMarix(A3,moveMarix3,result3);
	return CPoint(result3[0][0],result3[0][1]);

}


void CPaintingView::Show_Rela_Line_xy(CDC *pDC)
{
	pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3,C1(1,1);//参考点 C1,///C2比例参数
	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(100,10,14));
	hPen=(HPEN)pDC->SelectObject(pen);
	B1=Rela_Line_xy(A1.x,A1.y,C1.x,C1.y,45);
	B2=Rela_Line_xy(A2.x,A2.y,C1.x,C1.y,45);
	B3=Rela_Line_xy(A3.x,A2.y,C1.x,C1.y,45);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);
}


/ 相对Y=-X
void CPaintingView::Onyxxx() 
{
	// TODO: Add your command handler code here
		m_nDrawType2=16;
	Invalidate();
}

void CPaintingView::Show_Rela_Line_x_y(CDC *pDC)
{
	pDC->MoveTo(0,0);//画三角形
	pDC->LineTo(30,80);
	pDC->LineTo(180,150);
	pDC->LineTo(0,0);

	HBRUSH hbrush;//画笔 pen.DeleteObject();pDC->SelectObject(hPen);
	CPen pen;
	HPEN hPen;
	CPoint A1(0,0),A2(30,80),A3(180,150),B1,B2,B3,C1(-1,-1);//参考点 C1
	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(100,10,14));
	hPen=(HPEN)pDC->SelectObject(pen);
	B1=Rela_Line_xy(A1.x,A1.y,C1.x,C1.y,45);
	B2=Rela_Line_xy(A2.x,A2.y,C1.x,C1.y,45);
	B3=Rela_Line_xy(A3.x,A2.y,C1.x,C1.y,45);
	pDC->MoveTo(B1);
	pDC->LineTo(B2);
	pDC->LineTo(B3);
	pDC->LineTo(B1);
}

void CPaintingView::Show_Line(CDC *pDC)//绘制直线
{
	HBRUSH hbrush;//画笔 
	CPen pen;
	HPEN hPen;

	
	pen.CreatePen(PS_DASH,1,RGB(100,10,14));
	hPen=(HPEN)pDC->SelectObject(pen);
	pDC->MoveTo(-100,200);
	pDC->LineTo(100,200);

	pen.DeleteObject();
	pDC->SelectObject(hPen);

	pen.CreatePen(PS_SOLID,1,RGB(10,170,64));
	hPen=(HPEN)pDC->SelectObject(pen);
	pDC->MoveTo(-120,180);
	pDC->LineTo(120,180);

	pen.DeleteObject();
	pDC->SelectObject(hPen);

	pen.CreatePen(PS_DOT,1,RGB(100,10,64));
	hPen=(HPEN)pDC->SelectObject(pen);
	pDC->MoveTo(-140,160);
	pDC->LineTo(140,160);

	pen.DeleteObject();
	pDC->SelectObject(hPen);

	pen.CreatePen(PS_DASHDOT,1,RGB(130,150,64));
	hPen=(HPEN)pDC->SelectObject(pen);
	pDC->MoveTo(-160,140);
	pDC->LineTo(160,140);


	pen.DeleteObject();
	pDC->SelectObject(hPen);

	pen.CreatePen(PS_DASHDOTDOT,1,RGB(10,10,164));
	hPen=(HPEN)pDC->SelectObject(pen);
	pDC->MoveTo(-180,120);
	pDC->LineTo(180,120);

	pen.DeleteObject();
	pDC->SelectObject(hPen);

	pen.CreatePen(PS_SOLID,2,RGB(160,10,164));
	hPen=(HPEN)pDC->SelectObject(pen);
	pDC->MoveTo(-200,100);
	pDC->LineTo(200,100);

	
	pen.DeleteObject();
	pDC->SelectObject(hPen);

	pen.CreatePen(PS_SOLID,3,RGB(0,0,164));
	hPen=(HPEN)pDC->SelectObject(pen);
	pDC->MoveTo(-220,80);
	pDC->LineTo(220,80);

	
	pen.DeleteObject();
	pDC->SelectObject(hPen);

	pen.CreatePen(PS_SOLID,5,RGB(0,34,14));
	hPen=(HPEN)pDC->SelectObject(pen);
	pDC->MoveTo(-240,60);
	pDC->LineTo(240,60);


	
	pen.DeleteObject();
	pDC->SelectObject(hPen);

	pen.CreatePen(PS_SOLID,8,RGB(0,100,64));
	hPen=(HPEN)pDC->SelectObject(pen);
	pDC->MoveTo(-240,60);
	pDC->LineTo(240,60);


	
	pen.DeleteObject();
	pDC->SelectObject(hPen);

	pen.CreatePen(PS_SOLID,14,RGB(10,40,64));
	hPen=(HPEN)pDC->SelectObject(pen);
	pDC->MoveTo(-260,40);
	pDC->LineTo(260,40);


}


/ 自由曲线绘制//


/
/Bezier曲线


void CPaintingView::OnBezier1() 
{
	// TODO: Add your command handler code here
	m_nDrawType3=1;
	Invalidate();
}

void CPaintingView::Bezier1()
{
	CClientDC *pDC;
	pDC = new CClientDC(this);
	CPen pen;
	HPEN hPen;
	pen.CreatePen(PS_SOLID,1,RGB(15,123,130));
	hPen=(HPEN)pDC->SelectObject(pen);
	double x = 0, bx, by;
	double a[2][2] = { {300,190 },{ 540,40} };
	pDC->MoveTo(a[0][0], a[0][1]);
	pDC->LineTo(a[1][0], a[1][1]);
	pDC->MoveTo(a[0][0], a[0][1]);
	for (double i = 0; i <= 1; i += 0.001)
	{
		x = i;
		double parameters[2] = {(1-x),x};
		bx = parameters[0] * a[0][0] + parameters[1]*a[1][0];
		by = parameters[0] * a[0][1] + parameters[1] * a[1][1];
		pDC->LineTo(bx, by);
	}
	delete pDC;
}


void CPaintingView::OnBezier2() 
{
	// TODO: Add your command handler code here
		m_nDrawType3=2;
	Invalidate();
}
void CPaintingView::Bezier2()
{
	CClientDC *pDC;
	pDC = new CClientDC(this);
	CPen pen;
	HPEN hPen;
	pen.CreatePen(PS_SOLID,1,RGB(205,190,0));
	hPen=(HPEN)pDC->SelectObject(pen);
	double x = 0, bx, by;
	double a[3][2] = { {1400,270 },{ 1200,40},{900,270} };
	pDC->MoveTo(a[0][0], a[0][1]);
	pDC->LineTo(a[1][0], a[1][1]);
	pDC->LineTo(a[2][0], a[2][1]);
	pDC->MoveTo(a[0][0], a[0][1]);

	for (double i = 0; i <= 1; i += 0.001)
	{
		x = i;
		double parameters[3] = {x*x,x,0};
		bx = parameters[0] * (a[3][0]-2*a[2][0]+a[0][0]) + 2*parameters[1]*(a[1][0]-a[0][0])+a[0][0];
		by = parameters[0] * (a[3][1]-2*a[2][1]+a[0][1]) + 2*parameters[1]*(a[1][1]-a[0][1])+a[0][1];
		pDC->LineTo(bx, by);
	}
	delete pDC;

}

void CPaintingView::OnBezier3() 
{
	// TODO: Add your command handler code here
	m_nDrawType3=3;
	Invalidate();
}

void CPaintingView::Bezier3()
{
	CClientDC *pDC;
	pDC = new CClientDC(this);
	CPen pen;
	HPEN hPen;
	pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
	hPen=(HPEN)pDC->SelectObject(pen);
	double x = 0, bx, by;
	double a[4][2] = { { 50,50 },{150,240 },{ 450,370 },{ 640,130 } };
	pDC->MoveTo(a[0][0], a[0][1]);
	pDC->LineTo(a[1][0], a[1][1]);
	pDC->LineTo(a[2][0], a[2][1]);
	pDC->LineTo(a[3][0], a[3][1]);
	pDC->MoveTo(a[0][0], a[0][1]);
	for (double i = 0; i <= 1; i += 0.001)
	{
		x = i;
		double parameters[4] = { (1 - x)*(1 - x)*(1 - x), 3 * x*(1 - x)*(1 - x), 3 * x*x*(1 - x), x*x*x };
		bx = parameters[0] * a[0][0] + parameters[1] * a[1][0] + parameters[2] * a[2][0] + parameters[3] * a[3][0];
		by = parameters[0] * a[0][1] + parameters[1] * a[1][1] + parameters[2] * a[2][1] + parameters[3] * a[3][1];
		pDC->LineTo(bx, by);
	}

	delete pDC;
}

B样条曲线



void CPaintingView::OnB() 
{
	// TODO: Add your command handler code here
		m_nDrawType3=4;
	Invalidate();
}

void CPaintingView::Bline()
{
	CClientDC *pDC;
	pDC = new CClientDC(this);
		CPen pen;
	HPEN hPen;
	pen.CreatePen(PS_SOLID,1,RGB(16,170,0));
	hPen=(HPEN)pDC->SelectObject(pen);
    //控制点
    float Px[] = {120, 240, 430, 660, 1040};
    float Py[] = {650, 490, 350,  420, 700};

    //控制多边形
    pDC->MoveTo(Px[0], Py[0]);
    for(int i=0; i<nctlPoints; i++)
        pDC->LineTo(Px[i], Py[i]);

    //曲线
    float T[nctlPoints+4];           //结点矢量 
    for(i=0; i<nctlPoints+4; i++)
        T[i] = i;
    float pointsX[nctlPoints+3][4], pointsY[nctlPoints+3][4];  //曲线上的点
    bool first = true;
    for(i=3; i<nctlPoints; i++)
    {
        float delta = (T[i+1] - T[i]) / nPoints;
        for(float t=T[i]; t<=T[i+1]; t+=delta) 
        {
            for(int k=0; k<=3; k++) 
            {
                for(int j=i-3+k; j<=i; j++) 
                { 
                    if(k==0) 
                    {
                        pointsX[j][k] = Px[j]; 
                        pointsY[j][k] = Py[j];
                    }
                    else 
                    { 
                        float alpha = (t-T[j]) / (T[j+4-k]-T[j]); 
                        pointsX[j][k] = (1.0 - alpha) * pointsX[j-1][k-1] + alpha * pointsX[j][k-1]; 
                        pointsY[j][k] = (1.0 - alpha) * pointsY[j-1][k-1] + alpha * pointsY[j][k-1] ; 
                        if(j==i && k==3)
                        {
                            if(first)
                                pDC->MoveTo(pointsX[j][3], pointsY[j][3]);
                            else
                                pDC->LineTo(pointsX[j][3], pointsY[j][3]);
                            first = false;
                        }
                    }
                }
            }
        }
    }
}



*******************************

///hermite曲线
void CPaintingView::OnH() 
{
	// TODO: Add your command handler code here
		m_nDrawType3=5;
	Invalidate();
}

void CPaintingView::Hermite()
{
CClientDC *pDC;
	pDC = new CClientDC(this);
	CPen pen;
	HPEN hPen;
	pen.CreatePen(PS_SOLID,1,RGB(225,10,120));
	hPen=(HPEN)pDC->SelectObject(pen);
	double x = 0, bx, by;
	double a[4][2] = { { 100,350 },{170,500 },{ 450,670 },{ 640,330 } };
	double m[2][2] ={ {a[1][0]-a[0][0],a[1][1]-a[0][1]},{a[3][0]-a[2][0],{a[3][1]-a[2][1]}}};
	pDC->MoveTo(a[0][0], a[0][1]);
	pDC->LineTo(a[1][0], a[1][1]);
	pDC->LineTo(a[2][0], a[2][1]);
	pDC->LineTo(a[3][0], a[3][1]);
	pDC->MoveTo(a[0][0], a[0][1]);
	for (double i = 0; i <= 1; i += 0.001)
	{
		x = i;
		double parameters[4] = {2*x*x*x-3*x*x+1,x*x*x-2*x*x+x,x*x*x-x*x,-2*x*x*x+3*x*x};
		bx = parameters[0] * a[0][0] + parameters[1] * 2*a[1][0] + parameters[2] * 3*a[2][0] + parameters[3] * a[3][0];
		by = parameters[0] * a[0][1] + parameters[1] *2* a[1][1] + parameters[2] *3* a[2][1] + parameters[3] * a[3][1];
		pDC->LineTo(bx, by);
	}

	delete pDC;
}

void CPaintingView::OnP() 
{
	// TODO: Add your command handler code here
		m_nDrawType3=6;
	Invalidate();
}


void CPaintingView::LinkLine()///曲线连接
{
		CClientDC *pDC;
	pDC = new CClientDC(this);
	CPen pen;
	HPEN hPen;
	pen.CreatePen(PS_DASH,1,RGB(255,0,0));
	hPen=(HPEN)pDC->SelectObject(pen);
	double x = 0, bx, by;
	double a[4][2] = { { 40,450 },{150,300 },{ 450,225},{ 640,320 }};
	double b[4][2] = { { 640,320 },{1000,500 },{ 1250,440 },{ 1440,220 }};	
	pDC->MoveTo(a[0][0], a[0][1]);
	pDC->LineTo(a[1][0], a[1][1]);
	pDC->LineTo(a[2][0], a[2][1]);
	pDC->LineTo(a[3][0], a[3][1]);

	pDC->MoveTo(b[0][0], b[0][1]);
	pDC->LineTo(b[1][0], b[1][1]);
	pDC->LineTo(b[2][0], b[2][1]);
	pDC->LineTo(b[3][0], b[3][1]);
	pDC->MoveTo(a[0][0], a[0][1]);

	pen.DeleteObject();
	pDC->SelectObject(hPen);
	pen.CreatePen(PS_SOLID,1,RGB(100,10,40));
	hPen=(HPEN)pDC->SelectObject(pen);
	for (double i = 0; i <= 1; i += 0.001)
	{
		x = i;
		double parameters[4] = { (1 - x)*(1 - x)*(1 - x), 3 * x*(1 - x)*(1 - x), 3 * x*x*(1 - x), x*x*x };
		bx = parameters[0] * a[0][0] + parameters[1] * a[1][0] + parameters[2] * a[2][0] + parameters[3] * a[3][0];
		by = parameters[0] * a[0][1] + parameters[1] * a[1][1] + parameters[2] * a[2][1] + parameters[3] * a[3][1];
		pDC->LineTo(bx, by);
	}
	for (i = 0; i <= 1; i += 0.001)
	{
		x=0;
		x = i;
		double parameters[4] = { (1 - x)*(1 - x)*(1 - x), 3 * x*(1 - x)*(1 - x), 3 * x*x*(1 - x), x*x*x };
	    bx = parameters[0] * b[0][0] + parameters[1] * b[1][0] + parameters[2] * b[2][0] + parameters[3] * b[3][0];
		by = parameters[0] * b[0][1] + parameters[1] * b[1][1] + parameters[2] * b[2][1] + parameters[3] * b[3][1];
		pDC->LineTo(bx, by);
	}

	delete pDC;

}

void CPaintingView::OnPol() /填充//
{
	// TODO: Add your command handler code here
	CDC* pDC=GetDC();
	
	CPen pen(PS_SOLID,1,RGB(0,255,0));  //设置扫描线所用笔的属性
	CPen *old=pDC->SelectObject(&pen);
	
	int j,k,s=0;
	int p[9];  //每根扫描线交点
	int pmin,pmax;
		

	for(int i=0;i<8;i++)//建立边表
	{
		edge[i].dx=(float)(spt[i+1].x-spt[i].x)/(spt[i+1].y-spt[i].y);
		if(spt[i].y<=spt[i+1].y)
		{
			edge[i].num=i;
			edge[i].ymin=spt[i].y;
			edge[i].ymax=spt[i+1].y;
			edge[i].xmin=(float)spt[i].x;
			edge[i].xmax=(float)spt[i+1].x;
			}
		else{
			edge[i].num=i;
			edge[i].ymin=spt[i+1].y;
			edge[i].ymax=spt[i].y;
			edge[i].xmax=(float)spt[i].x;
			edge[i].xmin=(float)spt[i+1].x;
			}		
	}
	
	//求多边形的最大最小值
	for(int m=1;m<8;m++)
	{
		for(int n=0;n<8-m;n++)
		{
			if(spt[n].y<spt[n+1].y)
			{
			p0=spt[n];	spt[n]=spt[n+1];
			spt[n+1]=p0;
			}				
		}
	}
	pmax=spt[0].y,pmin=spt[7].y;

	for(int r=1;r<8;r++)	//边表edge排序
	{
		for(int q=0;q<8-r;q++)
		{
			if(edge[q].ymin<edge[q+1].ymin)
			{
			newedge[0]=edge[q];	edge[q]=edge[q+1];
			edge[q+1]=newedge[0];
			}				
		}
	}
		for(int scan=pmax-2;scan>pmin;scan--)  //扫描线遵守'“上开下闭”的原则
	{
		int b=0;
		k=s;
		  for(j=k;j<8;j++)
		{	
			if((scan>=edge[j].ymin)&&(scan<=edge[j].ymax))//判断扫描线与线段是否相交于顶点			  
			{
				if(scan==edge[j].ymax)
				{
					if(spt[edge[j].num+1].y<edge[j].ymax)
					{
									b++;
						p[b]=(int)edge[j].xmax;
					}
					if(spt[edge[j].num-1].y<edge[j].ymax)
					{
						b++;		
						p[b]=(int)edge[j].xmax;
					}			
				}
					if(scan==edge[j].ymin)
				{
					if(spt[edge[j].num+1].y>edge[j].ymin)
					{
									b++;
						p[b]=(int)edge[j].xmin;
					}
					if(spt[edge[j].num-1].y>edge[j].ymin)
					{
						b++;		
						p[b]=(int)edge[j].xmin;
					}			
				}	
				 if((scan>edge[j].ymin)&&(scan<edge[j].ymax))
				{
					b++;
					p[b]=(int)(edge[j].xmax+edge[j].dx*(scan-edge[j].ymax));
				}
			}
				
			if(scan<edge[j].ymin)          //建立新的活性边表
				 	s=j;                 
		  }		
		if(b>1)
		{					
				for(int u=1;u<=b;u++)
				{
				pDC->MoveTo(p[u],scan);
					u++;
				pDC->LineTo(p[u],scan);
				}				
		}		
	}

	pDC->MoveTo(150,200);
	pDC->LineTo(266,200);
	pDC->MoveTo(90,180);
	pDC->LineTo(273,180);
	pDC->SelectObject(old);
	ReleaseDC(pDC);
}

void CPaintingView::OnLButtonDblClk(UINT nFlags, CPoint point) //鼠标左键双击响应
{
	// TODO: Add your message handler code here and/or call default
		RedrawWindow();

	CDC* pDC=GetDC();
	CPen newpen(PS_SOLID,1,RGB(255,0,0));
	CPen *old=pDC->SelectObject(&newpen);

	spt[0]=CPoint(100,100);
	spt[1]=CPoint(300,100);
	spt[2]=CPoint(250,250);
	spt[3]=CPoint(100,250);	
	spt[4]=CPoint(150,200);
	spt[5]=CPoint(90,180);
	spt[6]=CPoint(150,150);
	spt[7]=CPoint(100,100);
	pDC->Polyline(spt,8);
	pDC->SelectObject(old);
	ReleaseDC(pDC);
	CView::OnLButtonDblClk(nFlags, point);
}


void CPaintingView::OnCuttinig() 
{
	// TODO: Add your command handler code here
	CMyDlg op;
	op.DoModal();
}

/EDGE/

// PaintingView.h : interface of the CPaintingView class
//
/

#if !defined(AFX_PAINTINGVIEW_H__9A649158_59D4_44DB_81D3_FA7A96178969__INCLUDED_)
#define AFX_PAINTINGVIEW_H__9A649158_59D4_44DB_81D3_FA7A96178969__INCLUDED_

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

typedef struct 
{
int ymin,ymax,num;
float xmin,xmax,dx;
}Edge;
class CPaintingView : public CView
{
protected: // create from serialization only
	CPaintingView();
	DECLARE_DYNCREATE(CPaintingView)

// Attributes
public:
	CPaintingDoc* GetDocument();
	CPoint s_point,ptset[8],spt[8],p0;
	Edge edge[8],edge1[8],newedge[1];

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CPaintingView)
	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:
	void LinkLine();
	void Hermite();
	void Bline();
	void Bezier3();
	void Bezier2();
	void Bezier1();
	int m_nDrawType3;
	void Show_Line(CDC*pDC);
	void Show_Rela_Line_x_y(CDC *pDC);
	void Show_Rela_Line_xy(CDC*pDC);
	CPoint Rela_Line_xy(double a,double b,double x,double y,double r);
	void Show_Rela_Bili(CDC*pDC);
	CPoint Rela_Bili(double a,double b,double x,double y,double  n,double m);
	void Show_Rela_xuanzhuan(CDC*pDC);
	CPoint Rela_xuanzhuan(double a,double b,double x,double y,double  r);
	void Show_xuanzhuan(CDC*pDC);
	CPoint R_Xuanzhuan(double x,double y,double r1,double r2);
	void Show_R_bili(CDC*pDC);
	CPoint R_bili(double a,double b,double x1,double y1,double x2,double y2);
	void Show_Trans(CDC*pDC);
	CPoint R_Trans(double a,double b,double x, double y,double x2, double y2);
	void MutiTransMarix1(double a[3][3], double b[3][3], double MutiResult[3][3]);
	void Show_Movexuanzhuan(CDC*pDC);
	CPoint Movexuanzhuan(double x, double y, double r);
	void Show_SymO(CDC *pDC);
	CPoint SymO(double x, double y);
	void Show_SymY_X(CDC *pDC);
	CPoint SymY_X(double x, double y);
	void Show_SymYX(CDC *pDC);
	CPoint SymYX(double x, double y);
	void Show_SymY(CDC *pDC);
	CPoint SymY(double x, double y);
	void Show_SymX(CDC*pDC);
	CPoint SymX(double x, double y);
	void Show_Shear(CDC*pDC);
	CPoint Shear(double x, double y ,double b, double c);
	void Show_Movebili(CDC*pDC);
	CPoint Movebili(double x, double y ,double l, double m);
	void Show_MoveTrans(CDC*pDC);
	CPoint MoveTrans(double x, double y ,double l, double m);
	void MutiTransMarix(double a[1][3], double b[3][3], double MutiResult[1][3]);
	int m_nDrawType2;
	void ArcTo(CDC*pDC);
	void Polygon(CDC *pDC);
	void MidBresenhamEllipse(int a, int b, CDC *pDC);
	void MidBresenhamCircle(int r, CDC *pDC);
	void MidBresenhamLine(int x0, int y0, int x1, int y1, CDC *pDC);
	void DDALine(int x0, int y0, int x1, int y1, CDC *pDC);
	int m_nDrawType1;
	void BresenhamLine(int x0, int y0, int x1, int y1, CDC *pDC);
	virtual ~CPaintingView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CPaintingView)
	afx_msg void OnDRAWBresenhamLine();
	afx_msg void OnDrawDda();
	afx_msg void OnDRAWMidBresenhamLine();
	afx_msg void OnSystemDrawLine();
	afx_msg void OnDRAWCircle();
	afx_msg void OnDRAWBresenhamEllipse();
	afx_msg void OnDRAWRectangle();
	afx_msg void OnDRAWPolygon();
	afx_msg void OnDRAWArc();
	afx_msg void OnTranslation();
	afx_msg void OnProport();
	afx_msg void OnShear();
	afx_msg void OnX();
	afx_msg void OnY();
	afx_msg void OnXy();
	afx_msg void OnXY();
	afx_msg void OnO();
	afx_msg void OnRotate();
	afx_msg void OnRTrans();
	afx_msg void OnRPro();
	afx_msg void OnMenuitem32791();
	afx_msg void Onxuanz();
	afx_msg void Onbili();
	afx_msg void OnYxx();
	afx_msg void Onyxxx();
	afx_msg void OnBezier1();
	afx_msg void OnBezier2();
	afx_msg void OnBezier3();
	afx_msg void OnB();
	afx_msg void OnH();
	afx_msg void OnP();
	afx_msg void OnPol();
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnCuttinig();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG  // debug version in PaintingView.cpp
inline CPaintingDoc* CPaintingView::GetDocument()
   { return (CPaintingDoc*)m_pDocument; }
#endif

/

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

#endif // !defined(AFX_PAINTINGVIEW_H__9A649158_59D4_44DB_81D3_FA7A96178969__INCLUDED_)

/MyDlg/

// MyDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Painting.h"
#include "MyDlg.h"
#include "MainFrm.h"
#include "Resource.h"
#include "PaintingDoc.h"
#include "PaintingView.h"


#define LEFT 1
#define RIGHT 2
#define BOTTOM 4
#define TOP 8

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

/
// CMyDlg dialog


CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

	
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	ldb = FALSE;
	step = 0;
	top = 20,but = 100,lef = 20,rig = 100;
	lxb = 0,lyb = 0;
	lxe = 50,lye = 50;
}


void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)

	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()

	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/
// CMyDlg message handlers


int CMyDlg::code(int x,int y)
{//编码函数
	int c = 0;
	if(x<lef)
		c = c|LEFT;
	else if(x>rig)
		c = c|RIGHT;
	if(y>but)
		c = c|BOTTOM;
	else if(y<top)
		c = c|TOP;
	return c;
}

void CMyDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	step = 1;
}

void CMyDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	step = 2;
}

void CMyDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	int code1,code2,tcode;
	code1 = code(lxb,lyb);
	code2 = code(lxe,lye);
	int x,y;
	while(code1!=0||code2!=0){
		if((code1&code2)!=0){
			lxb = 0,lyb = 0;
			lxe = 0,lye = 0;
			break;
		}
		tcode = code1;
		if(code1 == 0){
			tcode = code2;
		}
//		float tt = 0.5f;
		if((tcode&LEFT)!=0){//交左边界
			x = lef;
			y = lyb + (int)(float(lye - lyb)*float(lef-lxb)/float(lxe - lxb));
		}
		else if((tcode&RIGHT)!=0){//右边界相交
			x = rig;
			y = lyb + int(float(lye - lyb)*float(rig - lxb)/float(lxe - lxb));
		}
		else if((tcode&BOTTOM) != 0){//与下边界相交
			y = but;
			x = lxb + int(float(lxe - lxb) * float(but - lyb)/float(lye - lyb));
		}
		else if((tcode&TOP)!=0){//与上边界相交
			y = top;
			x = lxb + int(float(lxe - lxb) * float(top - lyb)/float(lye - lyb));
		}

		if(tcode == code1){
			lxb = x;
			lyb = y;
			code1 = code(x,y);
		}
		else{
			lxe = x;
			lye = y;
			code2 = code(x,y);
		}
	}
//	step = 0;
	Invalidate(FALSE);
}


BOOL CMyDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDB_B);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	CPaintDC dc(this);
	pic.CreateCompatibleDC(&dc);
	CBitmap * bp1,*obp1;
	bp1 = new CBitmap;
	bp1->LoadBitmap(IDB_B);
	obp1 = pic.SelectObject(bp1);
	obp1->DeleteObject();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		//CAboutDlg *dlgAbout=new CAboutDlg();
		//dlgAbout->DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

void CMyDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	if (IsIconic())
	{
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
	CDC mdc;
	CBitmap bmp,*bp;
	bmp.LoadBitmap(IDB_B);
	mdc.CreateCompatibleDC(GetDC());
	bp = mdc.SelectObject(&bmp);
	pic.BitBlt(0,0,500,320,&mdc,0,0,SRCCOPY);
	mdc.SelectObject(bp);

	CDC * dc1;
	CWnd * wd1;
	wd1 = this->GetDlgItem(IDC_S);
	dc1 = wd1->GetDC();
	pic.MoveTo(lxb,lyb);
	pic.LineTo(lxe,lye);
	pic.MoveTo(lef,top);
	pic.LineTo(rig,top);
	pic.LineTo(rig,but);
	pic.LineTo(lef,but);
	pic.LineTo(lef,top);
	dc1->BitBlt(1,1,496,309,&pic,0,0,SRCCOPY);
}

HCURSOR CMyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void CMyDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(step){
		if(point.x>11&&point.x<508&&point.y>11&&point.y<321){
			ldb = TRUE;
			switch(step){
			case 1:
				top = point.y-12;
				lef = point.x-12;
				break;
			case 2:
				lxb = point.x-12;
				lyb = point.y-12;
				break;
			}
		}
	}	
	CDialog::OnLButtonDown(nFlags, point);
}

void CMyDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(ldb){
		ldb = FALSE;
		int ti;
		switch(step){
		case 1:
			but = point.y-12;
			rig = point.x-12;
			if(but<top){ti = but;but = top;top = ti;}
			if(lef>rig){ti = lef;lef = rig;rig = ti;}
			break;
		case 2:
			lxe = point.x-12;
			lye = point.y-12;
			break;
		}
		Invalidate(FALSE);
	}
	CDialog::OnLButtonUp(nFlags, point);
}

void CMyDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(ldb){
		switch(step){
		case 1:
			but = point.y-12;
			rig = point.x-12;
			break;
		case 2:
			lxe = point.x-12;
			lye = point.y-12;
			break;
		}
		Invalidate(FALSE);
	}
	CDialog::OnMouseMove(nFlags, point);
}

部分截图

今天先分享这些吧!若有疑问欢迎留言!!!

  • 5
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值