Yirrlaar Posted September 24, 2019 Share Posted September 24, 2019 I have been having issues with the following code... If I press the Pause button it goes to the Pause Function and it switches to Resume button. When i click resume it goes to the Resume Function. The issue I am having is after I click "Run Program" and then attempt to click the any other button, it never goes into that function? What am i doing wrong, why after "Run Program" does it no longer look at the Button controls??? expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global $Start, $RunProg, $Pause, $Resume, $Stop, $Kill, $Restart Global $Resume_button = 0, $Pause_button = 0, $Restart_button = 0, $RunProg_button = 0, $Kill_button = 0, $Start_button = 0, $Stop_button = 0 guitest() While $Kill_button = 0 And $Stop_button = 0 WEnd Func guitest() Opt("GUIOnEventMode", 1) $hGUI = GUICreate("MyCommands", 443, 450, 1133, 116) $Main = GUICtrlCreateTab(8, 8, 425, 400) $MainTab = GUICtrlCreateTabItem("Main") $Start = GUICtrlCreatebutton("Load Files", 15, 38, 100, 30) $RunProg = GUICtrlCreatebutton("Run Program", 120, 38, 80, 30) $Pause = GUICtrlCreatebutton("PAUSE", 15, 73, 80, 30) $Resume = GUICtrlCreatebutton("RESUME", 15, 73, 80, 30) $Stop = GUICtrlCreatebutton("Stop", 15, 108, 80, 30) $Kill = GUICtrlCreatebutton("Stop Everything", 110, 108, 100, 30) $Restart = GUICtrlCreatebutton("Restart", 15, 143, 80, 30) GUICtrlSetState($Resume, $GUI_HIDE) GUICtrlSetState($Pause, $GUI_SHOW) GUICtrlSetOnEvent($Start, "Start") GUICtrlSetOnEvent($RunProg, "StartThis") GUICtrlSetOnEvent($Pause, "PauseThis") GUICtrlSetOnEvent($Resume, "ResumeThis") GUICtrlSetOnEvent($Stop, "STOPThis") GUICtrlSetOnEvent($Kill, "KillThis") GUICtrlSetOnEvent($Restart, "RestartThis") GUISetOnEvent($GUI_EVENT_CLOSE, "STOPThis") GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUISetState(@SW_SHOW) EndFunc ;==>guitest Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $Resume Then $Resume_button = 1 ElseIf BitAND($wParam, 0x0000FFFF) = $Pause Then $Pause_button = 1 ElseIf BitAND($wParam, 0x0000FFFF) = $Restart Then $Restart_button = 1 ElseIf BitAND($wParam, 0x0000FFFF) = $RunProg Then $RunProg_button = 1 ElseIf BitAND($wParam, 0x0000FFFF) = $Kill Then $Kill_button = 1 ElseIf BitAND($wParam, 0x0000FFFF) = $Start Then $Start_button = 1 ElseIf BitAND($wParam, 0x0000FFFF) = $Stop Then $Stop_button = 1 EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND Func Start() If $RunProg_button = 1 And $Start_button = 0 Then ConsoleWrite("Loading files" & @CRLF) ElseIf $RunProg_button = 0 And $Start_button = 1 Then ConsoleWrite("Loading files" & @CRLF) Else EndIf $RunProg_button = 0 $Start_button = 0 EndFunc ;==>Start Func STOPThis() if $Kill_button = 0 then ConsoleWrite("$Stop was pushed" & @CRLF) Exit EndFunc ;==>STOPThis Func StartThis() If $RunProg_button = 1 Then ConsoleWrite("$RunProg was pushed" & @CRLF) Start() ;makes sure files are loaded before program is loaded $RunProg_button = 0 Function_1() EndFunc ;==>StartThis Func RestartThis() ConsoleWrite("$Restart was pushed" & @CRLF) STOPThis() StartThis() EndFunc ;==>RestartThis Func KillThis() ConsoleWrite("$Kill was pushed & all windows are being closed" & @CRLF) STOPThis() EndFunc ;==>KillThis Func PauseThis() GUICtrlSetState($Resume, $GUI_SHOW) GUICtrlSetState($Pause, $GUI_HIDE) ConsoleWrite("$Pause was pushed" & @CRLF) While $Resume_button = 0 And $Stop_button = 0 And $Kill_button = 0 Sleep(100) WEnd $Resume_button = 0 $Pause_button = 0 $Stop_button = 0 $Kill_button = 0 EndFunc ;==>PauseThis Func ResumeThis() $Resume_button = 0 GUICtrlSetState($Resume, $GUI_HIDE) GUICtrlSetState($Pause, $GUI_SHOW) ConsoleWrite("$Resume was pushed" & @CRLF) Sleep(100) EndFunc ;==>ResumeThis Func Function_1() ConsoleWrite("func Function_1()" & @CRLF) Sleep(500) Function_2() EndFunc ;==>Function_1 Func Function_2() ConsoleWrite("func Function_2()" & @CRLF) Sleep(500) Function_3() EndFunc ;==>Function_2 Func Function_3() ConsoleWrite("func Function_3()" & @CRLF) Sleep(500) Function_4() EndFunc ;==>Function_3 Func Function_4() ConsoleWrite("func Function_4()" & @CRLF) Sleep(500) Function_5() EndFunc ;==>Function_4 Func Function_5() ConsoleWrite("func Function_5()" & @CRLF) Sleep(500) Function_6() EndFunc ;==>Function_5 Func Function_6() ConsoleWrite("func Function_6()" & @CRLF) Sleep(500) Function_7() EndFunc ;==>Function_6 Func Function_7() ConsoleWrite("func Function_7()" & @CRLF) Sleep(500) Function_8() EndFunc ;==>Function_7 Func Function_8() ConsoleWrite("func Function_8()" & @CRLF) Sleep(500) Function_9() EndFunc ;==>Function_8 Func Function_9() ConsoleWrite("func Function_9()" & @CRLF) Sleep(500) Function_10() EndFunc ;==>Function_9 Func Function_10() ConsoleWrite("func Function_10()" & @CRLF) Sleep(500) Function_11() EndFunc ;==>Function_10 Func Function_11() ConsoleWrite("func Function_11()" & @CRLF) Sleep(500) Function_12() EndFunc ;==>Function_11 Func Function_12() ConsoleWrite("func Function_12()" & @CRLF) Sleep(500) Function_1() ; looping back to Function_1 just be part of the example problem EndFunc ;==>Function_12 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 24, 2019 Moderators Share Posted September 24, 2019 Yirrlaar, I suggest reading the Interrupting a running function tutorial in the Wiki - it explains why this happens and how you can get round it. M23 Yirrlaar 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Yirrlaar Posted September 24, 2019 Author Share Posted September 24, 2019 2 hours ago, Melba23 said: Yirrlaar, I suggest reading the Interrupting a running function tutorial in the Wiki - it explains why this happens and how you can get round it. M23 I have read that post like 15 times previously and thought i was doing everything right!!! This round I took my time and read it word for word rather than rushing, bloody thing works like a charm now!!! expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global $Start, $RunProg, $Pause, $Resume, $Stop, $Kill, $Restart Global $Resume_button = 0, $Pause_button = 0, $RunProg_button = 0 Global $Start_prog = False guitest() While 1 If $Start_prog Then StartThis() WEnd Func guitest() Opt("GUIOnEventMode", 1) $hGUI = GUICreate("MyCommands", 443, 450, 1133, 116) $Main = GUICtrlCreateTab(8, 8, 425, 400) $MainTab = GUICtrlCreateTabItem("Main") $Start = GUICtrlCreateButton("Load Files", 15, 38, 100, 30) $RunProg = GUICtrlCreateButton("Run Program", 120, 38, 80, 30) $Pause = GUICtrlCreateButton("PAUSE", 15, 73, 80, 30) $Resume = GUICtrlCreateButton("RESUME", 15, 73, 80, 30) $Stop = GUICtrlCreateButton("Stop", 15, 108, 80, 30) $Kill = GUICtrlCreateButton("Stop Everything", 110, 108, 100, 30) $Restart = GUICtrlCreateButton("Restart", 15, 143, 80, 30) GUICtrlSetState($Resume, $GUI_HIDE) GUICtrlSetState($Pause, $GUI_SHOW) GUICtrlSetOnEvent($Start, "Start") GUICtrlSetOnEvent($RunProg, "Start_prog") GUICtrlSetOnEvent($Pause, "PauseThis") GUICtrlSetOnEvent($Resume, "ResumeThis") GUICtrlSetOnEvent($Stop, "STOPThis") GUICtrlSetOnEvent($Kill, "KillThis") GUICtrlSetOnEvent($Restart, "RestartThis") GUISetOnEvent($GUI_EVENT_CLOSE, "STOPThis") GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUISetState(@SW_SHOW) EndFunc ;==>guitest Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $Resume Then $Resume_button = 1 ElseIf BitAND($wParam, 0x0000FFFF) = $Pause Then $Pause_button = 1 ElseIf BitAND($wParam, 0x0000FFFF) = $RunProg Then $RunProg_button = 1 EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND Func Start() $RunProg_button = 0 $Start_button = 0 EndFunc ;==>Start Func STOPThis() Exit EndFunc ;==>STOPThis Func Start_prog() $Start_prog = True EndFunc ;==>Start_prog Func StartThis() If $RunProg_button = 1 Then ConsoleWrite("$RunProg was pushed" & @CRLF) Start() $RunProg_button = 0 Function_1() EndFunc ;==>StartThis Func RestartThis() ConsoleWrite("$Restart was pushed" & @CRLF) EndFunc ;==>RestartThis Func KillThis() ConsoleWrite("$Kill was pushed & all windows are being closed" & @CRLF) STOPThis() EndFunc ;==>KillThis Func PauseThis() GUICtrlSetState($Resume, $GUI_SHOW) GUICtrlSetState($Pause, $GUI_HIDE) ConsoleWrite("$Pause was pushed" & @CRLF) While $Resume_button = 0 Sleep(100) WEnd $Resume_button = 0 $Pause_button = 0 EndFunc ;==>PauseThis Func ResumeThis() $Resume_button = 0 GUICtrlSetState($Resume, $GUI_HIDE) GUICtrlSetState($Pause, $GUI_SHOW) ConsoleWrite("$Resume was pushed" & @CRLF) Sleep(100) EndFunc ;==>ResumeThis Func Function_1() ConsoleWrite("func Function_1()" & @CRLF) Sleep(500) Function_2() EndFunc ;==>Function_1 Func Function_2() ConsoleWrite("func Function_2()" & @CRLF) Sleep(500) Function_3() EndFunc ;==>Function_2 Func Function_3() ConsoleWrite("func Function_3()" & @CRLF) Sleep(500) Function_4() EndFunc ;==>Function_3 Func Function_4() ConsoleWrite("func Function_4()" & @CRLF) Sleep(500) Function_5() EndFunc ;==>Function_4 Func Function_5() ConsoleWrite("func Function_5()" & @CRLF) Sleep(500) Function_6() EndFunc ;==>Function_5 Func Function_6() ConsoleWrite("func Function_6()" & @CRLF) Sleep(500) Function_7() EndFunc ;==>Function_6 Func Function_7() ConsoleWrite("func Function_7()" & @CRLF) Sleep(500) Function_8() EndFunc ;==>Function_7 Func Function_8() ConsoleWrite("func Function_8()" & @CRLF) Sleep(500) Function_9() EndFunc ;==>Function_8 Func Function_9() ConsoleWrite("func Function_9()" & @CRLF) Sleep(500) Function_10() EndFunc ;==>Function_9 Func Function_10() ConsoleWrite("func Function_10()" & @CRLF) Sleep(500) Function_11() EndFunc ;==>Function_10 Func Function_11() ConsoleWrite("func Function_11()" & @CRLF) Sleep(500) Function_12() EndFunc ;==>Function_11 Func Function_12() ConsoleWrite("func Function_12()" & @CRLF) Sleep(500) Function_1() EndFunc ;==>Function_12 Link to comment Share on other sites More sharing options...
vincitek Posted October 16 Share Posted October 16 #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form = GUICreate("", 142, 127, 860, 475, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST)) $Button_Pausa = GUICtrlCreateButton("Stop", 42, 22, 61, 26, $BS_CENTER) GUICtrlSetFont(-1, 8, 400, 0, "Segoe UI") $Label = GUICtrlCreateLabel("Active", 44, 69, 59, 17, BitOR($SS_CENTER,$WS_BORDER)) GUICtrlSetFont(-1, 8, 400, 0, "Segoe UI") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $Paused HotKeySet("{pause}","TogglePauseHOTKEY") GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") AdlibRegister("TogglePause",200) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func TogglePause() if $Paused =1 then GUICtrlSetData($Button_Pausa,"Resume") GUICtrlSetData($Label,"Paused") While $Paused sleep(10) ; program on pause WEnd GUICtrlSetData($Button_Pausa,"Stop") GUICtrlSetData($Label,"Active") EndIf EndFunc Func TogglePauseHOTKEY() $Paused = NOT $Paused Beep(1000,20) GUICtrlSetData($Button_Pausa,"Resume") GUICtrlSetData($Label,"Paused") While $Paused sleep(10) ;program on pause WEnd GUICtrlSetData($Button_Pausa,"Stop") GUICtrlSetData($Label,"Active") EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $Button_Pausa Then Beep(1000,20) $Paused = NOT $Paused EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND exit Link to comment Share on other sites More sharing options...
Developers Jos Posted October 16 Developers Share Posted October 16 Are you posting an answer after 5 years or is there a question? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now