Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Button1 = 500
IDC_Button2
IDC_Button3
IDC_Button4
IDC_Button5
IDC_Button6
IDC_Undo
IDC_Redo
IDC_Text
End Enum
Global hDlg As Dword, Pressed, UndoData() As String, UndoPos, MaxUndoPos As Long
Function PBMain() As Long
Dialog New Pixels, 0, "Undo Example",300,300,350,100, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button1,"1", 10,10,20,20
Control Add Button, hDlg, %IDC_Button2,"2", 40,10,20,20
Control Add Button, hDlg, %IDC_Button3,"3", 70,10,20,20
Control Add Button, hDlg, %IDC_Button4,"4", 100,10,20,20
Control Add Button, hDlg, %IDC_Button5,"5", 130,10,20,20
Control Add Button, hDlg, %IDC_Button6,"6", 160,10,20,20
Control Add Button, hDlg, %IDC_Undo,"Undo", 220,10,50,20
Control Add Button, hDlg, %IDC_Redo,"Redo", 280,10,50,20
Control Add TextBox, hDlg, %IDC_Text, "", 20,40,310,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
ReDim UndoData(20)
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button1 : Pressed = "1" : SetUndoData : DrawHistory
Case %IDC_Button2 : Pressed = "2" : SetUndoData : DrawHistory
Case %IDC_Button3 : Pressed = "3" : SetUndoData : DrawHistory
Case %IDC_Button4 : Pressed = "4" : SetUndoData : DrawHistory
Case %IDC_Button5 : Pressed = "5" : SetUndoData : DrawHistory
Case %IDC_Button6 : Pressed = "6" : SetUndoData : DrawHistory
Case %IDC_Undo : Undo : DrawHistory
Case %IDC_Redo : Redo : DrawHistory
End Select
End Select
End Function
Sub Redo
If UndoPos >= MaxUndoPos Then Beep : Exit Sub
Incr UndoPos
Pressed = UndoData(UndoPos)
End Sub
Sub Undo
If UndoPos <= 1 Then Beep : Exit Sub
Decr UndoPos
Pressed = UndoData(UndoPos)
End Sub
Sub DrawHistory
Local i As Long, temp$
For i = 0 To UndoPos
temp$ = temp$ + UndoData(i)
Next i
Control Set Text hDlg, %IDC_Text, temp$
End Sub
Sub SetUndoData
Incr UndoPos
If UndoPos = UBound(UndoData) Then Array Delete UndoData(0)
MaxUndoPos = UndoPos
UndoData(UndoPos) = Pressed
End Sub
'gbs_01211
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm