Jump to content

Create cancel button


nwbyy
 Share

Recommended Posts

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.

 

#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 comment
Share on other sites

#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 my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...