Jump to content

Msgbox with timout: ending process is OK is clicked or if Msgbox timesout


Akshay07
 Share

Recommended Posts

Note: Sorry for the unclear title, I just found out that I made a mistake when writing it but I can't edit it.

It should be

Msgbox with timout: ending process when OK is clicked or if Msgbox timesout

Hello all,

I am trying to do the following:

1? Start a program

2/ Create a message box with a 10 seconds time out and a OK button

3/-a OK button is clicked within 10 seconds, close the program

or

3/-b OK button is NOT clicked within 1o seconds, close the program after 10 seconds.

I tried something like this, and as you can guess, it does not work ;)

The program does not get closed when I click on OK within 10 seconds.

Run ( "C:\MyProgram.exe" )
$answer = MsgBox ( 262144, "blablabla", "blablablabla", 10)
While WinExists ( "blablabla" ) = 1
    If $answer = 0 Then
        ProcessClose ( "MyProgram.exe" )
    EndIf
WEnd
ProcessClose ( "MyProgram.exe" )

Could someone please tell me what is wrong with this script?

Edited by Akshay07
Link to comment
Share on other sites

  • Developers

Look at the helpfile for details but this might help:

$answer = MsgBox ( 262144, "blablabla", "blablablabla", 10)
Switch $answer 
    Case -1 
    ; time out
    Case 6
    ; Yes
    Case 7
    ; No
EndSelect

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

Akshay07,

As you have only an OK button, all you need to do is check for the timeout:

Run ( "C:\MyProgram.exe" )
If MsgBox ( 262144, "blablabla", "blablablabla", 10) = -1 Then Sleep(10000) ; Time out so wait 10 secs
ProcessClose ( "MyProgram.exe" )

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

Look at the helpfile for details but this might help:

$answer = MsgBox ( 262144, "blablabla", "blablablabla", 10)
Switch $answer 
    Case -1 
    ; time out
    Case 6
    ; Yes
    Case 7
    ; No
EndSelect

Thanks for your quick answer.

I did look at the help file for Msgbox before posting (I try to not bother you guys for nothing whenever possible ;))

I guess you meant "Select" instead of "switch" ?

I tried this (I have only a OK button in my msgbox

While WinExists ( "blablabla" ) = 1
    Select
        Case $answer = -1  ; Timeout
            ProcessClose ( "MyProgram.exe" )
        Case $answer = 0   ; OK is clicked
            ProcessClose ( "MyProgram.exe" )
    EndSelect
WEnd

But it is still not working.

Edited by Akshay07
Link to comment
Share on other sites

Akshay07,

As you have only an OK button, all you need to do is check for the timeout:

Run ( "C:\MyProgram.exe" )
If MsgBox ( 262144, "blablabla", "blablablabla", 10) = -1 Then Sleep(10000) ; Time out so wait 10 secs
ProcessClose ( "MyProgram.exe" )

M23

Thanks.

But what I want to do is to close the program as soon as OK is clicked, without having to wait for the timeout.

The reason for this is that MyProgram.exe is playing a sound non-stop. So if the user clicks OK, the sound has to stop (therefore, MyProgram.exe has to stop)

Edited by Akshay07
Link to comment
Share on other sites

  • Developers

No I meant Switch, only made a typo with the EndSwitch.

$answer = MsgBox ( 262144, "blablabla", "blablablabla", 10)
Switch $answer
    Case -1
        ; time out
    Case 1
        ; Ok
    Case 6
        ; Yes
    Case 7
        ; Yes
EndSwitch

Try it and get rid of that While loop you posted again. ;)

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

No I meant Switch, only made a typo with the EndSwitch.

$answer = MsgBox ( 262144, "blablabla", "blablablabla", 10)
Switch $answer
    Case -1
        ; time out
    Case 1
        ; Ok
    Case 6
        ; Yes
    Case 7
        ; Yes
EndSwitch

Try it and get rid of that While loop you posted again. ;)

Still not working :evil:

$answer = MsgBox ( 262144, "blablabla", "blablablabla", 10)
Switch $answer
    Case -1
        ProcessClose ( "MyProgram.exe" )
    Case 0
        ProcessClose ( "MyProgram.exe" )
EndSwitch

$answer can only be -1 or 0 as I have only a OK button

Edited by Akshay07
Link to comment
Share on other sites

  • Developers

ok button returns a 1 as shown in my example!

..and it help to be specific as to what isn't working.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

@Akshay07

0 is decimal flag for OK button, its not return value, your looking on the wrong line (Remarks) in help file (try Return Value part not remarks)

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

I am an idiot ;)

bogQ, you are completely right. I mixed up two things from the help:

The flag parameter can be a combination of the following values:

decimal flag

0

Button-related

OK button

And

Button Pressed

OK

Return value

1

Jos, your proposal works like a charm.

I apologize for wasting the time of all of those who took the time to answer this message. I will try to be more careful in the future. I was so sure that "0" was the right value that I completely missed that (I am a beginner but it is not at all my first Msgbox).

Edited by Akshay07
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...