07-30-2021, 07:31 PM
How can I stop/pause/continue the below dialog?
When "START REMOVE" is clicked each item from the listbox is automatically removed from top to bottom.
For that to happen subfunction "remove_item_and_process" is called.
I want to: stop and pause/continue.
"pause/continue" is toggle based, meaning press "pause/continue" it pauses, click button again and it continues.
I found on the forum a way to end (stop) a subfunction but I couldn't get it to work.
And I do not know how to approach the "pause/continue"
The only method I can think of is using global variables, what I mean is when "STOP" is pressed the global variable is set to a certian value.
I then use this in the subfunction to check for. I might also be able to use this for the "PAUSE/CONTINUE"(?)
The downside is, is that have to check for that value after every command.
I hope a better more efficient method exists?
Function ListDialogRotate2
When "START REMOVE" is clicked each item from the listbox is automatically removed from top to bottom.
For that to happen subfunction "remove_item_and_process" is called.
I want to: stop and pause/continue.
"pause/continue" is toggle based, meaning press "pause/continue" it pauses, click button again and it continues.
I found on the forum a way to end (stop) a subfunction but I couldn't get it to work.
And I do not know how to approach the "pause/continue"
The only method I can think of is using global variables, what I mean is when "STOP" is pressed the global variable is set to a certian value.
I then use this in the subfunction to check for. I might also be able to use this for the "PAUSE/CONTINUE"(?)
The downside is, is that have to check for that value after every command.
I hope a better more efficient method exists?
Function ListDialogRotate2
str- appname;appname="ListDialog Rotator"
str- lb_items=
;item 1
;item 2
;item 3
;item 4
;item 5
;item 6
;item 7
str dd=
F
;BEGIN DIALOG
;0 "" 0x90CC0AC8 0x0 0 0 298 136 "{appname}" "4"
;3 ListBox 0x54230901 0x200 0 0 296 114 ""
;21 Button 0x54032000 0x0 5 120 78 14 "START REMOVE" "From top, start removing items one by one[][SHIFT] + left click = starts from BOTTOM"
;23 Button 0x54032000 0x4 95 120 32 14 "REFILL"
;4 Button 0x54032000 0x0 135 120 48 14 "stop"
;5 Button 0x54032000 0x0 195 120 72 14 "pause/continue"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""
str controls = "3"
str lb3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,,double- demo_wait_time;demo_wait_time=1
,,str- lb_items
,,sub.fill_lb(hDlg 3 lb_items)
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 21 ;; START REMOVING ITEMS FROM LISTBOX
,,mac "sub.remove_item_and_process" "" id(3 hDlg) demo_wait_time
,
,case 23 ;; REFILL THE LISTBOX
,,sub.fill_lb(hDlg 3 lb_items)
,
,case 4 ;; STOP (this does not work)
,,int- hThread;hThread=mac("sub.remove_item_and_process" "" hDlg)
,,EndThread("" hThread)
,,outt "Stopped?"
,case 5 ;; PAUSE/CONTINUE: ???
,,outt F"pause/continue clicked..."
ret 1
#sub remove_item_and_process
function cid double'demo_wait_time
int amount i
amount=LB_GetCount(cid)
if(amount=0)
,mes(F"No content to process" F"test" "!")
,ret
rep amount
,LB_GetItemText(cid 0 _s)
,LB_SelectItem(cid 0 1)
,outt F"PROCESSING, {_s}, {i} -> ({i} index listbox content)"
,wait demo_wait_time
,SendMessage(cid LB_DELETESTRING 0 0)
,outt F"PROCESSED, REMOVED: {_s}, {i} -> ({i} index listbox content)"
,out "-"
,i=i+1
mes(F"Finished[]No more content to process" F"test" "i")
#sub fill_lb
function int'hDlg int'lb_id str'lb_items
SendMessage(id(lb_id hDlg) LB_RESETCONTENT 0 0) ;; clear first then refill
int cnt
foreach _s lb_items
,LB_Add id(lb_id hDlg) _s cnt
,cnt=cnt+1