I want to add a hotkey and bind a task list to it. I can use bit flags 1, 2, 4, 8, 16 to associate each task with it, but I don't have the priority of the task being executed. I can associate each task with a number 1, 2, 3, 4 and add the order in which the task is executed:
1.2
2.1
3.4
4.3
But at the same time I will have to make a complex ini file. Whereas before I could simply specify a number using bit flags, because of priority I need to specify the task number in the chain. Maybe I should use a double word to record the task number and position on the list.
If I use a function pointer, then functions should not have parameters, that is, I need to have a parameter structure before calling the function.
I want to make the user order tasks from the list and bind a hotkey to them.
Code: Select all
;- TOP
EnableExplicit
Define NbTask, evg, iData
NbTask = 0
;- ╔═ GUI ═╗
If OpenWindow(0, 0, 0, 340, 400, "Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TreeGadget(0, 10, 10, 180, 340)
ButtonGadget(1, 200, 10, 120, 27, "Select a word")
ButtonGadget(2, 200, 40, 120, 27, "Select line")
ButtonGadget(3, 200, 70, 120, 27, "Lower case")
ButtonGadget(4, 200, 100, 120, 27, "Upper case")
ButtonGadget(5, 200, 130, 120, 27, "Sentence case")
ButtonGadget(6, 200, 160, 120, 27, "Capitalization")
ButtonGadget(7, 200, 190, 120, 27, "Inverting")
ButtonGadget(8, 200, 220, 120, 27, "Transliteration")
ButtonGadget(9, 10, 350, 120, 27, "Add a task")
;-┌──Loop──┐
Repeat
Select WaitWindowEvent()
;-…… Gadget Events ……
Case #PB_Event_Gadget
evg = EventGadget()
Select evg
Case 1 To 8
If Not NbTask
MessageRequester("","First add a task")
Continue
EndIf
AddGadgetItem(0, -1, GetGadgetText(evg), 0, 1)
iData = GetGadgetItemData(0 , 1)
SetGadgetItemData(0, 1 , iData | Int(Pow(2.0, evg)))
Case 9
NbTask + 1
AddGadgetItem(0, -1, "New task" + Str(NbTask), 0, 0)
Case 0
If EventType() = #PB_EventType_LeftClick
Debug GetGadgetItemData(0 , 1)
EndIf
EndSelect
Case #PB_Event_CloseWindow
CloseWindow(0)
End
EndSelect
ForEver
EndIf
Code: Select all
EnableExplicit
Define evg, evprm, thread
Structure Task
id.i
List TaskList.i()
EndStructure
Procedure Uppercase(*funk.Task)
Debug "Uppercase"
Debug *funk\id
EndProcedure
Procedure Inverting(*funk.Task)
Debug "Inverting"
Debug *funk\id
EndProcedure
Procedure SelectWord(*funk.Task)
Debug "SelectWord"
Debug *funk\id
EndProcedure
Global NewList hotkey.Task()
AddElement(hotkey())
hotkey()\id = 1001
AddElement(hotkey()\TaskList())
hotkey()\TaskList() = @SelectWord()
AddElement(hotkey()\TaskList())
hotkey()\TaskList() = @Uppercase()
AddElement(hotkey()\TaskList())
hotkey()\TaskList() = @Inverting()
If OpenWindow(0, 0, 0, 340, 400, "Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(1, 10, 10, 120, 27, "forced")
Repeat
Select WaitWindowEvent()
;-…… Gadget Events ……
Case #PB_Event_Gadget
evg = EventGadget()
Select evg
Case 1
; Case #WM_HOTKEY
; evprm = EventwParam()
evprm = 1001
ForEach hotkey()
If evprm = hotkey()\id
ForEach hotkey()\TaskList()
; Debug hotkey()\TaskList()
thread = CreateThread(hotkey()\TaskList(), hotkey())
If thread
WaitThread(thread)
Debug "done"
EndIf
Next
EndIf
Next
EndSelect
Case #PB_Event_CloseWindow
CloseWindow(0)
End
EndSelect
ForEver
EndIf