nwbyy 1 Posted April 11, 2021 Share Posted April 11, 2021 Hi. I created a quick shutdown button on my (windows) task bar. Sometimes it happened that I clicked on it accidentally. Quite frustrating when I loose my work... Decided to create a better shutdown button. Shutdown after a 5 second countdown with a cancel button. I found an example on this forum I adapted to my needs but I don't get the cancel (annuler) button to work. expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Global $SS_CENTER, $_CompteArebour = 6000, $_Seconds $_GuiCountDown = GUICreate ( "Arrêt dans...", 450, 200, @DesktopWidth/2 -250, @DesktopHeight/2 -100, $WS_EX_TOPMOST ) $TimeLabel = GUICtrlCreateLabel ( "", 35, -10, 480, 180, $SS_CENTER ) GUICtrlSetFont ( -1, 125, 800 ) GUISetState ( ) WinSetOnTop ( $_GuiCountDown, "", 1 ) $TimeTicks = TimerInit ( ) Local $idButton_Close = GUICtrlCreateButton("Annuler", 270, 20, 130, 130) While 1 _Check ( ) Sleep ( 200 ) WEnd Func _Check ( ) $_CompteArebour -= TimerDiff ( $TimeTicks ) $TimeTicks = TimerInit ( ) Local $_MinCalc = Int ( $_CompteArebour / ( 60 * 1000 ) ), $_SecCalc = $_CompteArebour - ( $_MinCalc * 60 * 1000 ) $_SecCalc = Int ( $_SecCalc / 1000 ) If $_MinCalc <= 0 And $_SecCalc <= 0 Then ; $iPID = Run("shutdown -s -t 0") Exit Else If $_SecCalc <> $_Seconds Then $_Seconds = $_SecCalc GUICtrlSetData ( $TimeLabel, StringFormat ( "%02u", $_Seconds ) ) If $_Seconds <= 10 Then GUISetBkColor ( 0x1e366d, $_GuiCountDown ) EndIf EndIf EndIf EndFunc ;==> _Check ( ) Button is created but I can't get the following line to work: Case $idButton_Close Exit Thanks for your help Link to post Share on other sites
argumentum 960 Posted April 11, 2021 Share Posted April 11, 2021 expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Global $SS_CENTER, $_CompteArebour = 6000, $_Seconds ; https://www.autoitscript.com/forum/topic/205606-create-cancel-button/ $_GuiCountDown = GUICreate ( "Arrêt dans...", 450, 200, @DesktopWidth/2 -250, @DesktopHeight/2 -100, $WS_EX_TOPMOST ) $TimeLabel = GUICtrlCreateLabel ( "", 35, -10, 180, 180, $SS_CENTER ) GUICtrlSetFont ( -1, 125, 800 ) GUISetBkColor ( 0x1e366d, $_GuiCountDown ) GUISetState ( ) WinSetOnTop ( $_GuiCountDown, "", 1 ) $TimeTicks = TimerInit ( ) Opt("GUIOnEventMode", 1) Global $idButton_Close = GUICtrlCreateButton("Annuler", 270, 20, 130, 130) GUICtrlSetState($idButton_Close, 2048); $GUI_ONTOP (2048) GUICtrlSetOnEvent($idButton_Close, "On_idButton_Close_Click") Func On_idButton_Close_Click() GUIDelete() Exit 6 EndFunc While 1 _Check ( ) Sleep ( 200 ) WEnd Func _Check ( ) $_CompteArebour -= TimerDiff ( $TimeTicks ) $TimeTicks = TimerInit ( ) Local $_MinCalc = Int ( $_CompteArebour / ( 60 * 1000 ) ), $_SecCalc = $_CompteArebour - ( $_MinCalc * 60 * 1000 ) $_SecCalc = Int ( $_SecCalc / 1000 ) If $_MinCalc <= 0 And $_SecCalc <= 0 Then ; $iPID = Run("shutdown -s -t 0") Exit 5 Else If $_SecCalc <> $_Seconds Then $_Seconds = $_SecCalc GUICtrlSetData($TimeLabel, StringFormat ( "%02u", $_Seconds ) ) EndIf EndIf EndFunc ;==> _Check ( ) ...it happens Follow the link to see my signature's stuff.FAQ - Please Read Before Posting. Link to post Share on other sites
Zedna 377 Posted April 11, 2021 Share Posted April 11, 2021 In your original code there is missing GUIGetMsg() in main loop, something like this: While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $idButton_Close Exit EndSwitch _Check ( ) ;~ Sleep ( 200 ) WEnd Resources UDF ResourcesEx UDF AutoIt Forum Search Link to post Share on other sites
nwbyy 1 Posted April 12, 2021 Author Share Posted April 12, 2021 Thank you very much! I tried again to fix my own code with no success so far. Shame on me 🙂 I will take the easy way this time and use argumentum's code. Works perfectly. argumentum 1 Link to post Share on other sites
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