Click here to Skip to main content
15,894,740 members
Articles / Desktop Programming / MFC

Action History - Undo and Redo

Rate me:
Please Sign up or sign in to vote.
3.20/5 (11 votes)
6 Mar 2004MIT2 min read 44.8K   1.2K   18  
A useful undo/redo system that can be implemented into most programs easily.
// UndoRedoView.h : interface of the CUndoRedoView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_UNDOREDOVIEW_H__BB2CC71D_AA77_4519_ABBE_0D15B7C57BE5__INCLUDED_)
#define AFX_UNDOREDOVIEW_H__BB2CC71D_AA77_4519_ABBE_0D15B7C57BE5__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


class CUndoRedoView : public CView
{
protected: // create from serialization only
	CUndoRedoView();
	DECLARE_DYNCREATE(CUndoRedoView)

// Attributes
public:
	CUndoRedoDoc* GetDocument();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CUndoRedoView)
	public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	//}}AFX_VIRTUAL

// Implementation
public:
	void DrawDragBox(CDC* pDC, bool bErase = false);
	void DrawUserInfo(CDC* pDC);

	virtual ~CUndoRedoView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CUndoRedoView)
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

private:
	CRect m_rtBox;			// stores the coordinates of the box on-screen
	CPoint m_ptOldMouse;	// stores the anchor position
	bool bDragBox;			// is the user dragging the box
};

#ifndef _DEBUG  // debug version in UndoRedoView.cpp
inline CUndoRedoDoc* CUndoRedoView::GetDocument()
   { return (CUndoRedoDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_UNDOREDOVIEW_H__BB2CC71D_AA77_4519_ABBE_0D15B7C57BE5__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer Rotorz Limited
United Kingdom United Kingdom
I have been fascinated by software and video games since a young age when I was given my first computer, a Dragon 32. Since then I have experimented with numerous methods of development ranging from point-and-click type packages to C++. I soon realized that software development was what I wanted to do.

Having invested a lot of time into programming with various languages and technologies I now find it quite easy to pickup new ideas and methodologies. I relish learning new ideas and concepts.

Throughout my life I have dabbled in game and engine development. I was awarded a first for the degree "BEng Games and Entertainment Systems Software Engineering" at the University of Greenwich. It was good to finally experience video games from a more professional perspective.

Due to various family difficulties I was unable to immediately pursue any sort of software development career. This didn't stop me from dabbling though!

Since then I formed a company to focus upon client projects. Up until now the company has primarily dealt with website design and development. I have since decided that it would be fun to go back to my roots and develop games and tools that other developers can use for their games.

We have recently released our first game on iPhone/iPad called "Munchy Bunny!" (see: http://itunes.apple.com/us/app/munchy-bunny!/id516575993?mt=8). We hope to expand the game and release to additional platforms.

Also, check out our tile system extension for Unity! (see: http://rotorz.com/tilesystem/)

Comments and Discussions