I need an unlimited undo/redo code for my app...
i've found a code for RichTextBoxes but it didnt support
pictureboxes so i relly need som help with this!
Private Function TranslateUndoType(ByVal eType As ERECUndoTypeConstants) As String
Select Case eType
Case ercUID_UNKNOWN
TranslateUndoType = "Last Action"
Case ercUID_TYPING
TranslateUndoType = "Typing"
Case ercUID_PASTE
TranslateUndoType = "Paste"
Case ercUID_DRAGDROP
TranslateUndoType = "Drag Drop"
Case ercUID_DELETE
TranslateUndoType = "Delete"
Case ercUID_CUT
TranslateUndoType = "Cut"
End Select
End Function
' Then, add this code to a module
'// View Types
Public Enum ERECViewModes
ercDefault = 0
ercWordWrap = 1
ercWYSIWYG = 2
End Enum
'// Undo Types
Public Enum ERECUndoTypeConstants
ercUID_UNKNOWN = 0
ercUID_TYPING = 1
ercUID_DELETE = 2
ercUID_DRAGDROP = 3
ercUID_CUT = 4
ercUID_PASTE = 5
End Enum
'// Text Modes
Public Enum TextMode
TM_PLAINTEXT = 1
TM_RICHTEXT = 2 ' /* default behavior */
TM_SINGLELEVELUNDO = 4
TM_MULTILEVELUNDO = 8 ' /* default behavior */
TM_SINGLECODEPAGE = 16
TM_MULTICODEPAGE = 32 ' /* default behavior */
End Enum
Public Const EM_SETTEXTMODE = (WM_USER + 89)
Public Const EM_UNDO = &HC7
Public Const EM_REDO = (WM_USER + 84)
Public Const EM_CANPASTE = (WM_USER + 50)
Public Const EM_CANUNDO = &HC6&
Public Const EM_CANREDO = (WM_USER + 85)
Public Const EM_GETUNDONAME = (WM_USER + 86)
Public Const EM_GETREDONAME = (WM_USER + 87)
Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
Posts
1,152
im guessing it isnt declared in that code
Public Const WM_USER = &H400
:::`DISCLAIMER`:::
Do NOT take anything i have posted to be truthful in any way, shape or form.
Thank You!
-------------------------------- "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe "Finaly I can look as gay as I want..." - NoteMe
Languages: VB6, BASIC, Java, C#. C++
with this code there are several things that are not defined.. you have to google the constants to get the values
anyway, i setup a demo project, and the identification of the kind of undo works ie Undo Typing, BUT it still behaves the same. that is, it acts just as if there was only 1 level of undo. pressing undo just toggles back and forth between the last action being there or not.
if someone could get this working that would be great
Oops. I hunted for quite a while, too. No idea. I'll see if i can find it in my history. It says this guy started the site. Still haven't tried it, but over 10K persons downloaded it.
I have attached the demo I was using, just so people don't keep having to create it from the code above.
The reason why this code doesn't work, and only seems to give you a single level undo, is because it's text mode is set to that.
In form load the code is:
Code:
Private Sub Form_Load()
Dim lStyle As Long
lStyle = TM_RICHTEXT Or TM_MULTILEVELUNDO Or TM_MULTICODEPAGE
SendMessageLong rtfText.hwnd, EM_SETTEXTMODE, lStyle, 0
End Sub
This should set the mode to multi level undo.
But what actually happens is that it doesn't get set.
I changed the above code to:
Code:
Private Sub Form_Load()
Dim lStyle As Long
lStyle = TM_RICHTEXT Or TM_MULTILEVELUNDO Or TM_MULTICODEPAGE
MsgBox "Style to be set: " & lStyle
SendMessageLong rtfText.hwnd, EM_SETTEXTMODE, lStyle, 0
MsgBox "Style after change: " & SendMessage(rtfText.hwnd, EM_GETTEXTMODE, 0&, 0&)
End Sub
and added the following to the module:
Code:
public Const EM_GETTEXTMODE = (WM_USER + 90)
What we actually see is that lStyle = 42, which is what we want. However, when we read back the style it's only got a value of 38
This means it's style is:
Code:
lStyle = TM_RICHTEXT Or TM_SINGLELEVELUNDO Or TM_MULTICODEPAGE
So, I can think of only 2 reasons why this doesn't work. The SendMessageLong command is wrong (I have tried to use SendMessage but that fails too), or it doesn't actually support this...
I didn't write it, just found it, tested, and posted the link to it (above)
I agree that it could be improved, but in actuality, you are deleting one letter at at time, so it's right. I didn't paste but it un-did pasting, and then deleting a picture.
The EM_SETTEXTMODE message is only supported in RichEdit 2.0 and above, however the VB RichTextBox is based on RichEdit 1.0. VBAccelerator used to have a RichTextBox control that was created purely from API which supported this. It is still available but only as part of some of the downloadable tools.
That makes sense. I ran across the RichEdit control from vbAccelerator, but whenever I try to run it I get different errors. I think I have all the type libraries and such registered that I need to. I will start a new thread about it when I get home.