Question

Is there a way to suspend/resume the Undo recording in a TRichEdit control? Is there a message to send or a mode to set?

EDIT
I have solved it by using the ITextDocument interface. See my post below.

Was it helpful?

Solution

Okay I solved it.

You have to use the ITextDocument interface to set the various undo modes. In this example Script_Edit is a TRichEdit control.

#include <Richole.h>
#include <Tom.h>

// Define the ITextDocument interface GUID
#define DEFINE_GUIDXXX(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
        EXTERN_C const GUID CDECL name \
                = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }

DEFINE_GUIDXXX(IID_ITextDocument,0x8CC497C0,0xA1DF,0x11CE,0x80,0x98,
                0x00,0xAA,0x00,0x47,0xBE,0x5D);

IRichEditOle  *IRich;
ITextDocument *IDoc;

// Get the IRichEditOle interface object
SendMessage(Script_Edit->Handle,EM_GETOLEINTERFACE,0,(LPARAM)&IRich);

// Get the ITextDocument interface
IRich->QueryInterface(IID_ITextDocument,(void**)&IDoc);

// Suspend the Undo recording
IDoc->Undo(tomSuspend,NULL);

 ... Do your stuff ...

// Resume the Undo recording
IDoc->Undo(tomResume,NULL);

// Release the interfaces
IDoc->Release();
IRich->Release();

The ITextDocument->Undo() can be used with:

ITextDocument->Undo(tomFalse,   NULL); //Prevents Undo and empties buffer.
ITextDocument->Undo(tomTrue,    NULL); //Restarts Undo again.
ITextDocument->Undo(tomSuspend, NULL); //Suspends Undo.
ITextDocument->Undo(tomResume,  NULL); //Resumes Undo.

I hope this can be useful to others too...

OTHER TIPS

See the EM_SETUNDOLIMIT message:

Sets the maximum number of actions that can stored in the undo queue of a rich edit control.

Parameters

wParam Specifies the maximum number of actions that can be stored in the undo queue.

lParam This parameter is not used; it must be zero.

Return value

The return value is the new maximum number of undo actions for the rich edit control. This value may be less than wParam if memory is limited.

Remarks

By default, the maximum number of actions in the undo queue is 100. If you increase this number, there must be enough available memory to accommodate the new number. For better performance, set the limit to the smallest possible value.

Setting the limit to zero disables the Undo feature.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top