Click here to Skip to main content
15,886,061 members
Articles / Programming Languages / C++

Undo and Redo the "Easy" Way

Rate me:
Please Sign up or sign in to vote.
4.95/5 (42 votes)
20 Jun 2004CPOL22 min read 289.8K   8.6K   114  
This article introduces a simple approach to in-memory transactions that can be used to implement Undo and Redo. The technique uses SEH and Virtual Memory and requires only STL and Win32.
// DrawItView.h : interface of the CDrawItView class
//


#pragma once


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

// Attributes
public:
	CDrawItDoc* GetDocument() const;

// Operations
public:

// Overrides
	public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);

// Implementation
public:
	virtual ~CDrawItView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	unsigned int m_spec;

// Generated message map functions
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnEditAbuse();
	afx_msg void OnEditAbuse2();
	afx_msg void OnInsertCommand(UINT id);
	afx_msg void OnUpdateInsertCommand(CCmdUI* pCmdUI);
	afx_msg void OnViewDrawobjects();
	afx_msg void OnUpdateViewDrawobjects(CCmdUI *pCmdUI);
protected:
	DECLARE_MESSAGE_MAP()
private:
	bool m_bDrawItems;
	unsigned long m_openMouseTransaction;
	unsigned long m_idCreating;
};

#ifndef _DEBUG  // debug version in DrawItView.cpp
inline CDrawItDoc* CDrawItView::GetDocument() const
   { return reinterpret_cast<CDrawItDoc*>(m_pDocument); }
#endif

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 Code Project Open License (CPOL)


Written By
United States United States
A compiler warns of bogasity, ignore it at your peril. Unless you've done the compiler's job yourself, don't criticize it.

Comments and Discussions