VB5, VB6Implement Undo, Redo, and Save Point Functionality
Option Explicit

Const EM_EMPTYUNDOBUFFER = 205
Const EM_CANUNDO = 198
Const EM_GETMODIFY = 184
Const EM_SETMODIFY = 185
Const EM_UNDO = 199

Const EM_CANPASTE = 1074
Const EM_FINDTEXT = 1080

Const EM_GETFIRSTVISIBLELINE = 206
Const EM_GETLINECOUNT = 186
Const EM_GETLINE = 196
Const EM_LINEFROMCHAR = 201
Const EM_LINEINDEX = 187

Const EM_EXLINEFROMCHAR = 1078 '(>64k text)
Const EM_LINESCROLL = 182
Const EM_SCROLLCARET = 183
Const EM_SETTABSTOPS = 203

Private Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _
   Long, ByVal wParam As Long, lParam As Any) As _
   Long

Private Sub Command1_Click()
   ' make control undo edits
   SendMessage Text1.hwnd, EM_UNDO, 0, 0
End Sub

Private Sub Command2_Click()
   ' make the controls current text
   ' be its undo text
   SendMessage Text1.hwnd, EM_EMPTYUNDOBUFFER, 0, 0
End Sub

Private Sub Command3_Click()
   MsgBox IIf(Changed(Text1), "Yes!", "No.")
End Sub

Private Sub Command5_Click()
   ' mark text1 as changed
   SendMessage ctlTextBox.hwnd, EM_SETMODIFY, 1, 0
End Sub

Private Sub Form_Load()
   Show
End Sub

Public Function Changed(ByVal ctlTextBox As _ 
   TextBox)    As Boolean
   ' return state of edit flag
   Changed = _
      SendMessage(ctlTextBox.hwnd, EM_GETMODIFY, 0, _
      0) <> 0
End Function

Private Sub Command4_Click()
   MsgBox IIf(SendMessage(Text1.hwnd, EM_CANUNDO, 0, _ 
   0)        <> 0, "Yes!", "No.")
End Sub

Public Sub SaveData()
   Dim iTextBoxCount As Integer
   For iTextBoxCount = 0 To Controls.Count - 1
      If TypeOf Controls(iTextBoxCount) Is TextBox _
         Then
         If Changed(Controls(iTextBoxCount)) Then
            ' save data
         End If
      End If
   Next
End Sub
Listing 1 This code implements sophisticated functionality with a minimum of code. The code in this listing uses SendMessage to implement undo, redo, and save point functionality. Also included are functions to control, query, set, and clear the changed state of a VB textbox.