www.pudn.com > Visual C++课程设计案例精编--画图1 .rar > PainterView.cpp


// PainterView.cpp : implementation of the CPainterView class 
// 
 
#include "stdafx.h" 
#include "Painter.h" 
#include "mainfrm.h" 
#include "EnterTexdlg.h" 
 
#include "PainterDoc.h" 
#include "PainterView.h" 
#include  
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CPainterView 
 
IMPLEMENT_DYNCREATE(CPainterView, CScrollView) 
 
BEGIN_MESSAGE_MAP(CPainterView, CScrollView) 
	//{{AFX_MSG_MAP(CPainterView) 
	ON_WM_LBUTTONDOWN() 
	ON_BN_CLICKED(IDC_COLOR, OnColor) 
	ON_BN_CLICKED(IDC_PEN_COLOR, OnPenColor) 
	ON_CBN_SELCHANGE(IDC_LINE_WIDTH, OnSelchangeLineWidth) 
	ON_CBN_SELCHANGE(IDC_LINE_TYPE, OnSelchangeLineType) 
	ON_CBN_SELCHANGE(IDC_FILL_PATTERN, OnSelchangeFillPattern) 
	ON_COMMAND(ID_DRAW_LINE, OnDrawLine) 
	ON_COMMAND(ID_DRAW_RECTANGLE, OnDrawRectangle) 
	ON_WM_LBUTTONUP() 
	ON_WM_MOUSEMOVE() 
	ON_COMMAND(ID_DRAW_ELLIPSE, OnDrawEllipse) 
	ON_COMMAND(ID_DRAW_FILL, OnDrawFill) 
	ON_COMMAND(ID_DRAW_SELECT, OnDrawSelect) 
	ON_COMMAND(ID_MODIFY_MOVE, OnModifyMove) 
	ON_UPDATE_COMMAND_UI(ID_EDIT_DELETE, OnUpdateEditDelete) 
	ON_COMMAND(ID_EDIT_DELETE, OnEditDelete) 
	ON_COMMAND(ID_EDIT_COPY, OnEditCopy) 
	ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy) 
	ON_COMMAND(ID_EDIT_PASTE, OnEditPaste) 
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste) 
	ON_COMMAND(ID_EDIT_CUT, OnEditCut) 
	ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut) 
	ON_COMMAND(ID_EDIT_REDO, OnEditRedo) 
	ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo) 
	ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo) 
	ON_COMMAND(ID_EDIT_UNDO, OnEditUndo) 
	ON_COMMAND(ID_DRAW_TRIANGLE, OnDrawTriangle) 
	ON_COMMAND(ID_TEXT, OnText) 
	ON_WM_DESTROY() 
	ON_COMMAND(ID_DRAW_GRID, OnDrawGrid) 
	ON_UPDATE_COMMAND_UI(ID_DRAW_GRID, OnUpdateDrawGrid) 
	ON_UPDATE_COMMAND_UI(ID_DRAW_FILL, OnUpdateDrawFill) 
	ON_COMMAND(ID_FILE_SAVE, OnFileSave) 
	ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) 
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen) 
	ON_WM_KEYDOWN() 
	ON_WM_KEYUP() 
	ON_COMMAND(ID_DRAW_NOTILT, OnDrawNotilt) 
	ON_UPDATE_COMMAND_UI(ID_DRAW_NOTILT, OnUpdateDrawNotilt) 
	ON_COMMAND(ID_ENLARGE, OnEnlarge) 
	ON_WM_CONTEXTMENU() 
	ON_COMMAND(ID_EDIT_MODIFY, OnEditModify) 
	ON_UPDATE_COMMAND_UI(ID_EDIT_MODIFY, OnUpdateEditModify) 
	ON_UPDATE_COMMAND_UI(ID_DRAW_ELLIPSE, OnUpdateDrawEllipse) 
	ON_UPDATE_COMMAND_UI(ID_DRAW_LINE, OnUpdateDrawLine) 
	ON_UPDATE_COMMAND_UI(ID_DRAW_RECTANGLE, OnUpdateDrawRectangle) 
	ON_UPDATE_COMMAND_UI(ID_DRAW_TRIANGLE, OnUpdateDrawTriangle) 
	ON_UPDATE_COMMAND_UI(ID_DRAW_SELECT, OnUpdateDrawSelect) 
	ON_UPDATE_COMMAND_UI(ID_TEXT, OnUpdateText) 
	ON_UPDATE_COMMAND_UI(ID_MODIFY_MOVE, OnUpdateModifyMove) 
	ON_COMMAND(ID_VIEW_100, OnView100) 
	ON_COMMAND(ID_VIEW_200, OnView200) 
	ON_COMMAND(ID_VIEW_25, OnView25) 
	ON_COMMAND(ID_VIEW_50, OnView50) 
	ON_COMMAND(ID_VIEW_75, OnView75) 
	//}}AFX_MSG_MAP 
	// Standard printing commands 
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview) 
	ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnDropDown) 
	ON_COMMAND(ID_ENLARGE, DoNothing) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CPainterView construction/destruction 
 
CPainterView::CPainterView() 
{ 
	// TODO: add construction code here 
	//初始化变量 
	hatchIndex=0;//当前填充方式 
	CurColor=(0,255,0);//当前颜色 
	PenCurColor=(0,0,0);//画笔颜色 
	penType=0;//画笔种类为1 
	penWidth=1;//画笔宽度为1 
	DrawStep=0;//绘图状态为未完成 
	DrawType=new BYTE; 
	*DrawType=SELECT;//当前无绘图种类 
	m_IsSelected=FALSE;//当前未选择图元 
	m_bCopy=FALSE;//当前没有拷贝图元 
	m_bRedo=FALSE;//不能恢复当前操作 
	m_bUndo=FALSE;//不能撤消当前操作 
	m_bGrid=FALSE;//没有绘制辅助网点 
	bFileSaved=FALSE;//没有保存过文件 
	bShiftDown=FALSE;//没有按下Shift键 
	OppIndex=0;//当前没有绘制图元 
	m_bNoTilt=FALSE;//当前不禁止绘制斜线 
	ZoomFactor=1; 
	m_bModify=FALSE; 
	m_nModifyStep=0; 
	m_bIsRect=FALSE; 
} 
 
CPainterView::~CPainterView() 
{ 
} 
 
BOOL CPainterView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// 如果需要修改窗口的风格则修改cs 
 
	return CScrollView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CPainterView drawing 
 
void CPainterView::OnDraw(CDC* pDC) 
{ 
	CPainterDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
 
	CRect rect; 
	GetClientRect(rect); 
 
	if(m_bGrid) 
	{ 
	    int i,j; 
	    for(i=0;iSetPixel(i,j,(COLORREF)0xf); 
	 } 
 
	if(m_bModify) 
	{ 
		DrawSnapList(); 
	} 
	// TODO: add draw code for native data here 
	//重画对话框条 
	CBrush Brush,*OldBrush; 
	CMainFrame *OwnWnd; 
	OwnWnd=(CMainFrame *)GetParentOwner(); 
	OwnWnd->m_wndMyDialogBar.OnPaint();//首先使对话框条发出WM_PAINT消息告知 
	                                   //应用程序重绘对话框条 
	CWnd* pWnd = OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_FILL_PREVIEW);//得到指向预览框的指针 
	pWnd->GetClientRect(rect);//得到预览框矩形 
	CDC* dc=pWnd->GetDC();//得到预览框的设备表述表 
	Brush.CreateHatchBrush(hatchIndex,CurColor); 
	rect.left+=1; 
	rect.right-=1; 
	rect.top+=1; 
	rect.bottom-=1; 
	dc->FillRect(rect,&Brush); 
 
	CPen pen(penType,penWidth,PenCurColor),*OldPen; 
	pWnd = OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_PREVIEW);//得到指向预览框的指针 
	dc=pWnd->GetDC();//得到预览框的设备表述表 
	pWnd->GetClientRect(rect);//得到预览框矩形 
	 
	dc->Rectangle(rect); 
	OldPen=dc->SelectObject(&pen); 
	dc->MoveTo(rect.left+5, (rect.bottom-rect.top)/2); 
	dc->LineTo(rect.right-5, (rect.bottom-rect.top)/2); 
	dc->SelectObject(OldPen); 
 
	//重绘图元 
	HPEN hPen,hOldPen; 
	HBRUSH hBrush; 
	POSITION pos=pDoc->RecordList.GetHeadPosition(); 
	while(pos!=NULL) 
	{ 
		BYTE *drawtype; 
		drawtype=(BYTE*)pDoc->RecordList.GetNext(pos); 
		switch(*drawtype) 
		{ 
		case LINE: 
			LINENODE *line; 
			line=(LINENODE *)pDoc->RecordList.GetNext(pos); 
			if(line->bDo>0) 
			{ 
				//另一种创建画笔的方法 
				if(line->bDo!=2)//如果图元不处于选择状态则创建其原始画笔 
                    hPen=CreatePen(line->pen.iStyle,line->pen.iWidth,line->pen.Color); 
				else//否则创建红色虚线画笔 
					hPen=CreatePen(PS_DASHDOT,1,RGB(255,0,0)); 
			    hOldPen=(HPEN)SelectObject(pDC->m_hDC,hPen); 
			    pDC->MoveTo(line->Start); 
			    pDC->LineTo(line->End); 
			    pDC->SelectObject(OldPen); 
			    DeleteObject(SelectObject(pDC->m_hDC,hOldPen)); 
			} 
			break; 
		case RECTANGLE: 
			RECTANGLENODE *rectangle; 
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(rectangle->bDo>0) 
			{ 
			    if(rectangle->bDo!=2) 
			        hPen=CreatePen(rectangle->pen.iStyle,rectangle->pen.iWidth,rectangle->pen.Color); 
			    else 
				    hPen=CreatePen(PS_DASHDOT,1,RGB(255,0,0)); 
			    hOldPen=(HPEN)SelectObject(pDC->m_hDC,hPen); 
			    pDC->MoveTo(rectangle->rT.left,rectangle->rT.top); 
			    pDC->LineTo(rectangle->rT.right,rectangle->rT.top); 
			    pDC->LineTo(rectangle->rT.right,rectangle->rT.bottom); 
			    pDC->LineTo(rectangle->rT.left,rectangle->rT.bottom); 
			    pDC->LineTo(rectangle->rT.left,rectangle->rT.top); 
			    DeleteObject(SelectObject(pDC->m_hDC,hOldPen)); 
			} 
			break; 
		case TRIANGLE: 
			TRIANGLENODE *triangle; 
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(triangle->bDo>0) 
			{ 
			    if(triangle->bDo!=2) 
			        hPen=CreatePen(triangle->pen.iStyle,triangle->pen.iWidth,triangle->pen.Color); 
			    else 
				    hPen=CreatePen(PS_DASHDOT,1,RGB(255,0,0)); 
			    hOldPen=(HPEN)SelectObject(pDC->m_hDC,hPen); 
			    DrawTriangle(pDC,triangle->rT); 
			    DeleteObject(SelectObject(pDC->m_hDC,hOldPen)); 
			} 
			break; 
		case TEXT: 
			TEXTNODE *text; 
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos); 
			if(text->bDo>0) 
			{ 
				if(text->bDo!=2) 
					pDC->SetTextColor(text->color); 
				else 
					pDC->SetTextColor(RGB(255,0,0)); 
				pDC->TextOut(text->point.x,text->point.y,text->str); 
			} 
			break; 
		case ELLIPSE: 
			ELLIPSENODE *ellipse; 
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos); 
			if(ellipse->bDo>0) 
			{ 
			    if(ellipse->bDo!=2) 
			        hPen=CreatePen(ellipse->pen.iStyle,ellipse->pen.iWidth,ellipse->pen.Color); 
			    else 
				    hPen=CreatePen(PS_DASHDOT,1,RGB(255,0,0)); 
			    hOldPen=(HPEN)SelectObject(pDC->m_hDC,hPen); 
			    Arc(pDC->m_hDC,ellipse->rT.left,ellipse->rT.top, 
					ellipse->rT.right,ellipse->rT.bottom,0,0,0,0); 
			    DeleteObject(SelectObject(pDC->m_hDC,hOldPen)); 
			} 
			break; 
		case FILL: 
			FILLNODE *fill; 
			fill=(FILLNODE *)pDoc->RecordList.GetNext(pos); 
			if(fill->bDo) 
			{ 
			   hBrush=CreateHatchBrush(fill->brush.iStyle,fill->brush.Color); 
			   OldBrush=(CBrush *)SelectObject(pDC->m_hDC,hBrush); 
			   pDC->ExtFloodFill(fill->Seed.x,fill->Seed.y,fill->BoundColor, 
				              FLOODFILLSURFACE); 
			   DeleteObject(SelectObject(pDC->m_hDC,OldBrush)); 
			} 
			break; 
		}		 
	} 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CPainterView printing 
//打印处理函数,如没有特别要求,不需添加任何代码即可完成打印 
BOOL CPainterView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CPainterView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CPainterView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CPainterView diagnostics 
 
#ifdef _DEBUG 
void CPainterView::AssertValid() const 
{ 
	CScrollView::AssertValid(); 
} 
 
void CPainterView::Dump(CDumpContext& dc) const 
{ 
	CScrollView::Dump(dc); 
} 
 
CPainterDoc* CPainterView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPainterDoc))); 
	return (CPainterDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CPainterView message handlers 
//处理按下鼠标左键 
void CPainterView::OnLButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	CPen pen(penType,penWidth,PenCurColor),*OldPen; 
	CBrush brush(hatchIndex,CurColor),*OldBrush; 
	CPainterDoc* pDoc=GetDocument(); 
	CDC* dc=GetDC(); 
	OldPen=dc->SelectObject(&pen); 
 
	PrePoint=TempPoint=point; 
	int i; 
 
	if(m_bModify==FALSE){ 
	switch(*DrawType)//根据绘图类型作不同处理 
	{ 
	case SELECT: 
		PickComponent(/*dc*/);//拾取图元 
		break; 
	case TEXT: 
		{//注意在switc-case语句中定义非指针变量必须用括号括起来 
		CEnterTexDlg dlg; 
        if(dlg.DoModal()==IDOK) 
			m_strText=dlg.m_str; 
		} 
 
		CStatusBar* pStatus;//得到状态栏指针 
		pStatus=(CStatusBar*)AfxGetApp()->m_pMainWnd->GetDescendantWindow(ID_VIEW_STATUS_BAR); 
    	pStatus->SetPaneText(0,"选择文本输出点"); 
		 
		if(m_strText==_T("")) 
			break; 
		dc->SetTextColor(PenCurColor); 
        dc->TextOut(point.x,point.y,m_strText); 
		textnode=new TEXTNODE; 
		textnode->point=point; 
		textnode->str=m_strText; 
		textnode->color=PenCurColor; 
		OppIndex+=1; 
		textnode->Index=OppIndex; 
		if(textnode->str!=_T("")) 
		{ 
		    pDoc->RecordList.AddTail(DrawType); 
		    pDoc->RecordList.AddTail(textnode); 
		    m_strText="";//清空字符串 
		} 
		break; 
	case PASTE: 
		DrawStep=1; 
		break; 
	case MOVE: 
		DrawStep=1; 
		break; 
	case LINE: 
		if(!DrawStep) 
		{ 
			linenode=new LINENODE; 
			linenode->Start=point; 
			DrawStep=1; 
		} 
		else 
		{ 
			if(!m_bNoTilt)//如果不处于禁止斜线状态 
				linenode->End=point; 
			else 
			{ 
				if(abs(linenode->Start.x-point.x)>abs(linenode->Start.y-point.y)) 
				{ 
					linenode->End.x=point.x; 
					linenode->End.y=linenode->Start.y; 
				} 
				else 
				{ 
					linenode->End.x=linenode->Start.x; 
					linenode->End.y=point.y; 
				} 
			} 
			DrawStep=0; 
			dc->MoveTo(linenode->Start); 
			dc->LineTo(linenode->End); 
			linenode->pen.Color=PenCurColor; 
			linenode->pen.iStyle=penType; 
			linenode->pen.iWidth=penWidth; 
			OppIndex+=1; 
			linenode->Index=OppIndex; 
			pDoc->RecordList.AddTail(DrawType); 
			pDoc->RecordList.AddTail(linenode); 
		} 
		break; 
	case RECTANGLE: 
		if(!DrawStep) 
		{ 
			rectanglenode=new RECTANGLENODE; 
			rectanglenode->rT.left=point.x; 
			rectanglenode->rT.top=point.y; 
			rectanglenode->rT.right=point.x; 
			rectanglenode->rT.bottom=point.y; 
			DrawStep=1; 
		} 
		break; 
	case TRIANGLE: 
		if(!DrawStep) 
		{ 
			trianglenode=new TRIANGLENODE; 
			trianglenode->rT.left=point.x; 
			trianglenode->rT.top=point.y; 
			trianglenode->rT.right=point.x; 
			trianglenode->rT.bottom=point.y; 
			DrawStep=1; 
		} 
		break; 
	case ELLIPSE: 
		if(!DrawStep) 
		{ 
			ellipsenode=new ELLIPSENODE; 
			ellipsenode->rT.left=point.x; 
			ellipsenode->rT.top=point.y; 
			ellipsenode->rT.right=point.x; 
			ellipsenode->rT.bottom=point.x; 
			DrawStep=1; 
		} 
		break; 
	case FILL: 
		OldBrush=dc->SelectObject(&brush); 
		fillnode=new FILLNODE; 
		fillnode->brush.Color=CurColor; 
		fillnode->brush.iStyle=hatchIndex; 
		fillnode->Seed=point; 
		fillnode->BoundColor=dc->GetPixel(point.x,point.y); 
		dc->ExtFloodFill(fillnode->Seed.x,fillnode->Seed.y,fillnode->BoundColor 
			             ,FLOODFILLSURFACE); 
		pDoc->RecordList.AddTail(DrawType); 
		pDoc->RecordList.AddTail(fillnode); 
		dc->SelectObject(OldBrush); 
		break; 
	default: 
		break; 
	} } 
 
    else if(m_bModify==TRUE) 
	{ 
		POSITION pos=SnapList.GetHeadPosition(); 
		BOOL finish=FALSE; 
		float fFX,fFY; 
	 
		fFX=1.0; 
		fFY=1.0; 
	 
		while(pos!=NULL && !finish) 
		{ 
			int   *index; 
			POINT *pPoint; 
 
		    index=(int *)SnapList.GetNext(pos); 
			pPoint=(POINT *)SnapList.GetNext(pos); 
			CRect rect((pPoint->x-5)*fFX,(pPoint->y-5)*fFY, 
				(pPoint->x+5)*fFX,(pPoint->y+5)*fFY); 
			if(rect.PtInRect(point)) 
			{ 
				finish=TRUE; 
			    m_nModifyIndex=*index; 
				if(!m_bIsRect) 
					m_pModifyPoint=pPoint; 
				else 
				{ 
					for(i=0;i<4;i++) 
					{ 
						m_pModifyPoints[i]=(POINT *)SnapList.GetAt(SnapList.FindIndex(i*2+1)); 
					} 
				} 
				m_nModifyStep=1; 
			} 
		} 
	} 
 
	dc->SelectObject(OldPen); 
	CScrollView::OnLButtonDown(nFlags, point); 
} 
 
//处理选择填充颜色 
void CPainterView::OnColor()  
{ 
	// TODO: Add your control notification handler code here 
	CColorDialog	color; 
 
	if(color.DoModal()==IDOK) 
	{ 
	   CMainFrame *OwnWnd; 
	   OwnWnd=(CMainFrame *)GetParentOwner(); 
	   //获得对话框工具条中填充预览框的指针 
	   CWnd* pWnd = OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_FILL_PREVIEW); 
	   //获得对话框工具条中填充模式组合框的指针 
	   CComboBox* pCBox = (CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_FILL_PATTERN); 
 
	   CRect	rect; 
	   pWnd->GetClientRect(rect);//获得对话框工具条中填充预览框的客户矩形 
	   CDC *dc=pWnd->GetDC(); 
 
	   //以当前填充模式填充预览框,并设置组合框选项 
	   CurColor = color.GetColor(); 
	   int i = pCBox->GetCurSel(); 
	 
	   CBrush	Brush; 
	 
	   if(i==6) 
	   { 
	       Brush.CreateSolidBrush(CurColor); 
		   hatchIndex=SOLIDBRUSH; 
	   } 
	   else 
	   {	 
		   hatchIndex = i; 
		   Brush.CreateHatchBrush( hatchIndex,  CurColor ); 
	   } 
	   dc->FillRect(rect,&Brush); 
	} 
} 
 
//处理选择画笔颜色 
void CPainterView::OnPenColor()  
{ 
	// TODO: Add your control notification handler code here 
	CColorDialog	color; 
	if(color.DoModal()==IDOK) 
	{ 
		CMainFrame *OwnWnd; 
	    OwnWnd=(CMainFrame *)GetParentOwner(); 
		//获得对话框工具条中线型预览框的指针 
	    CWnd* pWnd = OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_PREVIEW); 
		//获得对话框工具条中线型和线宽组合框的指针 
	    CComboBox* pCBox1,*pCBox2; 
		pCBox1= (CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_TYPE); 
		pCBox2= (CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_WIDTH); 
 
		//获得预览框客户区矩形 
	    CRect	rect; 
	    pWnd->GetClientRect(rect); 
	    CDC *dc=pWnd->GetDC(); 
 
		//取出系统画笔颜色与组框选项 
		if(!m_bModify) 
		{ 
			PenCurColor = color.GetColor(); 
		} 
		else 
		{ 
			m_ModifyPen->Color=color.GetColor(); 
		} 
 
		int i = pCBox1->GetCurSel(); 
		int j = pCBox2->GetCurSel(); 
 
 
		//以当前画笔绘制直线填充预览框 
		CBrush	WhiteBrush; 
		WhiteBrush.CreateSolidBrush( 0xffffffff ); 
 
		dc->FillRect(rect,&WhiteBrush); 
 
		CPen pen(i,j+1,PenCurColor),*OldPen; 
		OldPen=dc->SelectObject(&pen); 
		dc->MoveTo(rect.left+5, (rect.bottom-rect.top)/2); 
		dc->LineTo(rect.right-5, (rect.bottom-rect.top)/2); 
		dc->SelectObject(OldPen); 
	} 
} 
 
//处理线宽选择 
void CPainterView::OnSelchangeLineWidth()  
{ 
	// TODO: Add your control notification handler code here 
	CMainFrame *OwnWnd; 
	OwnWnd=(CMainFrame *)GetParentOwner(); 
	//获得对话框工具条中线型预览框的指针 
	CWnd* pWnd = OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_PREVIEW); 
	//获得对话框工具条中线型和线宽组合框的指针 
	CComboBox *pCBox1,*pCBox2; 
	pCBox1= (CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_TYPE); 
	pCBox2= (CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_WIDTH); 
 
	//获得预览框客户区矩形 
	CRect	rect; 
	pWnd->GetClientRect(rect); 
	CDC *dc=pWnd->GetDC(); 
 
	//取出系统画笔颜色与组框选项 
	int i = pCBox1->GetCurSel(); 
	int j = pCBox2->GetCurSel(); 
 
	if(!m_bModify) 
	{ 
		penType = i; 
		penWidth = j+1; 
	} 
	else 
	{ 
		m_ModifyPen->iStyle=i; 
		m_ModifyPen->iWidth=j+1; 
	} 
	//以当前画笔绘制直线填充预览框 
	CBrush	WhiteBrush; 
	WhiteBrush.CreateSolidBrush( 0xffffffff ); 
 
	dc->FillRect(rect,&WhiteBrush); 
 
	CPen pen(penType,penWidth,PenCurColor); 
	dc->SelectObject(&pen); 
 
 
	dc->MoveTo(rect.left+5, (rect.bottom-rect.top)/2); 
	dc->LineTo(rect.right-5, (rect.bottom-rect.top)/2); 
} 
 
//处理线型选择 
void CPainterView::OnSelchangeLineType()  
{ 
	// TODO: Add your control notification handler code here 
	CMainFrame *OwnWnd; 
	OwnWnd=(CMainFrame *)GetParentOwner(); 
	CWnd* pWnd = OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_PREVIEW); 
	CComboBox* pCBox1,*pCBox2; 
	pCBox1= (CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_TYPE); 
	pCBox2= (CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_WIDTH); 
 
	CRect	rect; 
	pWnd->GetClientRect(rect); 
	CDC *dc=pWnd->GetDC(); 
 
	int i = pCBox1->GetCurSel(); 
	int j = pCBox2->GetCurSel(); 
 
//	penType = i; 
//	penWidth = j+1; 
 
	if(!m_bModify) 
	{ 
		penType = i; 
//		penCur.iStyle=penType; 
		penWidth = j+1; 
//		PenColor=PenCurColor; 
	} 
	else 
	{ 
		m_ModifyPen->iStyle=i; 
		m_ModifyPen->iWidth=j+1; 
//		PenColor=m_ModifyPen->Color; 
	} 
 
	CBrush	WhiteBrush; 
	WhiteBrush.CreateSolidBrush( 0xffffffff ); 
 
	dc->FillRect(rect,&WhiteBrush); 
 
	CPen pen(penType,penWidth,PenCurColor); 
    dc->SelectObject(&pen); 
 
	dc->MoveTo(rect.left+5, (rect.bottom-rect.top)/2); 
	dc->LineTo(rect.right-5, (rect.bottom-rect.top)/2); 
} 
 
//处理填充模式选择 
void CPainterView::OnSelchangeFillPattern()  
{ 
	// TODO: Add your control notification handler code here 
	CMainFrame *OwnWnd; 
	OwnWnd=(CMainFrame *)GetParentOwner(); 
	CWnd* pWnd=OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_FILL_PREVIEW); 
	CComboBox* pCBox = (CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_FILL_PATTERN); 
	 
	CRect	rect; 
	pWnd->GetClientRect(rect); 
	CDC *dc=pWnd->GetDC(); 
 
	dc->Rectangle(rect); 
	hatchIndex= pCBox->GetCurSel(); 
	CBrush	Brush; 
	 
	if(hatchIndex== 6) 
	{ 
		Brush.CreateSolidBrush(CurColor); 
		hatchIndex=SOLIDBRUSH; 
	} 
	else 
	{ 
//////////////////////////////////////////////////////////	 
	//#define HS_HORIZONTAL       0       /* ----- */ 
	//#define HS_VERTICAL         1       /* ||||| */ 
	//#define HS_FDIAGONAL        2       /* \\\\\ */ 
	//#define HS_BDIAGONAL        3       /* ///// */ 
	//#define HS_CROSS            4       /* +++++ */ 
	//#define HS_DIAGCROSS        5       /* xxxxx */ 
///////////////////////////////////////////////////////// 
 
		Brush.CreateHatchBrush( hatchIndex,  CurColor ); 
	} 
	dc->FillRect(rect,&Brush); 
} 
 
//绘制直线命令 
void CPainterView::OnDrawLine()  
{ 
	// TODO: Add your command handler code here 
	DrawType=new BYTE; 
	*DrawType=LINE; 
} 
 
//绘制矩形命令 
void CPainterView::OnDrawRectangle()  
{ 
	// TODO: Add your command handler code here 
	DrawType=new BYTE; 
	*DrawType=RECTANGLE; 
} 
 
//处理鼠标释放左键 
void CPainterView::OnLButtonUp(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	CPen pen(penType,penWidth,PenCurColor),*OldPen; 
	CPainterDoc* pDoc=GetDocument(); 
	CDC* dc=GetDC(); 
	OldPen=dc->SelectObject(&pen); 
 
	if(m_bModify==FALSE){ 
	switch(*DrawType) 
	{ 
	case PASTE: 
	case MOVE: 
		MoveCompent(); 
		*DrawType=SELECT; 
		DrawStep=0; 
		break; 
	case RECTANGLE: 
		if(DrawStep==1) 
		{ 
		    rectanglenode->rT.right=point.x; 
		    rectanglenode->rT.bottom=point.y; 
			dc->MoveTo(rectanglenode->rT.left,rectanglenode->rT.top); 
    		dc->LineTo(rectanglenode->rT.right,rectanglenode->rT.top); 
	    	dc->LineTo(rectanglenode->rT.right,rectanglenode->rT.bottom); 
		    dc->LineTo(rectanglenode->rT.left,rectanglenode->rT.bottom); 
			dc->LineTo(rectanglenode->rT.left,rectanglenode->rT.top); 
			rectanglenode->pen.Color=PenCurColor; 
			rectanglenode->pen.iWidth=penWidth; 
			rectanglenode->pen.iStyle=penType; 
			OppIndex+=1; 
			rectanglenode->Index=OppIndex; 
			pDoc->RecordList.AddTail(DrawType); 
			pDoc->RecordList.AddTail(rectanglenode); 
			DrawStep=0; 
		} 
		break; 
	case TRIANGLE: 
		if(DrawStep==1) 
		{ 
			trianglenode->rT.right=point.x; 
			trianglenode->rT.bottom=point.y; 
			DrawTriangle(dc,trianglenode->rT); 
			trianglenode->pen.iWidth=penWidth; 
			trianglenode->pen.iStyle=penType; 
			trianglenode->pen.Color=PenCurColor; 
			OppIndex+=1; 
			trianglenode->Index=OppIndex; 
			pDoc->RecordList.AddTail(DrawType); 
			pDoc->RecordList.AddTail(trianglenode); 
			DrawStep=0; 
		} 
		break; 
	case ELLIPSE: 
		if(DrawStep==1) 
		{ 
			ellipsenode->rT.right=point.x; 
			ellipsenode->rT.bottom=point.y; 
			Arc(dc->m_hDC,ellipsenode->rT.left,ellipsenode->rT.top, 
					ellipsenode->rT.right,ellipsenode->rT.bottom,0,0,0,0); 
			ellipsenode->pen.Color=PenCurColor; 
			ellipsenode->pen.iStyle=penType; 
			ellipsenode->pen.iWidth=penWidth; 
			OppIndex+=1; 
			ellipsenode->Index=OppIndex; 
			pDoc->RecordList.AddTail(DrawType); 
			pDoc->RecordList.AddTail(ellipsenode); 
			DrawStep=0; 
		} 
		break; 
	}} 
 
	else if(m_bModify==TRUE && m_nModifyStep==1) 
	{ 
		m_nModifyStep=0; 
	} 
	Invalidate(); 
	dc->SelectObject(OldPen); 
	CScrollView::OnLButtonUp(nFlags, point); 
} 
 
//处理鼠标移动 
void CPainterView::OnMouseMove(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	CDC* dc=GetDC(); 
	int iR; 
 
	//设置状态栏输出 
	CStatusBar* pStatus=(CStatusBar*) 
		AfxGetApp()->m_pMainWnd->GetDescendantWindow(ID_VIEW_STATUS_BAR); 
	if(pStatus) 
	{ 
		char tbuf[40]; 
		sprintf(tbuf,"(%d,%d)",point.x,point.y); 
		//在状态条的第二个窗格中输出当前鼠标的位置 
		pStatus->SetPaneText(1,tbuf,TRUE); 
		pStatus->SetPaneInfo( 1, ID_SEPARATOR,SBPS_STRETCH, 10); 
	} 
 
	if(m_bModify==FALSE){ 
    //如果绘图未完成则返回 
	if(DrawStep==0 ) 
		return; 
    //否则处理 
	switch(*DrawType) 
	{ 
	case PASTE: 
	case MOVE: 
		iR=dc->SetROP2(R2_NOTXORPEN);//设置XOR绘图方式,擦去原图 
		dc->MoveTo(PrePoint); 
		dc->LineTo(TempPoint); 
		TempPoint=point; 
		dc->MoveTo(PrePoint); 
		dc->LineTo(TempPoint); 
		dc->SetROP2(iR); 
		break; 
	case LINE: 
		iR=dc->SetROP2(R2_NOTXORPEN); 
		dc->MoveTo(linenode->Start); 
		dc->LineTo(PrePoint); 
		dc->MoveTo(linenode->Start); 
		dc->LineTo(point); 
		PrePoint=point; 
		dc->SetROP2(iR); 
		break; 
	case RECTANGLE: 
		iR=dc->SetROP2(R2_NOTXORPEN); 
		dc->Rectangle(&rectanglenode->rT); 
		rectanglenode->rT.bottom=point.y; 
		rectanglenode->rT.right=point.x; 
		dc->Rectangle(&rectanglenode->rT); 
		dc->SetROP2(iR); 
		break; 
	case TRIANGLE: 
		iR=dc->SetROP2(R2_NOTXORPEN); 
		DrawTriangle(dc,trianglenode->rT); 
		trianglenode->rT.bottom=point.y; 
		trianglenode->rT.right=point.x; 
		DrawTriangle(dc,trianglenode->rT); 
		dc->SetROP2(iR); 
		break; 
	case ELLIPSE: 
		iR=dc->SetROP2(R2_NOTXORPEN); 
		Arc(dc->m_hDC,ellipsenode->rT.left,ellipsenode->rT.top, 
					ellipsenode->rT.right,ellipsenode->rT.bottom,0,0,0,0); 
		ellipsenode->rT.bottom=point.y; 
		ellipsenode->rT.right=point.x; 
		Arc(dc->m_hDC,ellipsenode->rT.left,ellipsenode->rT.top, 
					ellipsenode->rT.right,ellipsenode->rT.bottom,0,0,0,0); 
		dc->SetROP2(iR); 
		break; 
	}} 
	else if(m_bModify==TRUE && m_nModifyStep==1) 
	{ 
		float fFX,fFY; 
		CClientDC DC(this); 
	 
		fFX=1.; 
		fFY=1.; 
 
	    CPainterDoc *pDoc=GetDocument(); 
	    POSITION pos=pDoc->RecordList.GetHeadPosition(),TempPos; 
	    int finish=0; 
 
	    while(pos!=NULL && finish<=0) 
		{ 
		    BYTE *style; 
		    TempPos=pos; 
		    style=(BYTE *)pDoc->RecordList.GetNext(pos); 
		    switch(*style) 
			{ 
		      case LINE: 
			      LINENODE *line; 
			      line=(LINENODE *)pDoc->RecordList.GetNext(pos); 
			      iR=DC.SetROP2(R2_NOTXORPEN); 
			      DrawModifyRec(&DC); 
			      m_pModifyPoint->x=point.x/fFX; 
			      m_pModifyPoint->y=point.y/fFY; 
			      DrawModifyRec(&DC); 
			      DC.SetROP2(iR); 
			  break; 
		      case TEXT: 
			      TEXTNODE *text; 
			      text=(TEXTNODE *)pDoc->RecordList.GetNext(pos); 
		      break; 
		      case RECTANGLE: 
			      RECTANGLENODE *rectangle; 
			      rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos); 
 			      iR=DC.SetROP2(R2_NOTXORPEN); 
			      DrawModifyRec(&DC); 
			      if(m_nModifyIndex==0) 
				  { 
				      rectangle->rT.left=point.x/fFX; 
				      rectangle->rT.top=point.y/fFY; 
				  } 
			      else if(m_nModifyIndex==1) 
				  { 
				     rectangle->rT.right=point.x/fFX; 
				     rectangle->rT.top=point.y/fFY; 
				  } 
			      else if(m_nModifyIndex==2) 
				  { 
				     rectangle->rT.right=point.x/fFX; 
				     rectangle->rT.bottom=point.y/fFY; 
				  } 
			      else if(m_nModifyIndex==3) 
				  { 
				     rectangle->rT.left=point.x/fFX; 
				     rectangle->rT.bottom=point.y/fFY; 
				  } 
			      RectToPoints(rectangle->rT,*m_pModifyPoints); 
			      DrawModifyRec(&DC); 
			      DC.SetROP2(iR); 
			  break; 
		      case TRIANGLE: 
			      TRIANGLENODE *triangle; 
			      triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos); 
 			      iR=DC.SetROP2(R2_NOTXORPEN); 
			      DrawModifyRec(&DC); 
			      m_pModifyPoint->x=point.x/fFX; 
			      m_pModifyPoint->y=point.y/fFY; 
			      DrawModifyRec(&DC); 
			      DC.SetROP2(iR); 
			  break; 
		      case ELLIPSE: 
			      ELLIPSENODE *ellipse; 
			      ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos); 
			      iR=DC.SetROP2(R2_NOTXORPEN); 
			      DrawModifyRec(&DC); 
			      if(m_nModifyIndex==0) 
				  { 
				      ellipse->rT.left=point.x/fFX; 
				      ellipse->rT.top=point.y/fFY; 
				  } 
			      else if(m_nModifyIndex==1) 
				  { 
				      ellipse->rT.right=point.x/fFX; 
				      ellipse->rT.top=point.y/fFY; 
				  } 
			      else if(m_nModifyIndex==2) 
				  { 
				      ellipse->rT.right=point.x/fFX; 
				      ellipse->rT.bottom=point.y/fFY; 
				  } 
			      else if(m_nModifyIndex==3) 
				  { 
				      ellipse->rT.left=point.x/fFX; 
				      ellipse->rT.bottom=point.y/fFY; 
				  } 
			      RectToPoints(ellipse->rT,*m_pModifyPoints); 
			      DrawModifyRec(&DC); 
			      DC.SetROP2(iR); 
			  break; 
			} 
		} 
	} 
 
	CScrollView::OnMouseMove(nFlags, point); 
} 
 
//绘制椭圆命令 
void CPainterView::OnDrawEllipse()  
{ 
	// TODO: Add your command handler code here 
	DrawType=new BYTE; 
	*DrawType=ELLIPSE; 
} 
 
//填充命令 
void CPainterView::OnDrawFill()  
{ 
	// TODO: Add your command handler code here 
	DrawType=new BYTE; 
	*DrawType=FILL; 
} 
 
//判断图元是否被选择 
void CPainterView::PickComponent(/*CDC *pDC*/) 
{ 
	CPainterDoc *pDoc=GetDocument(); 
	BOOL IsPicked=FALSE; 
	 
	POSITION pos=pDoc->RecordList.GetHeadPosition(); 
	while(pos!=NULL) 
	{ 
		BYTE *drawtype; 
		drawtype=(BYTE*)pDoc->RecordList.GetNext(pos); 
		switch(*drawtype) 
		{ 
		case LINE: 
			LINENODE *line; 
			line=(LINENODE *)pDoc->RecordList.GetNext(pos); 
			if(line->bDo>0)//如果图元显示则继续处理 
			{ 
			    IsPicked=PickLine(line); 
			    if(IsPicked) 
				{ 
					m_IsSelected=TRUE; 
				    line->bDo=2; 
				} 
			    else if(!bShiftDown)//如果没有按下Shift键,而对其它图元进行选择 
				{ 
					if(line->bDo==2/* || line->bDo==2*/) 
						line->bDo=1; 
				} 
			} 
			break; 
		case RECTANGLE: 
			RECTANGLENODE *rectangle; 
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(rectangle->bDo>0)//如果图元显示则继续处理 
			{ 
			    IsPicked=PickRectangle(rectangle); 
			    if(IsPicked) 
				{ 
					m_IsSelected=TRUE; 
					    rectangle->bDo=2; 
				} 
			    else if(!bShiftDown)//如果没有按下Shift键,而对其它图元进行选择 
				{ 
					if(rectangle->bDo==2 /*|| rectangle->bDo==2*/) 
						rectangle->bDo=1; 
				} 
			} 
			break; 
		case TRIANGLE: 
			TRIANGLENODE *triangle; 
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(triangle->bDo>0)//如果图元显示则继续处理 
			{ 
				IsPicked=PickTriangle(triangle->rT); 
				if(IsPicked) 
				{ 
					m_IsSelected=TRUE; 
					triangle->bDo=2; 
				} 
				else if(!bShiftDown)//如果没有按下Shift键,而对其它图元进行选择 
				{ 
					if(triangle->bDo==2/* ||triangle->bDo==2*/) 
						triangle->bDo=1; 
				} 
			} 
			break; 
		case TEXT: 
			TEXTNODE *text; 
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos); 
			if(text->bDo>0) 
			{ 
				IsPicked=PickText(text); 
				if(IsPicked) 
				{ 
					m_IsSelected=TRUE; 
					text->bDo=2; 
				} 
				else if(!bShiftDown)//如果没有按下Shift键,而对其它图元进行选择 
				{ 
					if(text->bDo==2 /*|| text->bDo==2*/) 
						text->bDo=1; 
				} 
			} 
			break; 
		case ELLIPSE: 
			ELLIPSENODE *ellipse; 
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos); 
			if(ellipse->bDo>0)//如果图元显示则继续处理 
			{ 
			    IsPicked=PickEllipse(ellipse); 
			    if(IsPicked) 
				{ 
					m_IsSelected=TRUE; 
				    ellipse->bDo=2; 
				} 
			    else if(!bShiftDown)//如果没有按下Shift键,而对其它图元进行选择 
				{ 
					if(ellipse->bDo==2 /*|| ellipse->bDo==3*/) 
						ellipse->bDo=1; 
				} 
			} 
			break; 
		}		 
	} 
} 
 
//拾取直线 
BOOL CPainterView::PickLine(LINENODE *linenode) 
{ 
	BOOL	returncode=FALSE; 
	double	x=PrePoint.x-linenode->Start.x; 
	double	y=PrePoint.y-linenode->Start.y; 
 
	double	a=linenode->End.x-linenode->Start.x; 
	double	b=linenode->End.y-linenode->Start.y; 
	double	c=sqrt(a*a+b*b); 
 
	double	sin=b/c; 
	double  cos=a/c; 
 
	double	chg_x=x*cos+y*sin; 
	double	chg_y=-x*sin+y*cos; 
 
	if(fabs(chg_y)<5.0 &&(chg_x>=0&&chg_x<=c)) 
		returncode=TRUE; 
 
	return returncode;	 
} 
 
//拾取椭圆 
BOOL CPainterView::PickEllipse(ELLIPSENODE *ellipsenode) 
{ 
	CRgn ellipse; 
	BOOL returncode; 
	POINT point[4]; 
	 
	point[0].x=ellipsenode->rT.left; 
	point[0].y=ellipsenode->rT.top; 
	point[1].x=ellipsenode->rT.right; 
	point[1].y=ellipsenode->rT.top; 
	point[2].x=ellipsenode->rT.right; 
	point[2].y=ellipsenode->rT.bottom; 
	point[3].x=ellipsenode->rT.left; 
	point[3].y=ellipsenode->rT.bottom; 
	ellipse.CreatePolygonRgn(point,4,WINDING); 
 
	return returncode=ellipse.PtInRegion(PrePoint); 
} 
 
//拾取矩形 
BOOL CPainterView::PickRectangle(RECTANGLENODE *rectanglenode) 
{ 
	BOOL   returncode=FALSE; 
 
	if(fabs(PrePoint.x-rectanglenode->rT.left)<5.0|| 
		   fabs(PrePoint.x-rectanglenode->rT.right)<5.0) 
	{ 
		if((PrePoint.y>=rectanglenode->rT.top && PrePoint.y<=rectanglenode->rT.bottom) 
			||(PrePoint.y<=rectanglenode->rT.top && PrePoint.y>=rectanglenode->rT.bottom)) 
		{ 
			returncode=TRUE; 
		} 
	} 
 
	if(fabs(PrePoint.y-rectanglenode->rT.top)<5.0||fabs(PrePoint.y-rectanglenode->rT.bottom)<5.0) 
	{ 
		if((PrePoint.x>=rectanglenode->rT.left && PrePoint.x<=rectanglenode->rT.right) 
			||(PrePoint.x<=rectanglenode->rT.left && PrePoint.y>=rectanglenode->rT.right)) 
		{ 
			returncode=TRUE; 
		} 
	} 
 
	return returncode; 
} 
 
//处理选择命令 
void CPainterView::OnDrawSelect()  
{ 
	// TODO: Add your command handler code here 
	DrawType=new BYTE; 
	*DrawType=SELECT;	 
} 
 
//处理移动命令 
void CPainterView::OnModifyMove()  
{ 
	// TODO: Add your command handler code here 
	DrawType=new BYTE; 
	*DrawType=MOVE; 
} 
 
//移动图元 
void CPainterView::MoveCompent() 
{ 
	CPainterDoc *pDoc=GetDocument(); 
	POSITION pos=pDoc->RecordList.GetHeadPosition(); 
	int x_off=TempPoint.x-PrePoint.x; 
	int y_off=TempPoint.y-PrePoint.y; 
	if(*DrawType==MOVE) 
		movenode=new MOVENODE; 
	int index=0; 
 
	while(pos!=NULL) 
	{ 
		BYTE *style; 
		style=(BYTE *)pDoc->RecordList.GetNext(pos); 
 
		switch(*style) 
		{ 
		case LINE: 
			LINENODE *line; 
			line=(LINENODE *)pDoc->RecordList.GetNext(pos); 
			if(line->bDo==2) 
			{ 
				if(*DrawType==MOVE) 
				{ 
					line->bDo=5; 
					line->End.x+=x_off; 
				    line->End.y+=y_off; 
				    line->Start.x+=x_off; 
				    line->Start.y+=y_off; 
					movenode->Index[index]=line->Index; 
					index+=1; 
				} 
				else 
				{ 
					line->bDo=3; 
					line->End.x+=x_off; 
				    line->End.y+=y_off; 
				    line->Start.x+=x_off; 
				    line->Start.y+=y_off; 
				} 
			} 
		break; 
		case RECTANGLE: 
			RECTANGLENODE *rectangle; 
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(rectangle->bDo==2) 
			{ 
				if(*DrawType==MOVE) 
				{ 
					 rectangle->bDo=5; 
			         rectangle->rT.left+=x_off; 
			         rectangle->rT.right+=x_off; 
			         rectangle->rT.bottom+=y_off; 
			         rectangle->rT.top+=y_off; 
					 movenode->Index[index]=rectangle->Index; 
					 index+=1; 
				} 
				else 
				{ 
					 rectangle->bDo=3; 
					 rectangle->rT.left+=x_off; 
			         rectangle->rT.right+=x_off; 
			         rectangle->rT.bottom+=y_off; 
			         rectangle->rT.top+=y_off; 
				} 
			} 
			break; 
		case TRIANGLE: 
			TRIANGLENODE *triangle; 
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(triangle->bDo==2) 
			{ 
				triangle->bDo=-2; 
				if(*DrawType==MOVE) 
				{ 
					 triangle->bDo=5; 
			         triangle->rT.left+=x_off; 
			         triangle->rT.right+=x_off; 
			         triangle->rT.bottom+=y_off; 
			         triangle->rT.top+=y_off; 
					 movenode->Index[index]=triangle->Index; 
					 index+=1; 
				} 
				else 
				{ 
					 triangle->bDo=3; 
					 triangle->rT.left+=x_off; 
			         triangle->rT.right+=x_off; 
			         triangle->rT.bottom+=y_off; 
			         triangle->rT.top+=y_off; 
				} 
			} 
			break; 
		case TEXT: 
			TEXTNODE *text; 
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos); 
			if(text->bDo==2) 
			{ 
				if(*DrawType==MOVE) 
				{ 
					 text->bDo=5; 
			         text->point.x+=x_off; 
			         text->point.y+=y_off; 
					 movenode->Index[index]=text->Index; 
					 index+=1; 
				} 
				else 
				{ 
					 text->bDo=3; 
					 text->point.x+=x_off; 
			         text->point.y+=y_off; 
				} 
			} 
			break; 
		case ELLIPSE: 
			ELLIPSENODE *ellipse; 
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos); 
			if(ellipse->bDo==2) 
			{ 
				if(*DrawType==MOVE) 
				{ 
					ellipse->bDo=5; 
				    ellipse->rT.left+=x_off; 
				    ellipse->rT.right+=x_off; 
				    ellipse->rT.top+=y_off; 
				    ellipse->rT.bottom+=y_off; 
					movenode->Index[index]=ellipse->Index; 
					index+=1; 
				} 
				else 
				{ 
					ellipse->bDo=3; 
					ellipse->rT.left+=x_off; 
				    ellipse->rT.right+=x_off; 
				    ellipse->rT.top+=y_off; 
				    ellipse->rT.bottom+=y_off; 
				} 
			} 
			break; 
		default: 
			pDoc->RecordList.GetNext(pos); 
			break; 
		} 
	} 
 
	if(*DrawType==MOVE) 
	{ 
	    movenode->x_off=x_off; 
	    movenode->y_off=y_off; 
	    movenode->iCompNum=index; 
	    pDoc->RecordList.AddTail(&movenode->bType); 
	    pDoc->RecordList.AddTail(movenode); 
	} 
} 
 
//设置删除命令状态 
void CPainterView::OnUpdateEditDelete(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(m_IsSelected) 
		pCmdUI->Enable(TRUE && !m_bModify); 
	else 
		pCmdUI->Enable(FALSE); 
} 
 
//处理删除命令 
void CPainterView::OnEditDelete()  
{ 
	// TODO: Add your command handler code here 
	CPainterDoc *pDoc=GetDocument(); 
	POSITION pos,TempPos,TempPos1; 
	pos=pDoc->RecordList.GetHeadPosition(); 
 
	while(pos!=NULL) 
	{ 
    	BYTE* style; 
		TempPos1=pos;//记录图元文件类型的位置 
		style=(BYTE*)pDoc->RecordList.GetNext(pos); 
		TempPos=pos;//记录图元文件的位置 
		switch(*style) 
		{ 
		case LINE: 
			LINENODE *line; 
			line=(LINENODE*)pDoc->RecordList.GetNext(pos); 
			if(line->bDo==2) 
			{ 
				pDoc->RecordList.RemoveAt(TempPos1);//删除图元文件类型 
				pDoc->RecordList.RemoveAt(TempPos);//删除图元文件 
			} 
			break; 
		case TEXT: 
			TEXTNODE *text; 
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos); 
			if(text->bDo==2) 
			{ 
				pDoc->RecordList.RemoveAt(TempPos1); 
				pDoc->RecordList.RemoveAt(TempPos); 
			} 
			break; 
		case RECTANGLE: 
			RECTANGLENODE *rectangle; 
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(rectangle->bDo==2) 
			{ 
				pDoc->RecordList.RemoveAt(TempPos1);//删除图元文件类型 
				pDoc->RecordList.RemoveAt(TempPos);//删除图元文件 
			} 
			break; 
		case TRIANGLE: 
			TRIANGLENODE *triangle; 
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(triangle->bDo==2) 
			{ 
				pDoc->RecordList.RemoveAt(TempPos1); 
				pDoc->RecordList.RemoveAt(TempPos); 
			} 
			break; 
		case ELLIPSE: 
			ELLIPSENODE *ellipse; 
			ellipse=(ELLIPSENODE*)pDoc->RecordList.GetNext(pos); 
			if(ellipse->bDo==2) 
			{ 
				pDoc->RecordList.RemoveAt(TempPos1);//删除图元文件类型 
				pDoc->RecordList.RemoveAt(TempPos);//删除图元文件 
			} 
			break; 
		} 
	} 
	Invalidate(); 
} 
 
//处理拷贝命令 
void CPainterView::OnEditCopy()  
{ 
	// TODO: Add your command handler code here 
	CPainterDoc *pDoc=GetDocument(); 
	POSITION pos=pDoc->RecordList.GetHeadPosition(); 
	pDoc->RecordCopy.RemoveAll(); 
	int index=0; 
	if(*DrawType==CUT) 
		cutnode=new CUTNODE; 
 
	while(pos!=NULL) 
	{ 
		BYTE *style; 
		style=(BYTE *)pDoc->RecordList.GetNext(pos); 
 
		switch(*style) 
		{ 
		case LINE: 
			LINENODE *line; 
			line=(LINENODE *)pDoc->RecordList.GetNext(pos); 
			if(line->bDo==2)//如果图元处于被选择状态 
			{ 
				line->bDo=1; 
				LINENODE *newline; 
				newline=new LINENODE;//初始化指针 
				memcpy(newline,line,sizeof(LINENODE)); 
				pDoc->RecordCopy.Add(style); 
				pDoc->RecordCopy.Add(newline); 
				if(*DrawType==CUT) 
				{ 
					line->bDo=-6; 
					cutnode->Index[index]=line->Index; 
					index+=1; 
				} 
			} 
		break; 
		case TEXT: 
			TEXTNODE *text; 
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos); 
			if(text->bDo==2) 
			{ 
				text->bDo=1; 
				TEXTNODE *newtext; 
				newtext=new TEXTNODE; 
				memcpy(newtext,text,sizeof(TEXTNODE)); 
				pDoc->RecordCopy.Add(style); 
				pDoc->RecordCopy.Add(newtext); 
				if(*DrawType==CUT) 
				{ 
					text->bDo=-6; 
					cutnode->Index[index]=text->Index; 
					index+=1; 
				} 
			} 
			break; 
		case RECTANGLE: 
			RECTANGLENODE *rectangle; 
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(rectangle->bDo==2) 
			{ 
				rectangle->bDo=1; 
				RECTANGLENODE *newrectangle; 
				newrectangle=new RECTANGLENODE; 
				memcpy(newrectangle,rectangle,sizeof(RECTANGLENODE)); 
				newrectangle->bDo=3; 
				pDoc->RecordCopy.Add(style); 
				pDoc->RecordCopy.Add(newrectangle); 
				if(*DrawType==CUT) 
				{ 
					rectangle->bDo=-6; 
					cutnode->Index[index]=rectangle->Index; 
					index+=1; 
				} 
			} 
			break; 
		case TRIANGLE: 
			TRIANGLENODE *triangle; 
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(triangle->bDo==2) 
			{ 
				triangle->bDo=1; 
				TRIANGLENODE *newtriangle; 
				newtriangle=new TRIANGLENODE; 
				memcpy(newtriangle,triangle,sizeof(TRIANGLENODE)); 
				newtriangle->bDo=3; 
				pDoc->RecordCopy.Add(style); 
				pDoc->RecordCopy.Add(newtriangle); 
				if(*DrawType==CUT) 
				{ 
					triangle->bDo=-6; 
					cutnode->Index[index]=triangle->Index; 
					index+=1; 
				} 
			} 
			break; 
		case ELLIPSE: 
			ELLIPSENODE *ellipse; 
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos); 
			if(ellipse->bDo==2) 
			{ 
				ellipse->bDo=1; 
				ELLIPSENODE *newellipse; 
				newellipse=new ELLIPSENODE; 
				memcpy(newellipse,ellipse,sizeof(ELLIPSENODE)); 
				pDoc->RecordCopy.Add(style); 
				pDoc->RecordCopy.Add(newellipse); 
				if(*DrawType==CUT) 
				{ 
					ellipse->bDo=-6; 
					cutnode->Index[index]=ellipse->Index; 
					index+=1; 
				} 
			} 
			break; 
		} 
	} 
 
	if(pDoc->RecordCopy.GetSize())  //如果拷贝数组不为空 
		m_bCopy=TRUE; 
	if(*DrawType==CUT) 
	{ 
		cutnode->iCompNum=index; 
		pDoc->RecordList.AddTail(&cutnode->bType); 
		pDoc->RecordList.AddTail(cutnode); 
	} 
	m_IsSelected=0; 
	Invalidate(); 
} 
 
//设置拷贝命令状态 
void CPainterView::OnUpdateEditCopy(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(m_IsSelected)//如果选择了图元则允许执行该命令 
		pCmdUI->Enable(TRUE && !m_bModify); 
	else//否则不能执行 
		pCmdUI->Enable(FALSE); 
} 
 
//处理粘贴命令 
void CPainterView::OnEditPaste()  
{ 
	// TODO: Add your command handler code here 
	pastenode=new PASTENODE; 
	DrawType=new BYTE; 
	*DrawType=PASTE; 
	int i,index=0; 
	CPainterDoc *pDoc=GetDocument(); 
 
	CStatusBar* pStatus;//得到状态栏指针 
	pStatus=(CStatusBar*)AfxGetApp()->m_pMainWnd->GetDescendantWindow(ID_VIEW_STATUS_BAR); 
   	pStatus->SetPaneText(0,"拖动图元到指定位置"); 
	 
	for(i=0;iRecordCopy.GetSize();) 
	{ 
		BYTE *style; 
		style=(BYTE *)pDoc->RecordCopy.GetAt(i);//从复制矩阵中取出图元类型 
		i+=1; 
		switch(*style) 
		{ 
		case LINE: 
			LINENODE *line; 
			line=(LINENODE *)pDoc->RecordCopy.GetAt(i);//从复制矩阵中取出图元 
			//将复制图元移动一定位移以与原图元分别 
			line->End.x+=10; 
			line->End.y+=10; 
			line->bDo=2; 
			OppIndex+=1; 
			line->Index=OppIndex; 
			pastenode->Index[index]=line->Index; 
			index+=1; 
			//添加复制图元到链表 
			pDoc->RecordList.AddTail(style); 
			pDoc->RecordList.AddTail(line); 
			break; 
		case TEXT: 
			TEXTNODE *text; 
			text=(TEXTNODE *)pDoc->RecordCopy.GetAt(i); 
			text->point.x+=10; 
			text->point.y+=10; 
			text->bDo=2; 
			OppIndex+=1; 
			text->Index=OppIndex; 
			pastenode->Index[index]=text->Index; 
			index+=1; 
			pDoc->RecordList.AddTail(style); 
			pDoc->RecordList.AddTail(text); 
			break; 
		case RECTANGLE: 
			RECTANGLENODE *rectangle; 
			rectangle=(RECTANGLENODE *)pDoc->RecordCopy.GetAt(i); 
			rectangle->rT.left+=10; 
			rectangle->rT.right+=10; 
			rectangle->rT.top-=10; 
			rectangle->rT.bottom-=10; 
			rectangle->bDo=2; 
			OppIndex+=1; 
			rectangle->Index=OppIndex; 
			pastenode->Index[index]=rectangle->Index; 
			index+=1; 
			pDoc->RecordList.AddTail(style); 
			pDoc->RecordList.AddTail(rectangle); 
			break; 
		case TRIANGLE: 
			TRIANGLENODE *triangle; 
			triangle=(TRIANGLENODE *)pDoc->RecordCopy.GetAt(i); 
			triangle->rT.left+=10; 
			triangle->rT.right+=10; 
			triangle->rT.bottom-=10; 
			triangle->rT.top-=10; 
			triangle->bDo=2; 
			OppIndex+=1; 
			triangle->Index=OppIndex; 
			pastenode->Index[index]=triangle->Index; 
			index+=1; 
			pDoc->RecordList.AddTail(style); 
			pDoc->RecordList.AddTail(triangle); 
			break; 
		case ELLIPSE: 
			ELLIPSENODE *ellipse; 
			ellipse=(ELLIPSENODE *)pDoc->RecordCopy.GetAt(i); 
			ellipse->rT.left+=10; 
			ellipse->rT.right+=10; 
			ellipse->bDo=2; 
			OppIndex+=1; 
			ellipse->Index=OppIndex; 
			pastenode->Index[index]=ellipse->Index; 
			index+=1; 
			pDoc->RecordList.AddTail(style); 
			pDoc->RecordList.AddTail(ellipse); 
			break; 
		} 
		i+=1; 
	} 
 
	pastenode->iCompNum=index; 
	pDoc->RecordList.AddTail(&pastenode->bType); 
	pDoc->RecordList.AddTail(pastenode); 
	Invalidate(); 
} 
 
//设置粘贴命令状态 
void CPainterView::OnUpdateEditPaste(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(m_bCopy)//如果存在拷贝图元则允许执行该命令 
		pCmdUI->Enable(TRUE && !m_bModify); 
	else//否则禁止该命令 
		pCmdUI->Enable(FALSE);	 
} 
 
 
void CPainterView::OnEditCut()  
{ 
	// TODO: Add your command handler code here 
	DrawType=new BYTE; 
	*DrawType=CUT; 
	DrawStep=1; 
	OnEditCopy(); 
} 
 
void CPainterView::OnUpdateEditCut(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(m_IsSelected) 
		pCmdUI->Enable(TRUE && !m_bModify); 
	else 
		pCmdUI->Enable(FALSE); 
} 
 
void CPainterView::OnEditRedo()  
{ 
	// TODO: Add your command handler code here 
	CPainterDoc *pDoc=GetDocument(); 
	POSITION pos=pDoc->RecordList.GetHeadPosition(),TempPos; 
	DrawType=new BYTE; 
	*DrawType=REDO; 
	int finish=0; 
 
	while(pos!=NULL && finish<=0) 
	{ 
		BYTE *style; 
		TempPos=pos; 
		style=(BYTE *)pDoc->RecordList.GetNext(pos); 
		switch(*style) 
		{ 
		case LINE: 
			LINENODE *line; 
			line=(LINENODE *)pDoc->RecordList.GetNext(pos); 
			if(line->bDo==0) 
			{ 
				line->bDo=1; 
				finish=1; 
			} 
			break; 
		case TEXT: 
			TEXTNODE *text; 
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos); 
			if(text->bDo==0) 
			{ 
				text->bDo=1; 
				finish=1; 
			} 
			break; 
		case FILL: 
			FILLNODE *fill; 
			fill=(FILLNODE *)pDoc->RecordList.GetNext(pos); 
			if(fill->bDo==0) 
			{ 
				fill->bDo=1; 
				finish=1; 
			} 
			break; 
		case RECTANGLE: 
			RECTANGLENODE *rectangle; 
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(rectangle->bDo==0) 
			{ 
				rectangle->bDo=1; 
				finish=1; 
			} 
			break; 
		case TRIANGLE: 
			TRIANGLENODE *triangle; 
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(triangle->bDo==0) 
			{ 
				triangle->bDo=1; 
				finish=1; 
			} 
			break; 
		case ELLIPSE: 
			ELLIPSENODE *ellipse; 
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos); 
			if(ellipse->bDo<=0) 
			{ 
				ellipse->bDo=1; 
				finish=1; 
			} 
			break; 
		case MOVE: 
			MOVENODE *move; 
			move=(MOVENODE *)pDoc->RecordList.GetNext(pos); 
			if(move->bDo==0) 
			{ 
				move->bDo=1; 
				UndoMove(move); 
				finish=1; 
			} 
			break; 
		case PASTE: 
			PASTENODE *paste; 
			paste=(PASTENODE *)pDoc->RecordList.GetNext(pos); 
			if(paste->bDo==0) 
			{ 
				paste->bDo=1; 
				UndoPaste(paste); 
				finish=1; 
			} 
			break; 
		case CUT: 
			CUTNODE *cut; 
			cut=(CUTNODE *)pDoc->RecordList.GetNext(pos); 
			if(cut->bDo==0) 
			{ 
				cut->bDo=1; 
				UndoCut(cut); 
				finish=1; 
			} 
			break; 
		} 
	} 
	if(!finish) 
		m_bRedo=0; 
	*DrawType=SELECT; 
	Invalidate(); 
} 
 
void CPainterView::OnUpdateEditUndo(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	CPainterDoc *pDoc=GetDocument(); 
	POSITION pos=pDoc->RecordList.GetTailPosition(); 
	if(pos) 
		pCmdUI->Enable(!m_bModify); 
	else 
	{ 
		pCmdUI->Enable(FALSE); 
		m_bUndo=FALSE; 
	} 
} 
 
void CPainterView::OnUpdateEditRedo(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(m_bUndo) 
		pCmdUI->Enable(!m_bModify); 
	else 
		pCmdUI->Enable(FALSE); 
} 
 
void CPainterView::OnEditUndo()  
{ 
	// TODO: Add your command handler code here 
	m_bUndo=TRUE; 
	CPainterDoc *pDoc=GetDocument(); 
	POSITION pos=pDoc->RecordList.GetTailPosition(),TempPos; 
	DrawType=new BYTE; 
	*DrawType=UNDO; 
	int finish=0; 
 
	while(pos!=NULL && finish<=0) 
	{ 
		BYTE *style; 
		TempPos=pos; 
		pDoc->RecordList.GetPrev(pos); 
		style=(BYTE *)pDoc->RecordList.GetPrev(pos); 
		switch(*style) 
		{ 
		case LINE: 
			LINENODE *line; 
			line=(LINENODE *)pDoc->RecordList.GetAt(TempPos); 
			if(line->bDo==1 || line->bDo==7) 
			{ 
				line->bDo=0; 
				finish=1; 
			} 
			break; 
		case TEXT: 
			TEXTNODE *text; 
			text=(TEXTNODE *)pDoc->RecordList.GetAt(TempPos); 
			if(text->bDo==1 || text->bDo==7) 
			{ 
				text->bDo=0; 
				finish=1; 
			} 
			break; 
		case FILL: 
			FILLNODE *fill; 
			fill=(FILLNODE *)pDoc->RecordList.GetAt(TempPos); 
			if(fill->bDo==1 || fill->bDo==7) 
			{ 
				fill->bDo=0; 
				finish=1; 
			} 
			break; 
		case RECTANGLE: 
			RECTANGLENODE *rectangle; 
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetAt(TempPos); 
			if(rectangle->bDo==1 || rectangle->bDo==7) 
			{ 
				rectangle->bDo=0; 
				finish=1; 
			} 
			break; 
		case TRIANGLE: 
			TRIANGLENODE *triangle; 
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetAt(TempPos); 
			if(triangle->bDo==1 || triangle->bDo==7) 
			{ 
				triangle->bDo=0; 
				finish=1; 
			} 
			break; 
		case ELLIPSE: 
			ELLIPSENODE *ellipse; 
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetAt(TempPos); 
			if(ellipse->bDo==1 || ellipse->bDo==7) 
			{ 
				ellipse->bDo=0; 
				finish=1; 
			} 
			break; 
		case MOVE: 
			MOVENODE *move; 
			move=(MOVENODE *)pDoc->RecordList.GetAt(TempPos); 
			if(move->bDo==1) 
			{ 
			    UndoMove(move); 
			    finish=1; 
			    move->bDo=0; 
			} 
			break; 
		case PASTE: 
			PASTENODE *paste; 
			paste=(PASTENODE *)pDoc->RecordList.GetAt(TempPos); 
			if(paste->bDo==1) 
			{ 
				UndoPaste(paste); 
				finish=1; 
				paste->bDo=0; 
			} 
			break; 
		case CUT: 
			CUTNODE *cut; 
			cut=(CUTNODE *)pDoc->RecordList.GetAt(TempPos); 
			if(cut->bDo==1) 
			{ 
				UndoCut(cut); 
				finish=1; 
				cut->bDo=0; 
			} 
		} 
	} 
	if(!finish) 
		m_bUndo=0; 
	Invalidate(); 
	*DrawType=SELECT; 
} 
 
//画三角形 
void CPainterView::DrawTriangle(CDC * pDC,RECT rect) 
{ 
	pDC->MoveTo(rect.left,rect.top); 
	pDC->LineTo(rect.right,(rect.top+rect.bottom)/2); 
	pDC->LineTo(rect.left,rect.bottom); 
	pDC->LineTo(rect.left,rect.top); 
} 
 
//绘制三角形 
void CPainterView::OnDrawTriangle()  
{ 
	// TODO: Add your command handler code here 
	DrawType=new BYTE; 
	*DrawType=TRIANGLE;	 
} 
 
//检查点是否在三角形内部以决定是否此三角形被选择 
BOOL CPainterView::PickTriangle(RECT rect) 
{ 
	//另一种拾取方法 
	CRgn Triangle; 
	BOOL returncode; 
	POINT point[3]; 
	point[0].x=rect.left; 
	point[0].y=rect.top; 
	point[1].x=rect.right; 
	point[1].y=(rect.top+rect.bottom)/2; 
	point[2].x=rect.left; 
	point[2].y=rect.bottom; 
	Triangle.CreatePolygonRgn(point,3,WINDING); 
	returncode=Triangle.PtInRegion(PrePoint); 
	Triangle.DeleteObject(); 
	return returncode; 
} 
 
//绘制文本 
void CPainterView::OnText()  
{ 
	// TODO: Add your command handler code here 
	DrawType=new BYTE; 
	*DrawType=TEXT; 
} 
 
//选择文本 
BOOL CPainterView::PickText(/*POINT point*/TEXTNODE *text) 
{ 
	CClientDC dc(this); 
	CSize TextSize; 
	CRect TextRect; 
	BOOL returncode; 
 
	TextRect.top=text->point.x; 
	TextRect.left=text->point.y; 
	TextSize=dc.GetTextExtent(text->str); 
	TextRect.bottom=text->point.x+TextSize.cx; 
	TextRect.right=text->point.y+TextSize.cy; 
	returncode=TextRect.PtInRect(PrePoint); 
	 
	return returncode;	 
} 
 
void CPainterView::OnDestroy()  
{ 
	CScrollView::OnDestroy(); 
 
	CRect rect; 
	//清除对话框工具条的内容。 
	CBrush  brush=(0,RGB(255,255,255)); 
	CMainFrame *OwnWnd; 
	OwnWnd=(CMainFrame *)GetParentOwner(); 
	CWnd* pWnd = OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_FILL_PREVIEW); 
	pWnd->GetClientRect(rect); 
	CDC* dc=pWnd->GetDC(); 
	dc->FillRect(rect,&brush); 
 
	CComboBox* pCBox=(CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_FILL_PATTERN); 
	pCBox->SetCurSel(-1); 
 
	pCBox = (CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_TYPE); 
	pCBox->SetCurSel(-1); 
 
	pCBox=(CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_WIDTH); 
	pCBox->SetCurSel(-1); 
 
	pWnd = OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_PREVIEW); 
	pWnd->GetClientRect(rect); 
	dc=pWnd->GetDC(); 
	dc->Rectangle(rect); 
} 
 
void CPainterView::OnDrawGrid()  
{ 
	// TODO: Add your command handler code here 
	if(m_bGrid) 
		m_bGrid=FALSE; 
	else  
		m_bGrid=TRUE; 
	Invalidate(); 
} 
 
//根据是否绘制辅助网点而设置按钮状态 
void CPainterView::OnUpdateDrawGrid(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
		pCmdUI->SetCheck(m_bGrid); 
		pCmdUI->Enable(!m_bModify); 
} 
 
//根据是否绘处于填充而设置按钮状态 
void CPainterView::OnUpdateDrawFill(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(*DrawType==FILL) 
		pCmdUI->SetCheck(TRUE); 
	else 
		pCmdUI->SetCheck(FALSE); 
	pCmdUI->Enable(!m_bModify); 
} 
 
 
void CPainterView::OnFileSave()  
{ 
	// TODO: Add your command handler code here 
	if(bFileSaved) 
	{ 
// 已经有文件名,修改图形文件 
		Save(); 
	} 
	else 
		OnFileSaveAs(); 
} 
 
void CPainterView::OnFileSaveAs()  
{ 
	// TODO: Add your command handler code here 
	CFileDialog	file(0, // 1-文件打开, 0-文件另存为 
                         ".hpy|*.*", 
						 NULL, 
			OFN_OVERWRITEPROMPT | OFN_NOREADONLYRETURN , 
						 "绘图文件 (*.hpy)|*.hpy|All Files (*.*)|*.*||", 
						 NULL); 
	if(file.DoModal()==IDOK) 
	{ 
		path = file.GetPathName(); 
		fileName = file.GetFileTitle(); 
		Save(); 
		if(!AddIcon()) 
			MessageBox("添加记录失败!","错误"); 
  } 
} 
 
 
//处理文件打开命令 
void CPainterView::OnFileOpen()  
{ 
	// TODO: Add your command handler code here 
	CPainterDoc *pDoc=GetDocument(); 
	 
	CFileDialog	file(1, // 1-文件打开, 0-文件另存为 
                         ".hpy|*.*", 
						 NULL, 
			OFN_OVERWRITEPROMPT , 
						 "绘图文件 (*.hpy)|*.hpy|All Files (*.*)|*.*||", 
						 NULL); 
	if(file.DoModal()==IDOK) 
	{ 
 
		path = file.GetPathName(); 
		fileName=file.GetFileTitle(); 
		CFile	file; 
		if(!file.Open(path,0x0000,NULL)) return; 
		if(!pDoc->RecordList.IsEmpty())//如果文档数据内容非空则清空之 
			pDoc->RecordList.RemoveAll(); 
 
		DWORD   CurFilePointer=file.GetPosition();//得到文件指针当前位置 
      	DWORD   FileEndPointer=file.GetLength();//得到文件长度 
	 
		while(CurFilePointerRecordList.AddTail(style);//将图元类型加入链表 
			switch(*style) 
			{ 
			//如果图元是直线 
			case LINE: 
				LINENODE* line; 
				line=new LINENODE; 
				file.Read(line,sizeof(LINENODE)); 
				pDoc->RecordList.AddTail(line); 
				break; 
			//如果图元是矩形 
			case RECTANGLE: 
				RECTANGLENODE* rectangle; 
				rectangle=new RECTANGLENODE; 
				file.Read(rectangle,sizeof(RECTANGLENODE));; 
				pDoc->RecordList.AddTail(rectangle); 
				break; 
			//如果是填充 
			case FILL: 
				FILLNODE* fill; 
				fill=new FILLNODE; 
				file.Read(fill,sizeof(FILLNODE)); 
				pDoc->RecordList.AddTail(fill); 
				break; 
			//如果图元是文本 
			case TEXT: 
				TEXTNODE* text; 
				text=new TEXTNODE; 
				file.Read(text,sizeof(TEXTNODE)); 
				pDoc->RecordList.AddTail(text); 
				break; 
			//如果是椭圆 
			case ELLIPSE: 
				ELLIPSENODE* ellipse; 
				ellipse=new ELLIPSENODE; 
				file.Read(ellipse,sizeof(ELLIPSENODE)); 
				pDoc->RecordList.AddTail(ellipse); 
				break; 
			//如果是三角形 
			case TRIANGLE: 
				TRIANGLENODE* triangle; 
				triangle=new TRIANGLENODE; 
				file.Read(triangle,sizeof(TRIANGLENODE)); 
				pDoc->RecordList.AddTail(triangle); 
				break; 
			} 
			CurFilePointer=file.GetPosition();//获得当前文件指针位置 
		} 
		file.Close();//关闭文件 
	} 
 
	bFileSaved=TRUE; 
	pDoc->UpdateAllViews(NULL,0,NULL);//重绘窗口 
	GetParent()->SetWindowText(fileName); 
} 
 
//处理文件保存 
void CPainterView::Save() 
{ 
	CFile	save; 
////////////////////////////////////////// 
/*										// 
		modeRead =          0x0000,		// 
		modeWrite =         0x0001,		// 
		modeReadWrite =     0x0002,		// 
		modeCreate =        0x1000,		// 
*/										// 
////////////////////////////////////////// 
	save.Open(path,0x0001|0x1000,NULL); 
	CPainterDoc *pDoc=GetDocument(); 
	POSITION pos=pDoc->RecordList.GetHeadPosition(); 
    while(pos!=NULL) 
	{ 
		BYTE *style; 
		style=(BYTE*)pDoc->RecordList.GetNext(pos); 
		save.Write(style,sizeof(BYTE)); 
		switch(*style) 
		{ 
		case LINE: 
			save.Write((LINENODE*)pDoc->RecordList.GetAt(pos),sizeof(LINENODE)); 
			break; 
		case RECTANGLE: 
			save.Write((RECTANGLENODE*)pDoc->RecordList.GetNext(pos),sizeof(RECTANGLENODE)); 
			break; 
		case FILL: 
			save.Write((FILLNODE*)pDoc->RecordList.GetNext(pos),sizeof(FILLNODE)); 
			break; 
		case TEXT: 
			save.Write((TEXTNODE*)pDoc->RecordList.GetNext(pos),sizeof(TEXTNODE)); 
			break; 
		case TRIANGLE: 
			save.Write((TRIANGLENODE*)pDoc->RecordList.GetNext(pos),sizeof(TRIANGLENODE)); 
			break; 
		case ELLIPSE: 
			save.Write((ELLIPSENODE*)pDoc->RecordList.GetNext(pos),sizeof(ELLIPSENODE)); 
			break; 
		} 
	} 
	save.Close(); 
	pDoc->SetModifiedFlag(FALSE); 
	bFileSaved=TRUE; 
	GetParent()->SetWindowText(fileName); 
} 
 
void CPainterView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)  
{ 
	// TODO: Add your message handler code here and/or call default 
	if(nChar==VK_SHIFT)////如果按下Shift键 
		bShiftDown=TRUE; 
 
	CScrollView::OnKeyDown(nChar, nRepCnt, nFlags); 
} 
 
void CPainterView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)  
{ 
	// TODO: Add your message handler code here and/or call default 
	if(nChar==VK_SHIFT)//如果没有按下Shift键 
		bShiftDown=FALSE; 
 
	CScrollView::OnKeyUp(nChar, nRepCnt, nFlags); 
} 
 
void CPainterView::UndoMove(MOVENODE *move) 
{ 
	CPainterDoc *pDoc=GetDocument(); 
	POSITION pos=pDoc->RecordList.GetHeadPosition();//得到链表头节点的指针 
	int x_off=move->x_off; 
	int y_off=move->y_off; 
	int i; 
	BOOL Do=FALSE;//判断图元是否属于移动集 
 
	while(pos!=NULL) 
	{ 
		BYTE *style; 
		style=(BYTE *)pDoc->RecordList.GetNext(pos);//得到图元类型指针 
		switch(*style) 
		{ 
		case LINE: 
			LINENODE *line; 
			line=(LINENODE *)pDoc->RecordList.GetNext(pos);//从链表中取出图元数据 
			//移动集中是否存在直线图元的索引 
			for(i=0;iiCompNum;i++) 
				if(line->Index==move->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO)//如果是撤消 
				{ 
				    line->End.x-=x_off; 
				    line->End.y-=y_off; 
				    line->Start.x-=x_off; 
				    line->Start.y-=y_off; 
					line->bDo=7; 
				} 
				else//如果是恢复 
				{ 
					line->End.x+=x_off; 
				    line->End.y+=y_off; 
				    line->Start.x+=x_off; 
				    line->Start.y+=y_off; 
					line->bDo=5; 
				} 
			} 
			break; 
		case RECTANGLE: 
			RECTANGLENODE *rectangle; 
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(rectangle->Index==move->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO) 
				{ 
				    rectangle->rT.bottom-=y_off; 
				    rectangle->rT.top-=y_off; 
				    rectangle->rT.right-=x_off; 
				    rectangle->rT.left-=x_off; 
					rectangle->bDo=7; 
				} 
				else 
				{ 
					rectangle->rT.bottom+=y_off; 
				    rectangle->rT.top+=y_off; 
				    rectangle->rT.right+=x_off; 
				    rectangle->rT.left+=x_off; 
					rectangle->bDo=5; 
				} 
			} 
			break; 
		case ELLIPSE: 
			ELLIPSENODE *ellipse; 
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(ellipse->Index==move->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO) 
				{ 
				    ellipse->rT.bottom-=y_off; 
				    ellipse->rT.top-=y_off; 
				    ellipse->rT.right-=x_off; 
				    ellipse->rT.left-=x_off; 
					ellipse->bDo=7; 
				} 
				else 
				{ 
					ellipse->rT.bottom+=y_off; 
				    ellipse->rT.top+=y_off; 
				    ellipse->rT.right+=x_off; 
				    ellipse->rT.left+=x_off; 
					ellipse->bDo=5; 
				} 
			} 
			break; 
		case TRIANGLE: 
			TRIANGLENODE *triangle; 
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(triangle->Index==move->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO) 
				{ 
				    triangle->rT.bottom-=y_off; 
				    triangle->rT.top-=y_off; 
				    triangle->rT.right-=x_off; 
				    triangle->rT.left-=x_off; 
					triangle->bDo=7; 
				} 
				else 
				{ 
					triangle->rT.bottom+=y_off; 
				    triangle->rT.top+=y_off; 
				    triangle->rT.right+=x_off; 
				    triangle->rT.left+=x_off; 
					triangle->bDo=5; 
				} 
			} 
			break; 
		case TEXT: 
			TEXTNODE *text; 
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(text->Index==move->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO) 
				{ 
				    text->point.x-=x_off; 
				    text->point.y-=y_off; 
					text->bDo=7; 
				} 
				else 
				{ 
					text->point.x+=x_off; 
				    text->point.y+=y_off; 
					text->bDo=5; 
				} 
			} 
			break; 
		} 
		Do=FALSE; 
	} 
} 
 
void CPainterView::UndoPaste(PASTENODE *paste) 
{ 
	CPainterDoc *pDoc=GetDocument(); 
	POSITION pos=pDoc->RecordList.GetHeadPosition(); 
	int i; 
	BOOL Do=FALSE; 
 
	while(pos!=NULL) 
	{ 
		BYTE *style; 
		style=(BYTE *)pDoc->RecordList.GetNext(pos); 
		switch(*style) 
		{ 
		case LINE: 
			LINENODE *line; 
			line=(LINENODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(line->Index==paste->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO) 
					line->bDo=-3; 
				else 
					line->bDo=3; 
			} 
			break; 
		case RECTANGLE: 
			RECTANGLENODE *rectangle; 
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(rectangle->Index==paste->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO) 
					rectangle->bDo=-3; 
				else 
					rectangle->bDo=3; 
			} 
			break; 
		case ELLIPSE: 
			ELLIPSENODE *ellipse; 
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(ellipse->Index==paste->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO) 
					ellipse->bDo=-3; 
				else 
					ellipse->bDo=3; 
			} 
			break; 
		case TRIANGLE: 
			TRIANGLENODE *triangle; 
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(triangle->Index==paste->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO) 
					triangle->bDo=-3; 
				else 
					triangle->bDo=3; 
			} 
			break; 
		case TEXT: 
			TEXTNODE *text; 
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(text->Index==paste->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO) 
					text->bDo=-3; 
				else 
					text->bDo=3; 
			} 
			break; 
		} 
		Do=FALSE; 
	} 
}	 
 
void CPainterView::UndoCut(CUTNODE *cut) 
{ 
	CPainterDoc *pDoc=GetDocument(); 
	POSITION pos=pDoc->RecordList.GetHeadPosition(); 
	int i; 
	BOOL Do=FALSE; 
 
	while(pos!=NULL) 
	{ 
		BYTE *style; 
		style=(BYTE *)pDoc->RecordList.GetNext(pos); 
		switch(*style) 
		{ 
		case LINE: 
			LINENODE *line; 
			line=(LINENODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(line->Index==cut->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO) 
					line->bDo=6; 
				else 
					line->bDo=-6; 
			} 
			break; 
		case RECTANGLE: 
			RECTANGLENODE *rectangle; 
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(rectangle->Index==cut->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType=UNDO) 
					rectangle->bDo=6; 
				else 
					rectangle->bDo=-6; 
			} 
			break; 
		case ELLIPSE: 
			ELLIPSENODE *ellipse; 
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(ellipse->Index==cut->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO) 
					ellipse->bDo=6; 
				else 
					ellipse->bDo=-6; 
			} 
			break; 
		case TRIANGLE: 
			TRIANGLENODE *triangle; 
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(triangle->Index==cut->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO) 
					triangle->bDo=6; 
				else 
					triangle->bDo=-6; 
			} 
			break; 
		case TEXT: 
			TEXTNODE *text; 
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos); 
			for(i=0;iiCompNum;i++) 
				if(text->Index==cut->Index[i]) 
					Do=TRUE; 
			if(Do) 
			{ 
				if(*DrawType==UNDO) 
					text->bDo=6; 
				else 
					text->bDo=-6; 
			} 
			break; 
		} 
		Do=FALSE; 
	} 
} 
 
void CPainterView::OnDrawNotilt()  
{ 
	// TODO: Add your command handler code here 
	if(m_bNoTilt) 
		m_bNoTilt=FALSE; 
	else  
		m_bNoTilt=TRUE; 
	Invalidate(); 
} 
 
void CPainterView::OnUpdateDrawNotilt(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
		pCmdUI->SetCheck(m_bNoTilt); 
		pCmdUI->Enable(!m_bModify); 
} 
 
void CPainterView::OnEnlarge()  
{ 
	// TODO: Add your command handler code here 
 
} 
 
void CPainterView::OnInitialUpdate()  
{ 
	CScrollView::OnInitialUpdate(); 
	 
	// TODO: Add your specialized code here and/or call the base class 
	CSize sizeTotal; 
	sizeTotal.cx = 800; 
	sizeTotal.cy = 600; 
	SetScrollSizes(MM_TEXT, sizeTotal);	 
} 
 
/////////////////////////////////////////////////////////// 
/////////////////////////////////////////////////////////// 
void CPainterView::OnContextMenu(CWnd* pWnd, CPoint point)  
{ 
	// TODO: Add your message handler code here 
	if(*DrawType==SELECT) 
	{ 
    	if (point.x == -1 && point.y == -1) 
		{ 
		     CRect rect; 
		     GetClientRect(rect); 
		     ClientToScreen(rect); 
		     point = rect.TopLeft(); 
		     point.Offset(5, 5); 
		}   
 
	    CMenu menu; 
	    VERIFY(menu.LoadMenu(IDR_CONTEXT_MENU));//载入快捷菜单资源 
 
	    CMenu* pPopup = menu.GetSubMenu(0); 
	    ASSERT(pPopup != NULL); 
 
	    CWnd* pWndPopupOwner = this;//设置快捷菜单的主窗口 
 
	    while (pWndPopupOwner->GetStyle() & WS_CHILD) 
		     pWndPopupOwner = pWndPopupOwner->GetParent(); 
 
	    pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, 
		     pWndPopupOwner); 
	} 
} 
 
void CPainterView::OnEditModify()  
{ 
	// TODO: Add your command handler code here 
	if(!m_bModify) 
		EnterModifyMode(); 
	else 
		LeaveModifyMode(); 
} 
 
void CPainterView::LeaveModifyMode() 
{ 
	m_bModify=FALSE; 
	if(!SnapList.IsEmpty()) 
		SnapList.RemoveAll(); 
	m_ModifyPen=NULL; 
	m_pModifyPoint=NULL; 
 
	CMainFrame *OwnWnd; 
    OwnWnd=(CMainFrame *)GetParentOwner(); 
	CComboBox *pCBox1,*pCBox2; 
	pCBox1= (CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_TYPE); 
	pCBox2= (CComboBox*)OwnWnd->m_wndMyDialogBar.GetDlgItem(IDC_LINE_WIDTH); 
	pCBox1->SetCurSel(penType); 
	pCBox2->SetCurSel(penWidth-1); 
 
	m_bIsRect=FALSE; 
	m_IsSelected=FALSE; 
	OnLButtonDown(0,CPoint(-1,-1));//使被选图元恢复正常显示 
	Invalidate(TRUE); 
} 
 
void CPainterView::EnterModifyMode() 
{ 
	CClientDC dc(this); 
	m_bModify=TRUE; 
	POINT  *pPoints; 
 
	float fFX,fFY; 
	int j; 
	int i=0; 
	 
	fFX=1.; 
	fFY=1.; 
 
	CPainterDoc *pDoc=GetDocument(); 
	POSITION pos=pDoc->RecordList.GetHeadPosition(),TempPos; 
	int finish=0; 
 
	while(pos!=NULL && finish<=0) 
	{ 
		BYTE *style; 
		TempPos=pos; 
		style=(BYTE *)pDoc->RecordList.GetNext(pos); 
		switch(*style) 
		{ 
		case LINE: 
			LINENODE *line; 
			line=(LINENODE *)pDoc->RecordList.GetNext(pos); 
			if(line->bDo==2) 
			{ 
				m_ModifyPen=&line->pen; 
				pPoints=new POINT[2]; 
				pPoints[0]=line->Start; 
				pPoints[1]=line->End; 
				DrawSnapPoint(&dc,i,pPoints); 
				i+=1; 
				DrawSnapPoint(&dc,1,pPoints); 
			} 
			break; 
		case TEXT: 
			TEXTNODE *text; 
			text=(TEXTNODE *)pDoc->RecordList.GetNext(pos); 
			if(text->bDo==2) 
			{ 
			} 
			break; 
		case RECTANGLE: 
			RECTANGLENODE *rectangle; 
			rectangle=(RECTANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(rectangle->bDo==2) 
			{ 
				m_ModifyPen=&rectangle->pen; 
        		m_bIsRect=TRUE; 
                pPoints=new POINT[4]; 
 
		        RectToPoints(rectangle->rT,pPoints); 
 
		        DrawSnapPoint(&dc,i,pPoints); 
		        i+=1; 
		        DrawSnapPoint(&dc,i,pPoints); 
		        i+=1; 
		        DrawSnapPoint(&dc,i,pPoints); 
		        i+=1; 
		        DrawSnapPoint(&dc,i,pPoints); 
			} 
			break; 
		case TRIANGLE: 
			TRIANGLENODE *triangle; 
			triangle=(TRIANGLENODE *)pDoc->RecordList.GetNext(pos); 
			if(triangle->bDo==2) 
			{ 
				m_ModifyPen=&triangle->pen; 
				pPoints=new POINT[3]; 
				pPoints[0].x=triangle->rT.left; 
				pPoints[0].y=triangle->rT.top; 
				pPoints[1].x=triangle->rT.right; 
				pPoints[1].y=(triangle->rT.top+triangle->rT.bottom)/2; 
				pPoints[2].x=triangle->rT.left; 
				pPoints[2].y=triangle->rT.bottom; 
        	 
		        DrawSnapPoint(&dc,i,pPoints); 
		        i+=1; 
		        DrawSnapPoint(&dc,i,pPoints); 
		        i+=1; 
		        DrawSnapPoint(&dc,i,pPoints); 
			} 
			break; 
		case ELLIPSE: 
			ELLIPSENODE *ellipse; 
			ellipse=(ELLIPSENODE *)pDoc->RecordList.GetNext(pos); 
			if(ellipse->bDo==2) 
			{ 
				m_ModifyPen=&ellipse->pen; 
        		m_bIsRect=TRUE; 
		 
		        pPoints=new POINT[4]; 
 
		        RectToPoints(ellipse->rT,pPoints); 
 
		        DrawSnapPoint(&dc,i,pPoints); 
		        i+=1; 
		        DrawSnapPoint(&dc,i,pPoints); 
		        i+=1; 
		        DrawSnapPoint(&dc,i,pPoints); 
		        i+=1; 
		        DrawSnapPoint(&dc,i,pPoints); 
			} 
			break; 
		} 
	} 
} 
 
void CPainterView::DrawSnapList() 
{ 
	CClientDC dc(this); 
	float fFX,fFY; 
	 
	fFX=1.; 
	fFY=1; 
 
	POSITION pos=SnapList.GetHeadPosition(); 
 
	while(pos!=NULL) 
	{ 
		SnapList.GetNext(pos); 
		POINT *pPoint; 
		pPoint=(POINT *)SnapList.GetNext(pos); 
 
		dc.MoveTo((pPoint->x-5)*fFX,(pPoint->y-5)*fFY); 
		dc.LineTo((pPoint->x+5)*fFX,(pPoint->y-5)*fFY); 
		dc.LineTo((pPoint->x+5)*fFX,(pPoint->y+5)*fFY); 
		dc.LineTo((pPoint->x-5)*fFX,(pPoint->y+5)*fFY); 
		dc.LineTo((pPoint->x-5)*fFX,(pPoint->y-5)*fFY); 
	} 
} 
 
void CPainterView::DrawSnapPoint(CDC *dc,int index,/*CPoint point*/POINT* pPoints) 
{ 
	float fFX,fFY; 
	POINT point=pPoints[index]; 
	 
	fFX=1.; 
	fFY=1.; 
 
	dc->MoveTo((point.x-5)*fFX,(point.y-5)*fFY); 
	dc->LineTo((point.x+5)*fFX,(point.y-5)*fFY); 
	dc->LineTo((point.x+5)*fFX,(point.y+5)*fFY); 
	dc->LineTo((point.x-5)*fFX,(point.y+5)*fFY); 
	dc->LineTo((point.x-5)*fFX,(point.y-5)*fFY); 
	 
	m_nSnapIndex=new int; 
	*m_nSnapIndex=index; 
	SnapList.AddTail(m_nSnapIndex); 
 
	SnapList.AddTail(&pPoints[index]); 
} 
 
void CPainterView::OnUpdateEditModify(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(!m_IsSelected) 
		pCmdUI->Enable(FALSE); 
	else  
		pCmdUI->Enable(TRUE);	 
 
	if(m_bModify) 
		pCmdUI->SetCheck(1); 
	else 
		pCmdUI->SetCheck(0); 
} 
 
void CPainterView::DrawCurSnap() 
{ 
	CClientDC dc(this); 
	CPen pen(PS_SOLID,1,RGB(255,0,0)),*OldPen; 
	float fFX,fFY; 
	 
	fFX=1.; 
	fFY=1.; 
	POINT  *point; 
 
	if(m_nModifyIndex!=SnapList.GetCount()/2) 
		point=(POINT *)SnapList.GetAt(SnapList.FindIndex(m_nModifyIndex*2+1)); 
	else 
		point=(POINT *)SnapList.GetAt(SnapList.FindIndex(1)); 
 
 
	OldPen=dc.SelectObject(&pen); 
 
	dc.MoveTo((point->x-5)*fFX,(point->y-5)*fFY); 
	dc.LineTo((point->x+5)*fFX,(point->y-5)*fFY); 
	dc.LineTo((point->x+5)*fFX,(point->y+5)*fFY); 
	dc.LineTo((point->x-5)*fFX,(point->y+5)*fFY); 
	dc.LineTo((point->x-5)*fFX,(point->y-5)*fFY); 
 
	dc.SelectObject(OldPen); 
} 
 
void CPainterView::DrawModifyRec(CClientDC *DC) 
{ 
	int i; 
	float fFX,fFY; 
	 
	fFX=1.; 
	fFY=1.; 
 
	for(i=0;iMoveTo(pPoint->x*fFX,pPoint->y*fFY); 
 
		 if(i*2==SnapList.GetCount()-2) 
		 { 
		     pPoint=(POINT *)SnapList.GetAt(SnapList.FindIndex(1)); 
			 DC->LineTo(pPoint->x*fFX,pPoint->y*fFY); 
		 } 
		 else 
		 { 
		     pPoint=(POINT *)SnapList.GetAt(SnapList.FindIndex(i*2+3)); 
			 DC->LineTo(pPoint->x*fFX,pPoint->y*fFY); 
		 } 
	} 
} 
 
void CPainterView::RectToPoints(RECT rect,POINT *point) 
{ 
	point[0].x=rect.left; 
	point[0].y=rect.top; 
	point[1].x=rect.right; 
	point[1].y=rect.top; 
	point[2].x=rect.right; 
	point[2].y=rect.bottom; 
	point[3].x=rect.left; 
	point[3].y=rect.bottom; 
} 
 
void CPainterView::OnUpdateDrawEllipse(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(*DrawType==ELLIPSE) 
		pCmdUI->SetCheck(TRUE); 
	else 
		pCmdUI->SetCheck(FALSE); 
	pCmdUI->Enable(!m_bModify); 
} 
 
void CPainterView::OnUpdateDrawLine(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(*DrawType==LINE) 
		pCmdUI->SetCheck(TRUE); 
	else 
		pCmdUI->SetCheck(FALSE); 
	pCmdUI->Enable(!m_bModify); 
} 
 
void CPainterView::OnUpdateDrawRectangle(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(*DrawType==RECTANGLE) 
		pCmdUI->SetCheck(TRUE); 
	else 
		pCmdUI->SetCheck(FALSE); 
	pCmdUI->Enable(!m_bModify); 
} 
 
void CPainterView::OnUpdateDrawTriangle(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(*DrawType==TRIANGLE) 
		pCmdUI->SetCheck(TRUE); 
	else 
		pCmdUI->SetCheck(FALSE); 
	pCmdUI->Enable(!m_bModify); 
} 
 
void CPainterView::OnUpdateDrawSelect(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(*DrawType==SELECT) 
		pCmdUI->SetCheck(TRUE); 
	else 
		pCmdUI->SetCheck(FALSE); 
	pCmdUI->Enable(!m_bModify); 
} 
 
void CPainterView::OnUpdateText(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(*DrawType==TEXT) 
		pCmdUI->SetCheck(TRUE); 
	else 
		pCmdUI->SetCheck(FALSE); 
	pCmdUI->Enable(!m_bModify); 
} 
 
void CPainterView::OnUpdateModifyMove(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(*DrawType==MOVE) 
		pCmdUI->SetCheck(TRUE); 
	else 
		pCmdUI->SetCheck(FALSE); 
	pCmdUI->Enable(!m_bModify); 
} 
 
BOOL CPainterView::AddIcon() 
{ 
	if(!m_pSet.IsOpen()) 
		m_pSet.Open(); 
	m_pSet.AddNew(); 
	m_pSet.m_IconName=fileName; 
	m_pSet.m_IconPath=path; 
	m_pSet.Update(); 
	m_pSet.Close(); 
 
	return TRUE; 
} 
 
void CPainterView::DoNothing() 
{ 
	// 该函数使工具栏下拉菜单有一个返回值,以免使工具栏按钮被禁止 
} 
 
//处理工具栏中的下拉菜单 
void CPainterView::OnDropDown(NMHDR* pNotifyStruct, LRESULT* pResult) 
{ 
	NMTOOLBAR* pNMToolBar = (NMTOOLBAR*)pNotifyStruct; 
	CRect rect; 
	CMainFrame *pWnd=(CMainFrame *)AfxGetMainWnd(); 
 
	// 将工具栏按钮的矩形转换为屏幕坐标,以便确定从何处打开下拉菜单 
	pWnd->m_wndToolBar.GetToolBarCtrl().GetRect(pNMToolBar->iItem, &rect); 
	rect.top = rect.bottom; 
	::ClientToScreen(pNMToolBar->hdr.hwndFrom, &rect.TopLeft()); 
	if(pNMToolBar->iItem == ID_ENLARGE) 
	{ 
		CMenu menuR; 
		CMenu* pPopupR; 
 
		// 从资源中载入菜单 
		menuR.LoadMenu(IDR_ZOOM_POPUP); 
		pPopupR = menuR.GetSubMenu(0); 
		pPopupR->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd()); 
	} 
	*pResult = TBDDRET_DEFAULT; 
} 
 
void CPainterView::OnView100()  
{ 
	// TODO: Add your command handler code here 
	MessageBox("缩放100%,尚未完成!"); 
} 
 
void CPainterView::OnView200()  
{ 
	// TODO: Add your command handler code here 
	MessageBox("缩放200%,尚未完成!"); 
} 
 
void CPainterView::OnView25()  
{ 
	// TODO: Add your command handler code here 
	MessageBox("缩放25%,尚未完成!"); 
} 
 
void CPainterView::OnView50()  
{ 
	// TODO: Add your command handler code here 
	MessageBox("缩放50%,尚未完成!"); 
} 
 
void CPainterView::OnView75()  
{ 
	// TODO: Add your command handler code here 
	MessageBox("缩放75%,尚未完成!","提示"); 
}