Jump to content

Count down MsgBox


gbetsis
 Share

Recommended Posts

Here is my solution:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("You have to reboot", 362, 128, 192, 124, BitOR($WS_SYSMENU,$WS_POPUP,$WS_BORDER,$WS_CAPTION))
$Label1 = GUICtrlCreateLabel("You have to Reboot your machine now for changes to take effect.", 16, 32, 327, 17)
$Button1 = GUICtrlCreateButton("OK (10)", 64, 80, 75, 25)
$Button2 = GUICtrlCreateButton("Cancel", 200, 80, 75, 25)
GUISetState(@SW_SHOW)

Local $hTimer = TimerInit()                                  ; Begin the timer and store the handle in a variable.

While 1

   $iDiff = Int(TimerDiff($hTimer) / 1000)                   ; Stores in a variable the time difference in seconds
   GUICtrlSetData($Button1, "OK (" & (10 - $iDiff) & ")")    ; Refreshes the Button 1 caption to display the countdown
   Sleep(10)                                                 ; A small delay. You can remove this line if you want
   
   if (10 - $iDiff) <= 0 Then                                ; If Counter reaches 0 (or below)
      $nMsg = $Button1                                       ; Then the default action is the Button1
   Else                                                      ; Else
      $nMsg = GUIGetMsg()                                    ; The action is whatever the user clicked
   EndIf
   
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
      Case $Button1
         Exit
   EndSwitch

WEnd

 

Link to comment
Share on other sites

  • Moderators

gbetsis,

Welcome to the AutoIt forums.

But in future please do not necro-post in 11 year old threads. The language has changed so much that you are better off starting a new thread - as I have now done for you.

And your solution is not complete - what happens if you press $Button2? Perhaps something like this is better:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

$fReboot = True

$Form1 = GUICreate("You have to reboot", 362, 128, 192, 124, BitOR($WS_SYSMENU, $WS_POPUP, $WS_BORDER, $WS_CAPTION))
$Label1 = GUICtrlCreateLabel("You have to Reboot your machine now for changes to take effect.", 16, 32, 327, 17)
$Button1 = GUICtrlCreateButton("OK (10)", 64, 80, 75, 25)
$Button2 = GUICtrlCreateButton("Cancel", 200, 80, 75, 25)
GUISetState(@SW_SHOW)

$iSec = @SEC
$iCount = 10

While 1

    If @SEC <> $iSec Then
        $iSec = @SEC
        $iCount -= 1
        If Not $iCount Then
            ExitLoop ; Exit if counter reaches 0
        EndIf
        GUICtrlSetData($Button1, "OK (" & ($iCount) & ")") ; Refreshes the Button 1 caption to display the countdown
        ;Sleep(10)                                              ; Not needed with a GUIGetMsg in the loop
    EndIf

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Button1
            ExitLoop
        Case $Button2
            $fReboot = False
            ExitLoop
    EndSwitch

WEnd

GUIDelete($Form1)

If $fReboot Then
    MsgBox($MB_SYSTEMMODAL, "Warning", "Rebooting")
Else
    MsgBox($MB_SYSTEMMODAL, "Cancel", "You have cancelled the reboot")
EndIf

And personally I would use my ExtMsgBox UDF - the link is in my sig - as it does all the hard work for you. Try Example 1 - Test 6 to see what I mean.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...