gbetsis Posted January 14, 2017 Posted January 14, 2017 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
Moderators Melba23 Posted January 14, 2017 Moderators Posted January 14, 2017 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: expandcollapse popup#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 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
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