📄 mazeview.cpp
字号:
// MazeView.cpp : implementation of the CMazeView class
//
#include "stdafx.h"
#include "Maze.h"
#include "MazeDoc.h"
#include "MazeView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMazeView
CPoint m_point;
IMPLEMENT_DYNCREATE(CMazeView, CView)
BEGIN_MESSAGE_MAP(CMazeView, CView)
//{{AFX_MSG_MAP(CMazeView)
ON_WM_LBUTTONDOWN()
ON_COMMAND(cross, Oncross)
ON_COMMAND(select, Onselect)
ON_WM_SETCURSOR()
ON_WM_MOUSEMOVE()
ON_COMMAND(across, Onacross)
ON_COMMAND(erect, Onerect)
ON_COMMAND(TopRight, OnTopRight)
ON_COMMAND(TopLeft, OnTopLeft)
ON_COMMAND(BottomLeft, OnBottomLeft)
ON_COMMAND(BottomRight, OnBottomRight)
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()
/////////////////////////////////////////////////////////////////////////////
// CMazeView construction/destruction
CMazeView::CMazeView()
{
Flag=0;
// TODO: add construction code here
}
CMazeView::~CMazeView()
{
}
BOOL CMazeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMazeView drawing
void CMazeView::OnDraw(CDC* pDC)
{
CMazeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
POSITION pos;
CShape* pShape;
CObList* p=pList;
for( pos = p->GetHeadPosition();
pos != NULL; p->GetNext( pos ))
{
pShape=(CShape*)p->GetAt(pos);
pShape->Draw(pDC);
}
}
/////////////////////////////////////////////////////////////////////////////
// CMazeView printing
BOOL CMazeView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMazeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMazeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMazeView diagnostics
#ifdef _DEBUG
void CMazeView::AssertValid() const
{
CView::AssertValid();
}
void CMazeView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMazeDoc* CMazeView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMazeDoc)));
return (CMazeDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMazeView message handlers
void CMazeView::OnInitialUpdate()
{
CView::OnInitialUpdate();
CMazeDoc* pDoc=GetDocument();
pList=&(pDoc->List);
// TODO: Add your specialized code here and/or call the base class
}
void CMazeView::OnLButtonDown(UINT nFlags, CPoint point)
{
if(Flag==1)
{
CPoint p1(point.x,point.y),
p2(point.x+20,point.y+20);
CRect rect(p1,p2);
CShape* p=new CCross(rect);
pList->AddHead(p);
Invalidate();
}
else if(Flag==2)
{
CPoint p1(point.x,point.y),
p2(point.x+20,point.y+20);
CRect rect(p1,p2);
CShape* p=new CAcross(rect);
pList->AddHead(p);
Invalidate();
}
else if(Flag==3)
{
CPoint p1(point.x,point.y),
p2(point.x+20,point.y+20);
CRect rect(p1,p2);
CShape* p=new CErect(rect);
pList->AddHead(p);
Invalidate();
}
else if(Flag==4)
{
CPoint p1(point.x,point.y),
p2(point.x+20,point.y+20);
CRect rect(p1,p2);
CShape* p=new CTopRight(rect);
pList->AddHead(p);
Invalidate();
}
else if(Flag==5)
{
CPoint p1(point.x,point.y),
p2(point.x+20,point.y+20);
CRect rect(p1,p2);
CShape* p=new CTopLeft(rect);
pList->AddHead(p);
Invalidate();
}
else if(Flag==6)
{
CPoint p1(point.x,point.y),
p2(point.x+20,point.y+20);
CRect rect(p1,p2);
CShape* p=new CBottomLeft(rect);
pList->AddHead(p);
Invalidate();
}
else if(Flag==7)
{
CPoint p1(point.x,point.y),
p2(point.x+20,point.y+20);
CRect rect(p1,p2);
CShape* p=new CBottomRight(rect);
pList->AddHead(p);
Invalidate();
}
else if(Flag==0)
{
POSITION pos;
CShape* pShape;
CObList* p=pList;
for( pos = p->GetHeadPosition();
pos != NULL; p->GetNext( pos ))
{
pShape=(CShape*)p->GetAt(pos);
if(pShape->HitTest(point)==8)
{
pShape->SetStyleTracker(CRectTracker::dottedLine|CRectTracker::resizeOutside);
pShape->SetSelected(true);
}
else if(pShape->HitTest(point)==-1)
{
pShape->SetStyleTracker(0);
pShape->SetSelected(false);
}
pShape->Track(this,point,FALSE,NULL);
Invalidate();
}
}
CView::OnLButtonDown(nFlags, point);
}
void CMazeView::Oncross()
{
Flag=1;
}
void CMazeView::Onselect()
{
Flag=0;
}
BOOL CMazeView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
int nx=-1;
char *CurStyle=IDC_ARROW;
HCURSOR hCur;
POSITION pos;
CShape* pShape;
CObList* p=pList;
for( pos = p->GetHeadPosition();
pos != NULL; p->GetNext( pos ))
{
pShape=(CShape*)p->GetAt(pos);
if(pShape->GetSelected())
{
nx=pShape->HitTest(m_point);
switch (nx)
{
case -1:
CurStyle=IDC_ARROW;
break;
case 8:
CurStyle=IDC_SIZEALL;
break;
case 0:
case 2:
CurStyle=IDC_SIZENWSE;
break;
case 1:
case 3:
CurStyle=IDC_SIZENESW;
break;
case 4:
case 6:
CurStyle=IDC_SIZENS;
break;
case 5:
case 7:
CurStyle=IDC_SIZEWE ;
break;
}
hCur=((CMazeApp*)AfxGetApp())->LoadStandardCursor(CurStyle);
// if(::SetCursor(hCur))
// return true;
}
}
return CView::OnSetCursor(pWnd, nHitTest, message);
}
void CMazeView::OnMouseMove(UINT nFlags, CPoint point)
{
m_point=point;
CView::OnMouseMove(nFlags, point);
}
void CMazeView::Onacross()
{
Flag=2;
}
void CMazeView::Onerect()
{
Flag=3;
// TODO: Add your command handler code here
}
void CMazeView::OnTopRight()
{
Flag=4;
}
void CMazeView::OnTopLeft()
{
Flag=5;
}
void CMazeView::OnBottomLeft()
{
Flag=6;
}
void CMazeView::OnBottomRight()
{
Flag=7;
}
void CMazeView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(nChar==VK_DELETE)
{
POSITION pos;
CShape* pShape;
CObList* p=pList;
for( pos = p->GetHeadPosition();
pos != NULL; p->GetNext( pos ))
{
pShape=(CShape*)p->GetAt(pos);
if(pShape->GetSelected())
{
p->RemoveAt(pos);
break;
}
}
Invalidate();
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -