www.pudn.com > MyDraw1225.rar > MyDrawView.cpp
// MyDrawView.cpp : implementation of the CMyDrawView class
//
#include "stdafx.h"
#include "MyDraw.h"
#include "MyDrawDoc.h"
#include "MyDrawView.h"
#include "Ellipse.h"
#include "Line.h"
#include "LineProperties.h"
#include "EllipseProperties.h"
#include "Rectangle.h"
#include "Text.h"
#include "TextProperties.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyDrawView
IMPLEMENT_DYNCREATE(CMyDrawView, CView)
BEGIN_MESSAGE_MAP(CMyDrawView, CView)
//{{AFX_MSG_MAP(CMyDrawView)
ON_WM_LBUTTONDOWN()
ON_WM_SETCURSOR()
ON_WM_LBUTTONDBLCLK()
ON_COMMAND(ID_BUTTON_LINE, OnButtonLine)
ON_COMMAND(ID_BUTTON_ELLIPSE, OnButtonEllipse)
ON_COMMAND(ID_BUTTON_RECTANGLE, OnButtonRectangle)
ON_COMMAND(ID_BUTTON_ARC, OnButtonArc)
ON_WM_KEYUP()
ON_COMMAND(ID_BUTTON_TEXT, OnButtonText)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDrawView construction/destruction
CMyDrawView::CMyDrawView()
{
// TODO: add construction code here
m_tracker.m_nStyle=CRectTracker::resizeInside|
CRectTracker::dottedLine;
m_tracker.m_rect.SetRect(0,0,0,0);
m_tracker.m_nHandleSize=8;
}
CMyDrawView::~CMyDrawView()
{
}
BOOL CMyDrawView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyDrawView drawing
void CMyDrawView::OnDraw(CDC* pDC)
{
CMyDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
POSITION pos = m_ObjectList.GetHeadPosition();
CEllipse* pEllipse = NULL;
CLine* pLine=NULL;
CRectangle* pRectangle=NULL;
CArc* pArc=NULL;
CText* pText=NULL;
CObject* pObject=NULL;
while(pos != NULL)
{
pObject=(CObject*)m_ObjectList.GetNext(pos);
if (pObject->IsKindOf(RUNTIME_CLASS(CEllipse)))
{
pEllipse = (CEllipse*)pObject;
if(pEllipse != NULL)
{
if (pEllipse->bIsSelected)
{
pEllipse->startX=m_tracker.m_rect.left;
pEllipse->startY=m_tracker.m_rect.top;
pEllipse->endX=m_tracker.m_rect.right;
pEllipse->endY=m_tracker.m_rect.bottom;
}
DrawEllipse(pDC,pEllipse);
if (pEllipse->bIsSelected)
{
m_tracker.Draw(pDC);
}
}
}
else if (pObject->IsKindOf(RUNTIME_CLASS(CLine)))
{
pLine = (CLine*)pObject;
if(pLine != NULL)
{
if (pLine->bIsSelected)
{
pLine->startX=m_tracker.m_rect.left;
pLine->startY=m_tracker.m_rect.top;
pLine->endX=m_tracker.m_rect.right;
pLine->endY=m_tracker.m_rect.bottom;
}
DrawLine(pDC,pLine);
if (pLine->bIsSelected)
{
m_tracker.Draw(pDC);
}
}
}
else if (pObject->IsKindOf(RUNTIME_CLASS(CArc)))
{
pArc = (CArc*)pObject;
if(pArc != NULL)
{
if (pArc->bIsSelected)
{
pArc->startX=m_tracker.m_rect.left;
pArc->startY=m_tracker.m_rect.top;
pArc->endX=m_tracker.m_rect.right;
pArc->endY=m_tracker.m_rect.bottom;
}
DrawArc(pDC,pArc);
if (pArc->bIsSelected)
{
m_tracker.Draw(pDC);
}
}
}
else if (pObject->IsKindOf(RUNTIME_CLASS(CText)))
{
pText = (CText*)pObject;
if(pText != NULL)
{
if (pText->bIsSelected)
{
pText->startX=m_tracker.m_rect.left;
pText->startY=m_tracker.m_rect.top;
pText->endX=m_tracker.m_rect.right;
pText->endY=m_tracker.m_rect.bottom;
}
DrawMyText(pDC,pText);
if (pText->bIsSelected)
{
m_tracker.Draw(pDC);
}
}
}
else if (pObject->IsKindOf(RUNTIME_CLASS(CRectangle)))
{
pRectangle = (CRectangle*)pObject;
if(pRectangle != NULL)
{
if (pRectangle->bIsSelected)
{
pRectangle->startX=m_tracker.m_rect.left;
pRectangle->startY=m_tracker.m_rect.top;
pRectangle->endX=m_tracker.m_rect.right;
pRectangle->endY=m_tracker.m_rect.bottom;
}
DrawRectangle(pDC,pRectangle);
if (pRectangle->bIsSelected)
{
m_tracker.Draw(pDC);
}
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CMyDrawView diagnostics
#ifdef _DEBUG
void CMyDrawView::AssertValid() const
{
CView::AssertValid();
}
void CMyDrawView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyDrawDoc* CMyDrawView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDrawDoc)));
return (CMyDrawDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyDrawView message handlers
void CMyDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CEllipse* pEllipse = NULL;
CLine* pLine=NULL;
CRectangle* pRectangle=NULL;
CArc* pArc=NULL;
CText* pText=NULL;
POSITION pos = m_ObjectList.GetHeadPosition();
CObject* pHitItem;
while(pos != NULL)
{
pHitItem=(CObject*)m_ObjectList.GetNext(pos);
if (pHitItem->IsKindOf(RUNTIME_CLASS(CEllipse)))
{
pEllipse = (CEllipse*)pHitItem;
if(pEllipse != NULL)
{
CRect rc;
rc.left=pEllipse->startX;
rc.top=pEllipse->startY;
rc.right=pEllipse->endX;
rc.bottom=pEllipse->endY;
if (rc.PtInRect(point))
{
ClearSelection();
pEllipse->bIsSelected=true;
m_tracker.m_rect.SetRect(pEllipse->startX,pEllipse->startY,
pEllipse->endX,pEllipse->endY);
}
else
{
pEllipse->bIsSelected=false;
}
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CLine)))
{
pLine = (CLine*)pHitItem;
if(pLine != NULL)
{
CRect rc(pLine->startX,pLine->startY,pLine->endX,pLine->endY);
if (rc.PtInRect(point))
{
ClearSelection();
pLine->bIsSelected=true;
m_tracker.m_rect.SetRect(pLine->startX,pLine->startY,
pLine->endX,pLine->endY);
}
else
{
pLine->bIsSelected=false;
}
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CArc)))
{
pArc = (CArc*)pHitItem;
if(pArc != NULL)
{
CRect rc(pArc->startX,pArc->startY,pArc->endX,pArc->endY);
if (rc.PtInRect(point))
{
ClearSelection();
pArc->bIsSelected=true;
m_tracker.m_rect.SetRect(pArc->startX,pArc->startY,
pArc->endX,pArc->endY);
}
else
{
pArc->bIsSelected=false;
}
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CText)))
{
pText = (CText*)pHitItem;
if(pText != NULL)
{
CRect rc(pText->startX,pText->startY,pText->endX,pText->endY);
if (rc.PtInRect(point))
{
ClearSelection();
pText->bIsSelected=true;
m_tracker.m_rect.SetRect(pText->startX,pText->startY,
pText->endX,pText->endY);
}
else
{
pText->bIsSelected=false;
}
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CRectangle)))
{
pRectangle = (CRectangle*)pHitItem;
if(pRectangle != NULL)
{
CRect rc;
rc.left=pRectangle->startX;
rc.top=pRectangle->startY;
rc.right=pRectangle->endX;
rc.bottom=pRectangle->endY;
if (rc.PtInRect(point))
{
ClearSelection();
pRectangle->bIsSelected=true;
m_tracker.m_rect.SetRect(pRectangle->startX,
pRectangle->startY,pRectangle->endX,pRectangle->endY);
}
else
{
pRectangle->bIsSelected=false;
}
}
}
}
m_tracker.Track(this,point);//显示调节框
Invalidate();
}
BOOL CMyDrawView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
//鼠标移动到调节框范围内时,改变鼠标指针形状,指示可以拖动或改变绘图元素
if(m_tracker.SetCursor(pWnd,nHitTest))
return true;
return CView::OnSetCursor(pWnd, nHitTest, message);
}
void CMyDrawView::ClearSelection()
{
CObject* pHitItem=NULL;
POSITION pos = m_ObjectList.GetHeadPosition();
CEllipse* pEllipse = NULL;
CLine* pLine=NULL;
CRectangle* pRectangle=NULL;
CArc* pArc=NULL;
CText* pText=NULL;
while(pos != NULL)
{
pHitItem=(CObject*)m_ObjectList.GetNext(pos);
if (pHitItem->IsKindOf(RUNTIME_CLASS(CEllipse)))
{
pEllipse = (CEllipse*)pHitItem;
if(pEllipse != NULL)
{
pEllipse->bIsSelected=false;
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CLine)))
{
pLine = (CLine*)pHitItem;
if(pLine != NULL)
{
pLine->bIsSelected=false;
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CRectangle)))
{
pRectangle = (CRectangle*)pHitItem;
if(pRectangle != NULL)
{
pRectangle->bIsSelected=false;
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CArc)))
{
pArc = (CArc*)pHitItem;
if(pArc != NULL)
{
pArc->bIsSelected=false;
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CText)))
{
pText = (CText*)pHitItem;
if(pText != NULL)
{
pText->bIsSelected=false;
}
}
}
return;
}
void CMyDrawView::DrawLine(CDC *pDC, CLine *pLine)
{
CPen cMyPen;
CPen* pOldPen;
cMyPen.CreatePenIndirect(&pLine->LinePen);
pOldPen=pDC->SelectObject(&cMyPen);
pDC->MoveTo(pLine->startX,pLine->startY);
pDC->LineTo(pLine->endX,pLine->endY);
pDC->SelectObject(pOldPen);
}
void CMyDrawView::DrawArc(CDC *pDC, CArc *pArc)
{
CPen cMyPen;
CPen* pOldPen;
cMyPen.CreatePenIndirect(&pArc->LinePen);
pOldPen=pDC->SelectObject(&cMyPen);
if(pArc->Direction)
{
pDC->Arc(pArc->startX,pArc->startY,pArc->endX,pArc->endY,
pArc->startX,pArc->startY,pArc->endX,pArc->endY);
}
else
{
pDC->Arc(pArc->endX,pArc->endY,pArc->startX,pArc->startY,
pArc->endX,pArc->endY,
pArc->startX,pArc->startY);
}
pDC->SelectObject(pOldPen);
}
void CMyDrawView::DrawMyText(CDC *pDC, CText *pText)
{
CFont cMyFont;
CFont* pOldFont;
cMyFont.CreateFontIndirect(&pText->MyFont);
pOldFont=pDC->SelectObject(&cMyFont);
pDC->SetBkMode(pText->BkMode);
pDC->SetTextColor(pText->MyColor);
pDC->DrawText(pText->MyText,CRect(pText->startX,pText->startY,
pText->endX,pText->endY),DT_LEFT);
pDC->SelectObject(pOldFont);
}
void CMyDrawView::DrawEllipse(CDC *pDC, CEllipse *pEllipse)
{
CPen cMyPen;
CPen* pOldPen;
cMyPen.CreatePenIndirect(&pEllipse->LinePen);
pOldPen=pDC->SelectObject(&cMyPen);
CBrush cMyBrush;
CBrush* pOldBrush;
cMyBrush.CreateBrushIndirect(&pEllipse->MyBrush);
pOldBrush=pDC->SelectObject(&cMyBrush);
pDC->Ellipse(pEllipse->startX,pEllipse->startY,pEllipse->endX,pEllipse->endY);
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
}
void CMyDrawView::DrawRectangle(CDC *pDC, CRectangle *pRectangle)
{
CPen cMyPen;
CPen* pOldPen;
cMyPen.CreatePenIndirect(&pRectangle->LinePen);
pOldPen=pDC->SelectObject(&cMyPen);
CBrush cMyBrush;
CBrush* pOldBrush;
cMyBrush.CreateBrushIndirect(&pRectangle->MyBrush);
pOldBrush=pDC->SelectObject(&cMyBrush);
pDC->Rectangle(pRectangle->startX,pRectangle->startY,
pRectangle->endX,pRectangle->endY);
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
}
void CMyDrawView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CEllipse* pEllipse = NULL;
CLine* pLine=NULL;
CRectangle* pRectangle=NULL;
CArc* pArc=NULL;
CText* pText=NULL;
POSITION pos = m_ObjectList.GetHeadPosition();
CObject* pHitItem;
while(pos != NULL)
{
pHitItem=(CObject*)m_ObjectList.GetNext(pos);
if (pHitItem->IsKindOf(RUNTIME_CLASS(CLine)))
{
pLine = (CLine*)pHitItem;
if(pLine != NULL)
{
if (pLine->bIsSelected)
{
CLineProperties LineDlg;
CString str_LineWidth;
str_LineWidth.Format("%d",pLine->LinePen.lopnWidth.x);
LineDlg.m_LineWidth=str_LineWidth;
if (pLine->LinePen.lopnStyle==PS_DASH)
LineDlg.m_LineStyle="虚线";
else if (pLine->LinePen.lopnStyle==PS_DOT)
LineDlg.m_LineStyle="点线";
else if(pLine->LinePen.lopnStyle==PS_DASHDOT)
LineDlg.m_LineStyle="点划线";
else
LineDlg.m_LineStyle="实线";
LineDlg.m_LineColor=pLine->LinePen.lopnColor;
if (LineDlg.DoModal()==IDOK)
{
pLine->LinePen.lopnWidth.x=atoi(LineDlg.m_LineWidth);
if (LineDlg.m_LineStyle=="虚线")
pLine->LinePen.lopnStyle=PS_DASH;
else if (LineDlg.m_LineStyle=="点线")
pLine->LinePen.lopnStyle=PS_DOT;
else if(LineDlg.m_LineStyle=="点划线")
pLine->LinePen.lopnStyle=PS_DASHDOT;
else
pLine->LinePen.lopnStyle=PS_SOLID;
pLine->LinePen.lopnColor=LineDlg.m_LineColor;
Invalidate();
}
}
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CEllipse)))
{
pEllipse = (CEllipse*)pHitItem;
if(pEllipse != NULL)
{
if (pEllipse->bIsSelected)
{
CEllipseProperties EllipseDlg;
CString str_LineWidth;
str_LineWidth.Format("%d",pEllipse->LinePen.lopnWidth.x);
EllipseDlg.m_LineWidth=str_LineWidth;
if (pEllipse->LinePen.lopnStyle==PS_DASH)
EllipseDlg.m_LineStyle="虚线";
else if (pEllipse->LinePen.lopnStyle==PS_DOT)
EllipseDlg.m_LineStyle="点线";
else if(pEllipse->LinePen.lopnStyle==PS_DASHDOT)
EllipseDlg.m_LineStyle="点划线";
else
EllipseDlg.m_LineStyle="实线";
EllipseDlg.m_LineColor=pEllipse->LinePen.lopnColor;
EllipseDlg.m_BrushColor=pEllipse->MyBrush.lbColor;
if(pEllipse->MyBrush.lbHatch==HS_BDIAGONAL)
EllipseDlg.m_HatchStyle= "HS_BDIAGONAL";
else if(pEllipse->MyBrush.lbHatch==HS_CROSS)
EllipseDlg.m_HatchStyle= "HS_CROSS";
else if(pEllipse->MyBrush.lbHatch==HS_DIAGCROSS)
EllipseDlg.m_HatchStyle= "HS_DIAGCROSS";
else if(pEllipse->MyBrush.lbHatch==HS_FDIAGONAL)
EllipseDlg.m_HatchStyle= "HS_FDIAGONAL";
else if(pEllipse->MyBrush.lbHatch==HS_HORIZONTAL)
EllipseDlg.m_HatchStyle= "HS_HORIZONTAL";
else
EllipseDlg.m_HatchStyle= "HS_VERTICAL";
if(pEllipse->MyBrush.lbStyle==BS_HATCHED)
EllipseDlg.m_BrushStyle= "BS_HATCHED";
else if(pEllipse->MyBrush.lbStyle==BS_NULL)
EllipseDlg.m_BrushStyle= "BS_NULL";
else
EllipseDlg.m_BrushStyle= "BS_SOLID";
if (EllipseDlg.DoModal()==IDOK)
{
pEllipse->LinePen.lopnWidth.x=atoi(EllipseDlg.m_LineWidth);
if (EllipseDlg.m_LineStyle=="虚线")
pEllipse->LinePen.lopnStyle=PS_DASH;
else if (EllipseDlg.m_LineStyle=="点线")
pEllipse->LinePen.lopnStyle=PS_DOT;
else if(EllipseDlg.m_LineStyle=="点划线")
pEllipse->LinePen.lopnStyle=PS_DASHDOT;
else
pEllipse->LinePen.lopnStyle=PS_SOLID;
pEllipse->LinePen.lopnColor=EllipseDlg.m_LineColor;
pEllipse->MyBrush.lbColor=EllipseDlg.m_BrushColor;
if(EllipseDlg.m_HatchStyle== "HS_BDIAGONAL")
pEllipse->MyBrush.lbHatch=HS_BDIAGONAL;
else if(EllipseDlg.m_HatchStyle== "HS_CROSS")
pEllipse->MyBrush.lbHatch=HS_CROSS;
else if(EllipseDlg.m_HatchStyle== "HS_DIAGCROSS")
pEllipse->MyBrush.lbHatch=HS_DIAGCROSS;
else if(EllipseDlg.m_HatchStyle== "HS_FDIAGONAL")
pEllipse->MyBrush.lbHatch=HS_FDIAGONAL;
else if(EllipseDlg.m_HatchStyle== "HS_HORIZONTAL")
pEllipse->MyBrush.lbHatch=HS_HORIZONTAL;
else
pEllipse->MyBrush.lbHatch=HS_VERTICAL;
if(EllipseDlg.m_BrushStyle=="BS_HATCHED")
pEllipse->MyBrush.lbStyle=BS_HATCHED;
else if(EllipseDlg.m_BrushStyle=="BS_NULL")
pEllipse->MyBrush.lbStyle=BS_NULL;
else
pEllipse->MyBrush.lbStyle=BS_SOLID;
Invalidate();
}
}
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CArc)))
{
pArc = (CArc*)pHitItem;
if(pArc != NULL)
{
if (pArc->bIsSelected)
{
CLineProperties LineDlg;
CString str_LineWidth;
str_LineWidth.Format("%d",pArc->LinePen.lopnWidth.x);
LineDlg.m_LineWidth=str_LineWidth;
if (pArc->LinePen.lopnStyle==PS_DASH)
LineDlg.m_LineStyle="虚线";
else if (pArc->LinePen.lopnStyle==PS_DOT)
LineDlg.m_LineStyle="点线";
else if(pArc->LinePen.lopnStyle==PS_DASHDOT)
LineDlg.m_LineStyle="点划线";
else
LineDlg.m_LineStyle="实线";
LineDlg.m_LineColor=pArc->LinePen.lopnColor;
if (LineDlg.DoModal()==IDOK)
{
pArc->LinePen.lopnWidth.x=atoi(LineDlg.m_LineWidth);
if (LineDlg.m_LineStyle=="虚线")
pArc->LinePen.lopnStyle=PS_DASH;
else if (LineDlg.m_LineStyle=="点线")
pArc->LinePen.lopnStyle=PS_DOT;
else if(LineDlg.m_LineStyle=="点划线")
pArc->LinePen.lopnStyle=PS_DASHDOT;
else
pArc->LinePen.lopnStyle=PS_SOLID;
pArc->LinePen.lopnColor=LineDlg.m_LineColor;
Invalidate();
}
}
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CText)))
{
pText = (CText*)pHitItem;
if(pText != NULL)
{
if (pText->bIsSelected)
{
CTextProperties TextDlg;
if (pText->BkMode==TRANSPARENT)
TextDlg.m_BkMode=true;
else
TextDlg.m_BkMode=false;
TextDlg.m_Font=pText->MyFont;
TextDlg.m_TextColor=pText->MyColor;
TextDlg.m_Text=pText->MyText;
if (TextDlg.DoModal()==IDOK)
{
pText->MyFont=TextDlg.m_Font;
pText->MyColor=TextDlg.m_TextColor;
pText->MyText=TextDlg.m_Text;
if (TextDlg.m_BkMode)
pText->BkMode=TRANSPARENT;
else
pText->BkMode=OPAQUE;
Invalidate();
}
}
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CRectangle)))
{
pRectangle = (CRectangle*)pHitItem;
if(pRectangle != NULL)
{
if (pRectangle->bIsSelected)
{
CEllipseProperties EllipseDlg;
CString str_LineWidth;
str_LineWidth.Format("%d",pRectangle->LinePen.lopnWidth.x);
EllipseDlg.m_LineWidth=str_LineWidth;
if (pRectangle->LinePen.lopnStyle==PS_DASH)
EllipseDlg.m_LineStyle="虚线";
else if (pRectangle->LinePen.lopnStyle==PS_DOT)
EllipseDlg.m_LineStyle="点线";
else if(pRectangle->LinePen.lopnStyle==PS_DASHDOT)
EllipseDlg.m_LineStyle="点划线";
else
EllipseDlg.m_LineStyle="实线";
EllipseDlg.m_LineColor=pRectangle->LinePen.lopnColor;
EllipseDlg.m_BrushColor=pRectangle->MyBrush.lbColor;
if(pRectangle->MyBrush.lbHatch==HS_BDIAGONAL)
EllipseDlg.m_HatchStyle= "HS_BDIAGONAL";
else if(pRectangle->MyBrush.lbHatch==HS_CROSS)
EllipseDlg.m_HatchStyle= "HS_CROSS";
else if(pRectangle->MyBrush.lbHatch==HS_DIAGCROSS)
EllipseDlg.m_HatchStyle= "HS_DIAGCROSS";
else if(pRectangle->MyBrush.lbHatch==HS_FDIAGONAL)
EllipseDlg.m_HatchStyle= "HS_FDIAGONAL";
else if(pRectangle->MyBrush.lbHatch==HS_HORIZONTAL)
EllipseDlg.m_HatchStyle= "HS_HORIZONTAL";
else
EllipseDlg.m_HatchStyle= "HS_VERTICAL";
if(pRectangle->MyBrush.lbStyle==BS_HATCHED)
EllipseDlg.m_BrushStyle= "BS_HATCHED";
else if(pRectangle->MyBrush.lbStyle==BS_NULL)
EllipseDlg.m_BrushStyle= "BS_NULL";
else
EllipseDlg.m_BrushStyle= "BS_SOLID";
if (EllipseDlg.DoModal()==IDOK)
{
pRectangle->LinePen.lopnWidth.x=atoi(EllipseDlg.m_LineWidth);
if (EllipseDlg.m_LineStyle=="虚线")
pRectangle->LinePen.lopnStyle=PS_DASH;
else if (EllipseDlg.m_LineStyle=="点线")
pRectangle->LinePen.lopnStyle=PS_DOT;
else if(EllipseDlg.m_LineStyle=="点划线")
pRectangle->LinePen.lopnStyle=PS_DASHDOT;
else
pRectangle->LinePen.lopnStyle=PS_SOLID;
pRectangle->LinePen.lopnColor=EllipseDlg.m_LineColor;
pRectangle->MyBrush.lbColor=EllipseDlg.m_BrushColor;
if(EllipseDlg.m_HatchStyle== "HS_BDIAGONAL")
pRectangle->MyBrush.lbHatch=HS_BDIAGONAL;
else if(EllipseDlg.m_HatchStyle== "HS_CROSS")
pRectangle->MyBrush.lbHatch=HS_CROSS;
else if(EllipseDlg.m_HatchStyle== "HS_DIAGCROSS")
pRectangle->MyBrush.lbHatch=HS_DIAGCROSS;
else if(EllipseDlg.m_HatchStyle== "HS_FDIAGONAL")
pRectangle->MyBrush.lbHatch=HS_FDIAGONAL;
else if(EllipseDlg.m_HatchStyle== "HS_HORIZONTAL")
pRectangle->MyBrush.lbHatch=HS_HORIZONTAL;
else
pRectangle->MyBrush.lbHatch=HS_VERTICAL;
if(EllipseDlg.m_BrushStyle=="BS_HATCHED")
pRectangle->MyBrush.lbStyle=BS_HATCHED;
else if(EllipseDlg.m_BrushStyle=="BS_NULL")
pRectangle->MyBrush.lbStyle=BS_NULL;
else
pRectangle->MyBrush.lbStyle=BS_SOLID;
Invalidate();
}
}
}
}
}
CView::OnLButtonDblClk(nFlags, point);
}
void CMyDrawView::OnButtonLine()
{
// TODO: Add your command handler code here
CLine* pLine=new CLine;
m_ObjectList.AddTail(pLine);
Invalidate();
}
void CMyDrawView::OnButtonEllipse()
{
// TODO: Add your command handler code here
CEllipse* pEllipse=new CEllipse;
m_ObjectList.AddTail(pEllipse);
Invalidate();
}
void CMyDrawView::OnButtonRectangle()
{
// TODO: Add your command handler code here
CRectangle* pRectangle=new CRectangle;
m_ObjectList.AddTail(pRectangle);
Invalidate();
}
void CMyDrawView::OnButtonArc()
{
// TODO: Add your command handler code here
CArc* pArc=new CArc;
srand(::GetTickCount());
if(rand()%10+1>5)//产生一个1到10的随机数
pArc->Direction=0;
else
pArc->Direction=1;
m_ObjectList.AddTail(pArc);
Invalidate();
}
void CMyDrawView::OnButtonText()
{
// TODO: Add your command handler code here
CText* pText=new CText;
m_ObjectList.AddTail(pText);
Invalidate();
}
void CMyDrawView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CEllipse* pEllipse = NULL;
CLine* pLine=NULL;
CRectangle* pRectangle=NULL;
CArc* pArc=NULL;
CText* pText=NULL;
if (46==nChar)
{
POSITION pos = m_ObjectList.GetTailPosition();
CObject* pHitItem;
while(pos != NULL)
{
POSITION curpos=pos;
pHitItem=(CObject*)m_ObjectList.GetPrev(pos);
if (pHitItem->IsKindOf(RUNTIME_CLASS(CEllipse)))
{
pEllipse = (CEllipse*)pHitItem;
if(pEllipse != NULL)
{
if (pEllipse->bIsSelected)
{
m_ObjectList.RemoveAt(curpos);
Invalidate();
break;
}
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CLine)))
{
pLine = (CLine*)pHitItem;
if(pLine != NULL)
{
if (pLine->bIsSelected)
{
m_ObjectList.RemoveAt(curpos);
Invalidate();
break;
}
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CArc)))
{
pArc = (CArc*)pHitItem;
if(pArc != NULL)
{
if (pArc->bIsSelected)
{
m_ObjectList.RemoveAt(curpos);
Invalidate();
break;
}
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CText)))
{
pText = (CText*)pHitItem;
if(pText != NULL)
{
if (pText->bIsSelected)
{
m_ObjectList.RemoveAt(curpos);
Invalidate();
break;
}
}
}
else if (pHitItem->IsKindOf(RUNTIME_CLASS(CRectangle)))
{
pRectangle = (CRectangle*)pHitItem;
if(pRectangle != NULL)
{
if (pRectangle->bIsSelected)
{
m_ObjectList.RemoveAt(curpos);
Invalidate();
break;
}
}
}
}
}
CView::OnKeyUp(nChar, nRepCnt, nFlags);
}