?
Solved

Undo / Redo

Posted on 1997-09-04
5
Medium Priority
?
626 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 200 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

741 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