📄 testundoview.cpp
字号:
// TestUndoView.cpp : implementation of the CTestUndoView class
//
#include "stdafx.h"
#include "TestUndo.h"
#include "TestUndoDoc.h"
#include "TestUndoView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestUndoView
IMPLEMENT_DYNCREATE(CTestUndoView, CView)
BEGIN_MESSAGE_MAP(CTestUndoView, CView)
//{{AFX_MSG_MAP(CTestUndoView)
ON_WM_LBUTTONDOWN()
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CTestUndoView construction/destruction
CTestUndoView::CTestUndoView()
{
// TODO: add construction code here
}
CTestUndoView::~CTestUndoView()
{
}
BOOL CTestUndoView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTestUndoView drawing
void CTestUndoView::OnDraw(CDC* pDC)
{
CTestUndoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CMyObjCollection* pObjs = &pDoc->m_objects;
for (int i = 0; i < pObjs->getCount(); i++)
pObjs->getItem(i)->Draw(pDC);
}
/////////////////////////////////////////////////////////////////////////////
// CTestUndoView printing
BOOL CTestUndoView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTestUndoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTestUndoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTestUndoView diagnostics
#ifdef _DEBUG
void CTestUndoView::AssertValid() const
{
CView::AssertValid();
}
void CTestUndoView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTestUndoDoc* CTestUndoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestUndoDoc)));
return (CTestUndoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTestUndoView message handlers
void CTestUndoView::OnLButtonDown(UINT nFlags, CPoint point)
{
CTestUndoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->AddMyObject( point );
Invalidate( );
CView::OnLButtonDown(nFlags, point);
}
void CTestUndoView::OnEditUndo()
{
CTestUndoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_undoManager.Undo();
Invalidate();
}
void CTestUndoView::OnRButtonDown(UINT nFlags, CPoint point)
{
CTestUndoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int nCount = pDoc->m_objects.getCount();
for( int i = 0; i < nCount; i ++ )
{
CMyObject * pObj = pDoc->m_objects.getItem(i);
if( pObj->GetObjRect().PtInRect(point) )
{
CRect rect = pObj->GetObjRect();
rect.right += 10;
rect.bottom += 10;
pDoc->ModObj( rect, pObj );
break;
}
}
Invalidate();
CView::OnRButtonDown(nFlags, point);
}
void CTestUndoView::OnEditRedo()
{
CTestUndoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_undoManager.Redo();
Invalidate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -