Code below provides the following functionality:
- Undo a textbox
- Determine whether a textbox can be undone
- Empty undo buffer, thereby disabling the undo functionality
- Create a new standard project
- Add 1 textbox and 3 command buttons.
- Set the Caption of the first command button to Undo
- Set the Caption of the second command button to Empty Undo Buffer
- Set the Caption of the third command button to Can be undone?
| Add the following to a Form |
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 Const EM_CANUNDO = &HC6
Private Const EM_EMPTYUNDOBUFFER = &HCD
Private Const EM_UNDO = &HC7
Private Sub Command1_Click()
SendMessage Text1.hwnd, EM_UNDO, 0&, 0&
End Sub
Private Sub Command2_Click()
SendMessage Text1.hwnd, EM_EMPTYUNDOBUFFER, 0&, 0&
End Sub
Private Sub Command3_Click()
Dim retcode As Long
retcode = SendMessage(Text1.hwnd, EM_CANUNDO, 0&, 0&)
If retcode Then
MsgBox "The text box can be UNDOne"
Else
MsgBox "The text box cannot be UNDOne"
End If
End Sub
Run the project, type something into the text box and test out various functions.