Jump to content

Continue Script with MsgBox


Recommended Posts

So I've created this script that teminates the script when you press ESC (same script as before)

HotKeySet ("{ESC}", "Terminate") 
Func Terminate()
    Exit
EndFunc

Now I tried to add a box that will tell the user that ESC stops the script,

However the script doesn't keep on going when the MsgBox is on (until I press OK).

There's any way to continue the script whitouth me having to press "OK" in the MsgBox?

I've tried the Timeout but it just closes and the window, and that is something I don't want to happen.

Here's the little code I did:

MsgBox (0, "How To Exit", "Press ESC to Terminate The Script")
HotKeySet ("{ESC}", "Terminate")
Func Terminate()
    Exit
EndFunc

Thank you :mellow:

Link to comment
Share on other sites

Hey pieeater,

What happens is that now I have to press ESC for the message to appear.

After that the script terminates.

But I want the message to appear WHILE the script is running,

so that people will know how to stop the script.

Link to comment
Share on other sites

MsgBox is a blocking function, which means that it won't continue until it's closed. Use the timeout parameter to have it close automatically after however many seconds that you want it to close. MsgBox ( flag, "title", "text" [, timeout [, hwnd]] ).

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Hey BrewManNH,

As I've said before:

"I've tried the Timeout but it just closes and the window, and that is something I don't want to happen."

Alright so I get the problem. It's a blocking function.

Is there an alternative function to popup a message box?

Link to comment
Share on other sites

Hey Hannes123,

A smart way I guess, though it's not the nicest one indeed :mellow:

The problem is It's blocking my way. I can't a spot I can place

the second script without it getting in my way of the first script.

Edited by Omga4000
Link to comment
Share on other sites

Hey BrewManNH,

As I've said before:

"I've tried the Timeout but it just closes and the window, and that is something I don't want to happen."

Alright so I get the problem. It's a blocking function.

Is there an alternative function to popup a message box?

If the code you posted in the first post is all the code you have, it will do exactly that, close after the msgbox is closed. You'll need to post an example of your code that you want to run, that isn't running correctly, otherwise there's no way to fix whatever might be happening.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Hey Hannes123,

A smart way I guess, though it's not the nicest one indeed :mellow:

Just to do some cosmetics you could do a FileInstall() so you don't need to ship two files. Or you could use a VB function. :)

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Sounds like you don't need a MsgBox but your own GUI. Something like this?

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

Opt("GUIOnEventMode", 1)
$hGUI = GUICreate("My Script", 300, 55, -1, -1, $WS_POPUPWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
HotKeySet ("{ESC}", "_Exit")
GUICtrlCreateLabel("Pressing ESCAPE will terminate the script.", 5, 20, 290, 25)
GUISetState(@SW_SHOW, $hGUI)

While 1
    Sleep(10)
WEnd

Func _Exit()
    Exit
EndFunc
Link to comment
Share on other sites

Hey BrewManNH,

Sorry for being unclear. My Fault :mellow:

Let's say for example that I want this script to run in a loop:

$cursor = MouseGetCursor ()
Select
    Case $cursor = 15
        Sleep (10000)
        MouseClick("left",976,643,1)
        Sleep (500)
    Case $cursor = 2
        MouseClick("left",976,643,1)
        Sleep (500)
EndSelect

WHILE this script is running I want a message box to appear, saying:

"Press ESC to terminate the script"

I don't want that message box to disappear until the script it terminated.

EDIT: ZacUSNYR, seems like you have done it! :)

Now the next problem is I want it to remain on top of everything.

I don't want folders or other files to go on top of that.

Is it possible?

Edited by Omga4000
Link to comment
Share on other sites

I see now, I would use ZacUSNYR's suggestion and make your own GUI instead, and put your code inside the While...Wend loop. Your Terminate() function would be outside of that loop though. This will keep a box up as long as the script is running, and still allow the script to run in the background.

EDIT: Use the $WS_EX_TOPMOST extended style setting to keep it on top of other windows.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

EDIT: Use the $WS_EX_TOPMOST extended style setting to keep it on top of other windows.

Now the next problem is I want it to remain on top of everything.

I don't want folders or other windows to go on top of the GUI window.

Is it possible?

You'll want to add that to the GUICreate

Example:

$hGUI = GUICreate("My Script", 300, 55, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOPMOST)
Link to comment
Share on other sites

This ->

Or this ->

Melba23s's solutions are just way too smart for me :mellow:

The sedond one you gave me was a pretty nice solution,

tough I still need to mess with it a little so it will work for me.

For some reason it doesn't accept "$code=0" or "$title = ""," or actually

any other statment that he gave in there.

Got any idea how to solve that?

You'll want to add that to the GUICreate

Example:

$hGUI = GUICreate("My Script", 300, 55, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOPMOST)

TopMost.. Stupid me :)

Thank you!! :)

Edited by Omga4000
Link to comment
Share on other sites

For some reason it doesn't accept "$code=0" or "$title = ""," or actually

any other statment that he gave in there.

Got any idea how to solve that?

In this case you must double escape the string.

_NoHaltMsgBox(0, "Hi", "Test """"test"""" test")

Func _NoHaltMsgBox($code=0, $title = "",$text = "" ,$timeout = 0)
    Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(' & $code & ', '''& $title & ''', '''& $text &''',' & $timeout & ')"')
EndFunc
Link to comment
Share on other sites

Manadar, May I ask why do I need to double it here?

Of course. :mellow:

_NoHaltMsgBox(0, "Hi", "Test """"test"""" test")

Makes the string:

Test ""test"" test

Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(' & $code & ', '''& $title & ''', '''& $text &''',' & $timeout & ')"')

Makes the string:

AutoIt.exe /AutoIt3ExecuteLine "MsgBox(0, 'Hi', 'Test ""test"" test', 0)"

AutoIt basically turns that in its own memory into a script that works like:

Execute("MsgBox(0, 'Hi', 'Test ""test"" test', 0)")

So the end result is a string that says:

MsgBox(0, 'Hi', 'Test "test" test', 0)

It all depends on what the line was started with (a " or a ') and then double escaping is sometimes necessary.

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