Solved

Undo / Redo

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 150
haveThree challenge 22 100
changeXy challenge 13 58
firstChar challenge 13 85
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now