Allow2010 Posted April 21, 2015 Posted April 21, 2015 Hello, i have a script similar to this example: HotKeySet("{ESC}", "Terminate") While True ConsoleWrite("Running" & @CRLF) Sleep(500) WEnd Func Terminate() ConsoleWrite("Waiting" & @CRLF) $result = MsgBox(262148, "Exit?", "Are you sure you want to exit?") If $result = 6 Then Exit 0 EndIf EndFunc ;==>Terminate When i press esc it will ask me if i really want to exit. As MsgBox is a blocking function, the whole script will pause until i answer the messagebox. So my question is: Is there a way to make sure the main script continues even while the question is unanswered?
computergroove Posted April 21, 2015 Posted April 21, 2015 Instead of msgbox why don't you use guicreate? Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
Allow2010 Posted April 21, 2015 Author Posted April 21, 2015 unsure if this can help...a loop for the guimsg would block also...mayb i can try with eventmode...
computergroove Posted April 21, 2015 Posted April 21, 2015 You can display a gui and still have your script running in the background. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
caramen Posted April 21, 2015 Posted April 21, 2015 1) Gui create 2) Gui set stat 2A) SW_HIDE 2B) SW_SHOW 3) Condition My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
Allow2010 Posted April 21, 2015 Author Posted April 21, 2015 (edited) expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $askexit = 1 ;set to 0 to exit without question global $idno, $idexit,$msgboxgui $title = "Exit?" $text = "Are you sure you want to exit?" $msgboxgui = GUICreate($title, 100, 100, -1, -1, -1, $WS_EX_TOPMOST) GUICtrlCreateLabel($text, 10, 10) $idno = GUICtrlCreateButton("No", 50, 50) $idexit = GUICtrlCreateButton("exit", 10, 50) HotKeySet("{ESC}", "Terminate") While True ConsoleWrite("Running" & @CRLF) Sleep(50) Switch GUIGetMsg() Case $idno GUISetState(@SW_HIDE, $msgboxgui) Case $idexit leave() EndSwitch WEnd Func leave() ;some more cleanup commands... Exit 0 EndFunc ;==>leave Func askexit() ; Display the GUI. GUISetState(@SW_SHOW, $msgboxgui) EndFunc ;==>askexit Func Terminate() If $askexit = 1 Then askexit() Else leave() EndIf EndFunc ;==>Terminate it works, but it is a bit unresponsive because of the sleep...as i need to sleep in my script i will have to find some workaround... Edited April 21, 2015 by Allow2010
Allow2010 Posted April 21, 2015 Author Posted April 21, 2015 (edited) expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Timers.au3> $askexit = 1 ;set to 0 to exit without question Global $idno, $idexit, $msgboxgui $title = "Exit?" $text = "Are you sure you want to exit?" $msgboxgui = GUICreate($title, 200, 100, -1, -1, -1, $WS_EX_TOPMOST) GUICtrlCreateLabel($text, 10, 10) $idno = GUICtrlCreateButton("No", 50, 50) $idexit = GUICtrlCreateButton("exit", 10, 50) ;GUISetState(@SW_SHOW, $msgboxgui) HotKeySet("{ESC}", "Terminate") $timer = _Timer_SetTimer($msgboxgui, 50, "runner") While True Switch GUIGetMsg() Case $idno, $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $msgboxgui) Case $idexit leave() EndSwitch WEnd Func runner($hWnd, $iMsg, $iIDTimer, $iTime) ConsoleWrite("Running" & @CRLF) EndFunc ;==>runner Func leave() ;some more cleanup commands... _Timer_KillTimer($msgboxgui, $timer) Exit 0 EndFunc ;==>leave Func Terminate() If $askexit = 1 Then GUISetState(@SW_SHOW, $msgboxgui) Else leave() EndIf EndFunc ;==>Terminate this one works OK, just in case someone needs something like this... Edited April 21, 2015 by Allow2010
jguinch Posted April 21, 2015 Posted April 21, 2015 You can also use AdlibRegister instead of a timer : expandcollapse popup#Include <GUIConstantsEx.au3> #Include <WindowsConstants.au3> Global $hExitDialog, $id_ExitYes, $id_ExitNo HotKeySet("{ESC}", "Terminate") _ExitDialog() AdlibRegister("_AdlibRunner", 500) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE, $id_ExitNo GUISetState(@SW_HIDE, $hExitDialog) Case $id_ExitYes Exit EndSwitch WEnd Func _AdlibRunner() ConsoleWrite("Running" & @CRLF) EndFunc Func Terminate() GUISetState(@SW_SHOW, $hExitDialog) EndFunc Func _ExitDialog() $hExitDialog = GUICreate("Exit?", 242, 144, -1, -1, $WS_SYSMENU ) GUISetFont(10, 400, 0, "Calibri") GUICtrlCreateLabel("Are you sure you want to exit?", 12, 26) GUICtrlCreateLabel("", 0, 70, 242, 74) GUICtrlSetBkColor(-1, 0xdddddd) GUICtrlSetState(-1, $GUI_DISABLE) $id_ExitYes = GUICtrlCreateButton("Yes", 42, 80, 89, 26) $id_ExitNo = GUICtrlCreateButton("No", 140, 79, 89, 26) EndFunc Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Allow2010 Posted April 22, 2015 Author Posted April 22, 2015 ahh, good, especiall if there is no gui.-)
Allow2010 Posted April 22, 2015 Author Posted April 22, 2015 FYI: I did a few test, and for some reason unknown, my script is less responsive when using AdlibRegister . Not sure if there is a technical reason that would explain it. I used the same timing and code, just repleced the functions. Using Adlib register i sometimes have to click severltimes on the exit button until it reacts...never hat this with settimer. So i will stay with _Timer_SetTimer for now.
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