Jump to content

Count down MsgBox


Recommended Posts

  • Moderators

Here is a rough sample:

#include <GUIConstants.au3>
; == GUI generated with Koda ==
$Form1 = GUICreate("Count Down", 333, 128, 200, 125)
$Button1 = GUICtrlCreateButton("OK", 128, 80, 75, 25)
$Label = GUICtrlCreateLabel("", 128, 32, 76, 28, $SS_CENTER)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
While 1
    For $i = 10 to 1 Step -1
    GUICtrlSetData($Label, $i)  
    Sleep(500)
    Next
    GUICtrlSetData($Label, "Blast off!!!")
    Sleep(2000)
    ExitLoop
WEnd
Exit
Link to comment
Share on other sites

  • Moderators

Could have done Splash also.

While 1
    For $i = 10 to 1 Step -1
        SplashTextOn('', $i, 30, 20)
        Sleep(1000)
    Next
    ExitLoop
WEnd
SplashOff()

Edit:

Could have a bit of fun with it :lmao:

While 1
    For $i = 10 to 1 Step -1
        SplashTextOn('', $i, $i&1.5, $i&1.5)
        Sleep(1000)
    Next
    ExitLoop
WEnd
SplashOff()
Much more too! Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

a message box is still just a window like any other. you can't make a countdown on a standard message box in a single script, because execution of the script stops while the message box is active on the screen. now with autoit you do have the ability to fileinstall() in a second script, run() a compiled script etc etc, to give you the illusion of a multi-threaded approach to achieve the goal you want. here's a little example. 2 files. one just makes a message box.

Msgbox(0,"This is a Test","10")

now that script could be fileinstalled into the next script, and maybe run with an added #NoTrayIcon so that it would appear to be all one script. the other script would be:

Run("code1.exe")
WinWaitActive("This is a test")
ControlDisable("This is a test","",2)
for $x = 1 to 10
WinActivate("This is a test","")
ControlSetText("This is a test","",65535,10-$x)
Next
ControlEnable("This is a test","",2)

that will give you the result that you want, and even disable the user's ability to acknowledge the box via ok button while they watch your countdown...

Link to comment
Share on other sites

  • Moderators

a message box is still just a window like any other. you can't make a countdown on a standard message box in a single script, because execution of the script stops while the message box is active on the screen. now with autoit you do have the ability to fileinstall() in a second script, run() a compiled script etc etc, to give you the illusion of a multi-threaded approach to achieve the goal you want. here's a little example. 2 files. one just makes a message box.

Msgbox(0,"This is a Test","10")

now that script could be fileinstalled into the next script, and maybe run with an added #NoTrayIcon so that it would appear to be all one script. the other script would be:

Run("code1.exe")
WinWaitActive("This is a test")
ControlDisable("This is a test","",2)
for $x = 1 to 10
WinActivate("This is a test","")
ControlSetText("This is a test","",65535,10-$x)
Next
ControlEnable("This is a test","",2)

that will give you the result that you want, and even disable the user's ability to acknowledge the box via ok button while they watch your countdown...

If he didn't want to create more 'MsgBoxes' I doubt he'd want to create another script just to count down. ;) (My turn :lmao:)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I think he means

he wants a msgbox to come up after he clicks ok right? so he watnts 2 or more msg boxes?

here's the code for 2

pretty simple

(MsgBox 0, "TestBox", "10")
(MsgBox 0, "Testbox2", "9")
(MsgBox 0, "TestBox", "8")
(MsgBox 0, "Testbox2", "7")
(MsgBox 0, "TestBox", "6")
(MsgBox 0, "Testbox2", "5")
(MsgBox 0, "TestBox", "4")
(MsgBox 0, "Testbox2", "3")
(MsgBox 0, "TestBox", "2")
(MsgBox 0, "Testbox2", "1")

here's for infinite boxes

While1
(MsgBox 0, "TestBox", "10")
(MsgBox 0, "Testbox2", "9")
(MsgBox 0, "TestBox", "8")
(MsgBox 0, "Testbox2", "7")
(MsgBox 0, "TestBox", "6")
(MsgBox 0, "Testbox2", "5")
(MsgBox 0, "TestBox", "4")
(MsgBox 0, "Testbox2", "3")
(MsgBox 0, "TestBox", "2")
(MsgBox 0, "Testbox2", "1")
WEnd

is this what u mean?

Edited by gunnersense
Link to comment
Share on other sites

  • 12 years later...

MsgBox(4096, "Title", "10", 1)
MsgBox(4096, "Title", "9", 1)
MsgBox(4096, "Title", "8", 1)
MsgBox(4096, "Title", "7", 1)
MsgBox(4096, "Title", "6", 1)
MsgBox(4096, "Title", "5", 1)
MsgBox(4096, "Title", "4", 1)
MsgBox(4096, "Title", "3", 1)
MsgBox(4096, "Title", "2", 1)
MsgBox(4096, "Title", "1", 1)
MsgBox(4096, "Title", "0", 1)
 

Link to comment
Share on other sites

  • Moderators

Ahihi,

Quote

If the countdown from 10 to 0 can be put on the "Cancel"  button or "OK" button of Msgbox ?

My ExtMsgBox UDF (the link is in my sig) can run a countdown for you - run "Test 6" in Example 1 in the zip.

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

; open a detached MsgBox and get handle
$hwMSG = _MsgBox(0, "Hello", "Content", 5) ; auto close in 5 seconds

; get handle of the text label
$hMSGtext = ControlGetHandle($hwMSG, "", "[CLASS:Static; INSTANCE:1]")
; get handle of the OK button
$hButton = ControlGetHandle($hwMSG, "", "[CLASS:Button; INSTANCE:1]")

$countdown = 4
While WinExists($hwMSG) ; wait the autoclose of the MsgBox
    ; change the text in the MsgBox
    ControlSetText($hwMSG, '', $hMSGtext, "Off in " & $countdown & " sec") ; label
    ControlSetText($hwMSG, '', $hButton, $countdown) ; ok button
    Sleep(1000)
    $countdown -= 1
WEnd

; spawn a detached MsgBox and returns an handle
Func _MsgBox($flag = 0, $title = '', $text = '', $timeout = 0)
    Local $sCommand = 'MsgBox(' & $flag & ', "' & $title & '", "' & $text & '", ' & $timeout & ')'
    $sCommand = '"' & StringReplace($sCommand, '"', '""') & '"'
    Local $hPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $sCommand)
    Sleep(1000)
    ; Retrieve a list of window handles. (MsgBox included)
    Local $aList = WinList(), $hwMSGBOX
    For $i = 1 To $aList[0][0]
        If WinGetProcess($aList[$i][1]) = $hPID Then
            $hwMSGBOX = $aList[$i][1]
            ExitLoop
        EndIf
    Next
    Return $hwMSGBOX
EndFunc   ;==>_MsgBox

 

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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