Solved

Undo / Redo

Posted on 1997-09-04
5
625 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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