Solved

Undo / Redo

Posted on 1997-09-04
5
624 Views
Last Modified: 2013-11-20
I am implementing a graphical newtork editor in Visual C++ 5.0 running on the Windows NT 4.0 platform. This editor should support multiple undo / redo functionality.

I have looked in all available MFC / OLE / COM books and in the online help in DevStudio and the only information I have found has been the manual pages for:
      IOleUndoManager
      IOleUndoUnit
      IOleParentUndoUnit

In my opinion these man pages are very difficult to understand especially since no examples are included with them.

Is there anyone out there who can give me any information and perhaps examples on how undo / redo is best implemented using MFC.
0
Comment
Question by:julieb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Expert Comment

by:byang
ID: 1305783
Trap undo/redo keys and handle them yourself. For contained OLE objects, just pump the keyboard input to them.
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1305784
The concept of undo and redo was hard for me to understand until I read that the state of the application is captured by the undo and redo.

For example, let's say that you want to create a graphical editor that lets you draw lines and circles and such. So when a user draws a line, you catch the difference of the state of the application before and after drawing that line and store that within an object and store that object within a list (because you want to support more than one level of undo). Then if the user decides to undo that line, the object knows what was affected by that line and restores everything back. Of course, if the user wants to redo, the object is still in the list and knows how to put the line back.

If you want to read more about undo/redo objects, I recommend you pick up the book Design Patterns by Gamma et al. It is a really good book on designing applications with C++.
0
 

Author Comment

by:julieb
ID: 1305786
No pointers on how to implement Undo / Redo best in MFC
0
 
LVL 8

Expert Comment

by:gelbert
ID: 1305785
Check http://web.ukonline.co.uk/Members/julian.smart/code.html. You can find sample code there called "Command/Undo"
0
 
LVL 1

Accepted Solution

by:
kargo earned 100 total points
ID: 1305787
What we did here was to use serialization into a memory file of the document components that change.  Basically the components that are possible to change are small.  We wrapped them into a class that supports serialization.  Then when a process is done the parts get serialized into a memory file which we then keep the HGLOBAL.  If the user does an undo we deserialize the last HGLOBAL.  The application uses a round buffer to manage many HGLOBALs allowing us to have multilayer undo/redo.  The pointers are manages using a double link (next/Prev).  We use memory for speed.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question