Jump to content
sumone4life

Count down MsgBox

Recommended Posts

sumone4life

is there any way to make a message box refresh and display somthing else. I know i can do it by closing the Msgbox and then opening a new one but is there a way to refresh it. Im trying to make a countdown kind of thing.

Share this post


Link to post
Share on other sites
big_daddy

You could build a GUI and update a label.

Share this post


Link to post
Share on other sites
sumone4life

Any simplier way? I dont really need a GUI at this point maybe in the future though.

Share this post


Link to post
Share on other sites
theguy0000

nope, sorry. A message box is the way it is as far as I know. There's no way to update it AFAIK.


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites
big_daddy

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

Share this post


Link to post
Share on other sites
sumone4life

Thanks

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
giantsquid

You could also use WinSetTitle to change the title of the msgbox, but this is a bit clumsy.

Share this post


Link to post
Share on other sites
seandisanti

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

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
gunnersense

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

Share this post


Link to post
Share on other sites
Ahihi

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)
 

Share this post


Link to post
Share on other sites
Subz

@Ahihi Why resurrect a 13 year old post?  If you are going to increment or de-increment it would be better to just use a loop

For $i = 10 To 0 Step - 1
    MsgBox(4096, "Title", $i, 1)
Next

 

  • Like 1

Share this post


Link to post
Share on other sites
Ahihi

yeah right, thanks. I just find google msgbox countdown and auto close, so I go to here. And I find out a solution for his post for someone come here after me find solution like this

Share this post


Link to post
Share on other sites
mikell

Anyway as mentioned before in this kind of situation a SplashTextOn is much more clean and classy  B)

Edited by mikell
... and it is still true 13 years later
  • Like 1
  • Haha 1

Share this post


Link to post
Share on other sites
Ahihi

Ok sir, I even haven't known splashtexton yet. I'm newbie. But I lvoe u :)) 

Share this post


Link to post
Share on other sites
Ahihi

THank all, but I still have a question. If the countdown from 10 to 0 can be put on the "Cancel"  button or "OK" button of Msgbox ? Like many msgbox normal they use I see before ?

Share this post


Link to post
Share on other sites
Subz

Look at MsgBox in help file, you'll notice constants $MB_DEFBUTTON1...

Share this post


Link to post
Share on other sites
Melba23

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

 

Share this post


Link to post
Share on other sites
Chimp
; 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

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

Share this post


Link to post
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

×