?? test1view.cpp
字號(hào):
// test1View.cpp : implementation of the CTest1View class
//
#include <afxwin.h>
#include "stdafx.h"
#include "test1.h"
#include "Object1.h"
#include "Rectangle.h"
#include "Line.h"
#include "From.h"
#include "test1Doc.h"
#include "test1View.h"
#include "Tuoyuan.h"
#include "Circle.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTest1View
IMPLEMENT_DYNCREATE(CTest1View, CView)
BEGIN_MESSAGE_MAP(CTest1View, CView)
//{{AFX_MSG_MAP(CTest1View)
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_DRAW_SUISHOU, OnDrawSuishou)
ON_COMMAND(ID_DRAW_LINE, OnDrawLine)
ON_COMMAND(ID_DRAW_CIRCLE, OnDrawCircle)
ON_COMMAND(ID_DRAW_RECTANGLE, OnDrawRectangle)
ON_COMMAND(ID_DRAW_TUOYUAN, OnDrawTuoyuan)
ON_COMMAND(ID_PEN_WIDTH1, OnPenWidth1)
ON_COMMAND(ID_PEN_WIDTH3, OnPenWidth3)
ON_COMMAND(ID_PEN_WIDTH5, OnPenWidth5)
ON_COMMAND(ID_PEN_WIDTH7, OnPenWidth7)
ON_COMMAND(ID_PEN_DOT, OnPenDot)
ON_COMMAND(ID_PEN_DUSH, OnPenDush)
ON_COMMAND(ID_PEN_SOLID, OnPenSolid)
ON_COMMAND(ID_BRUSH_SOLID, OnBrushSolid)
ON_COMMAND(ID_DRAW_GETCOLOR, OnDrawGetcolor)
ON_COMMAND(ID_PEN, OnPen)
ON_COMMAND(ID_DRAW_DELET, OnDrawDelet)
ON_COMMAND(ID_DRAW_MOVE, OnDrawMove)
ON_WM_KEYDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTest1View construction/destruction
CTest1View::CTest1View()
{
// TODO: add construction code here
m_bStart=false;
m_euDrawType=DRAW_LINE;
pObject=NULL;
m_nPenType=PS_SOLID;
m_nPenWidth=1;
m_nSelect=0;
m_bMoveSelect=false;
m_bDraw=false;
m_crColor=RGB(0,0,0);
}
CTest1View::~CTest1View()
{
CTest1Doc* pDoc = GetDocument();
POSITION pos=pDoc->m_ltRecord.GetHeadPosition();
while (pos)
{
CObject1* pObject=(CObject1*)pDoc->m_ltRecord.GetNext(pos);
// delete pObject;//沒(méi)有這句,就沒(méi)有關(guān)閉時(shí)的錯(cuò)誤提示
}
}
BOOL CTest1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTest1View drawing
void CTest1View::OnDraw(CDC* pDC)
{
CTest1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
POSITION pos=pDoc->m_ltRecord.GetHeadPosition();
while (pos)
{
CObject1* pObject=(CObject1*)pDoc->m_ltRecord.GetNext(pos);
pObject->Draw(pDC);
}
/*
if (m_bMoveSelect)
{
POSITION pos=m_listRecord.GetHeadPosition();
while (pos)
{
CObject1* pObject=(CObject1*)m_listRecord.GetNext(pos);
pObject->Draw(pDC);
}
}*/
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CTest1View printing
BOOL CTest1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTest1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTest1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTest1View diagnostics
#ifdef _DEBUG
void CTest1View::AssertValid() const
{
CView::AssertValid();
}
void CTest1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTest1Doc* CTest1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTest1Doc)));
return (CTest1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTest1View message handlers
void CTest1View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// CDC* pDC=this->GetDC();//沒(méi)有用到
CTest1Doc* pDoc = GetDocument();
if (m_bDraw)
{
switch(m_euDrawType)
{
case DRAW_LINE:
{
pDoc->m_ltRecord.AddTail(pObject);
}
break;
case DRAW_SUISHOU:
{
pDoc->m_ltRecord.AddTail(pObject);
}
case DRAW_RECTANGLE:
{
pDoc->m_ltRecord.AddTail(pObject);
}
break;
case DRAW_TUOYUAN:
{
pDoc->m_ltRecord.AddTail(pObject);
}
break;
case DRAW_CIRCLE:
{
pDoc->m_ltRecord.AddTail(pObject);
}
default:
break;
}
}
m_bDraw=false;
m_bMoveSelect=false;
m_bStart=false;
// m_listRecord.AddTail(pObject);
pObject->GetPoint(m_ptFirst,point);
pObject->PassWord(m_nPenType,m_nPenWidth,m_crColor,m_nSelect);
Invalidate();
CView::OnLButtonUp(nFlags, point);
}
void CTest1View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bStart=true;
m_ptFirst=point;
m_ptEnd=point;
m_ptTemp=point;
if(m_bMoveSelect)
{
m_bDraw=false;
}
else
{
m_bDraw=true;
switch(m_euDrawType)
{
case DRAW_SUISHOU:
pObject=new CFrom;
break;
case DRAW_LINE:
pObject=new CLine;
break;
case DRAW_RECTANGLE:
pObject=new CRectangle;
break;
case DRAW_TUOYUAN:
pObject=new CTuoyuan;
break;
case DRAW_CIRCLE:
pObject=new CCircle;
break;
default:
break;
}
}
switch(m_euOperator)
{
case OPER_SELECT:
{
if (IsInArea(point))
{
m_bMoveSelect=true;
m_ptTemp=point;
TRACE("m_ptTemp.x=%d\n m_ptTemp.y=%d\n",m_ptTemp.x,m_ptTemp.y);
m_bDraw=false;
}
}
break;
case OPER_DELETE:
{
if(IsInArea(point))
{
m_bDraw=false;
m_bMoveSelect=true;
}
}
break;
default:
break;
}//對(duì)這段話的位置有疑問(wèn)
/*
if (m_euOperator==OPER_SELECT&&IsInArea(point))
{
m_bMoveSelect=true;
m_ptTemp=point;
TRACE("m_ptTemp.x=%d\n m_ptTemp.y=%d\n",m_ptTemp.x,m_ptTemp.y);
m_bDraw=false;
}*/
CView::OnLButtonDown(nFlags, point);
}
void CTest1View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC*pDC=this->GetDC();
int old=pDC->SetROP2(R2_NOTXORPEN);
if (m_bDraw)
{
if (m_bStart)
{
switch(m_euDrawType)
{
case DRAW_SUISHOU:
{
pDC->MoveTo(m_ptFirst);
pDC->LineTo(point);
pObject->GetPoint(m_ptFirst,point);
m_ptFirst=point;
}
break;
case DRAW_LINE:
{
pDC->MoveTo(m_ptFirst);
pDC->LineTo(m_ptEnd);
m_ptEnd=point;
pDC->MoveTo(m_ptFirst);
pDC->LineTo(m_ptEnd);
// pObject->GetPoint(m_ptFirst,point);
}
break;
case DRAW_RECTANGLE:
{
pDC->Rectangle(m_ptFirst.x,m_ptFirst.y,m_ptEnd.x,m_ptEnd.y);
m_ptEnd=point;
// pObject->GetPoint(m_ptFirst,point);
pDC->Rectangle(m_ptFirst.x,m_ptFirst.y,m_ptEnd.x,m_ptEnd.y);
}
break;
case DRAW_TUOYUAN:
{
pDC->Ellipse(m_ptFirst.x,m_ptFirst.y,m_ptEnd.x,m_ptEnd.y);
m_ptEnd=point;
// pObject->GetPoint(m_ptFirst,point);
pDC->Ellipse(m_ptFirst.x,m_ptFirst.y,m_ptEnd.x,m_ptEnd.y);
}
break;
case DRAW_CIRCLE:
{
pDC->Ellipse(m_ptFirst.x,m_ptFirst.y,m_ptEnd.x,m_ptEnd.y);
m_ptEnd=point;
// pObject->GetPoint(m_ptFirst,point);
pDC->Ellipse(m_ptFirst.x,m_ptFirst.y,m_ptEnd.x,m_ptEnd.y);
}
break;
default:
break;
}
// pDC->SetROP2(old);
}
}
if(m_bMoveSelect)
{
// int old=pDC->SetROP2(R2_NOTXORPEN);
CPoint pt1=point-m_ptTemp+m_pObject->SetFirstPoint();
CPoint pt2=point-m_ptTemp+m_pObject->SetEndPoint();
m_pObject->Draw(pDC);
m_pObject->GetPoint(pt1,pt2);
m_ptTemp=point;
m_pObject->Draw(pDC);
// pDC->SetROP2(old);
}
CView::OnMouseMove(nFlags, point);
}
bool CTest1View::IsInArea(CPoint point)
{
int x1,x2,y1,y2;
x1=x2=y1=y2=0;
CTest1Doc* pDoc = GetDocument();
POSITION pos=pDoc->m_ltRecord.GetTailPosition();//與移動(dòng)時(shí)讀取順序有關(guān)
while (pos)
{
m_pObject=(CObject1*)pDoc->m_ltRecord.GetPrev(pos);//與移動(dòng)時(shí)讀取順序有關(guān)
x1=m_pObject->SetFirstPoint().x;
y1=m_pObject->SetFirstPoint().y;
x2=m_pObject->SetEndPoint().x;
y2=m_pObject->SetEndPoint().y;
CRgn rgn;
rgn.CreateRectRgn(x1,y1,x2,y2);
BOOL isin=rgn.PtInRegion(point);
if (isin)
{
return true;
}
}
return false;
}
void CTest1View::OnDrawSuishou()
{
// TODO: Add your command handler code here
m_euDrawType=DRAW_SUISHOU;
m_nSelect=0;
}
void CTest1View::OnDrawLine()
{
// TODO: Add your command handler code here
m_euDrawType=DRAW_LINE;
m_nSelect=0;
}
void CTest1View::OnDrawCircle()
{
// TODO: Add your command handler code here
m_euDrawType=DRAW_CIRCLE;
}
void CTest1View::OnDrawRectangle()
{
// TODO: Add your command handler code here
m_euDrawType=DRAW_RECTANGLE;
}
void CTest1View::OnDrawTuoyuan()
{
// TODO: Add your command handler code here
m_euDrawType=DRAW_TUOYUAN;
}
void CTest1View::OnPenWidth1()
{
// TODO: Add your command handler code here
m_nPenWidth=1;
m_nSelect=0;
}
void CTest1View::OnPenWidth3()
{
// TODO: Add your command handler code here
m_nPenWidth=3;
m_nSelect=0;
}
void CTest1View::OnPenWidth5()
{
// TODO: Add your command handler code here
m_nPenWidth=5;
m_nSelect=0;
}
void CTest1View::OnPenWidth7()
{
// TODO: Add your command handler code here
m_nPenWidth=7;
m_nSelect=0;
}
void CTest1View::OnPenDot()
{
// TODO: Add your command handler code here
m_nPenType=PS_DOT;
m_nSelect=0;
}
void CTest1View::OnPenDush()
{
// TODO: Add your command handler code here
m_nPenType=PS_DASH;
m_nSelect=0;
}
void CTest1View::OnPenSolid()
{
// TODO: Add your command handler code here
m_nPenType=PS_SOLID;
m_nSelect=0;
}
void CTest1View::OnBrushSolid()
{
// TODO: Add your command handler code here
m_nSelect=1;
}
void CTest1View::OnDrawGetcolor()
{
// TODO: Add your command handler code here
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
{
m_crColor = dlg.GetColor();
}
}
void CTest1View::OnPen()
{
// TODO: Add your command handler code here
m_nSelect=0;
}
void CTest1View::OnDrawDelet()
{
// TODO: Add your command handler code here
m_euOperator=OPER_MOVE;
}
void CTest1View::OnDrawMove()
{
// TODO: Add your command handler code here
m_euOperator=OPER_SELECT;
// m_bMoveSelect=true;
}
void CTest1View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
char Ischar;
Ischar=char(nChar);
if(Ischar==VK_DELETE)
{
/*
for(m_ptFirst=m_listRecord.GetTailPosition();(m_ptFirst=m_ptEnd)!==NULL)
pObject=m_listRecord.GetAt(m_ptEnd);
m_listRecord.RemoveAt(m_ptEnd);
delete pObject;*/
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -