BabyG Posted October 21, 2005 Share Posted October 21, 2005 Hey I created a msgbox(0,"",""). When ok is clicked it returns 1, when the top right cross is clicked it returns 1, when an "End Task" is performed on it, it returns 1. But if a timeout occurs on a box it returns -1. I know that there is no specification saying "a close of the msgbox will return X" in the help, but personally I need to handle these cases and don't think 1 should be returned. What do you guys think about making the msgbox return -1, or 0 if the box is closed by the top right cross and end task? (or maybe even setting @error) I have discovered if msgbox(1,"","") is created it returns 2 (cancel) if "end task"/cross pressed. For now i will use that as I need to be able to handle reboots to the machine, and don't want the script to think ok has been clicked when windows closes the msgbox, when infact it has not. Thanx guys Link to comment Share on other sites More sharing options...
LxP Posted October 21, 2005 Share Posted October 21, 2005 I'm not sure that this would be classified as a bug. When a MsgBox() is displayed with just an OK button, it's not really being used for anything other than an information display. A click of the OK button or of the X button are essentially equivalent because of this.An 'End Task' request is equivalent to hitting the X button on the box, which is why the same result is received. However, as you would have seen, the task isn't actually ended; if the user does indeed attempt to reboot the machine then the box may be dismissed but the script will continue to run until completion (or until Windows forcefully closes it after a given timeframe with the user's permission).May I ask what you're trying to achieve with the MsgBox()? There may be a better way. Link to comment Share on other sites More sharing options...
BabyG Posted October 21, 2005 Author Share Posted October 21, 2005 Thanx for quick reply I have already writen out what I (really) do below, and thought it might be abit complicated for a msgbox bug ... so I'll write a simple version....Simple version:A script is to be run to do a few things automatically for me, in the middle of the script I wish to popup a msgbox which then allows the user to do some manual steps. So for example, the script will first install a peice of software and then after that is done a msgbox will apear. During this time the user can do anything on the computer, including reboot the machine (the script has a shortcut in the startup menu which will execute it on startup). When the computer reboots I expect (as i have seen it many times before) that the msgbox will be closed before the script and the script will continue running. I don't want the machine to think the ok button has been clicked when windows closes the msgbox.After the user click the ok button the script will continue running and for example it might uninstall the software.I want the script to look somthing like this... (hasn't been reboot tested, a second or so sleep might need to be included in the while loop)SaveToStartup( @ScriptFullPath, "", False );my function While MsgBox ( 0, "Manual Steps", "Please complete all manual steps and click ok when finished. This msgbox will be displayed again after a reboot if ok is not clicked." ) <> 1 WEnd DeleteFromStartUp( );my functionThe code I am using now because I need the cancel button is...SaveToStartup( @ScriptFullPath, "", False ) While MsgBox ( 1, "Manual Steps", "Please complete all manual steps and click ok when finished. This msgbox will be displayed again after a reboot if ok is not clicked." ) = 2 WEnd DeleteFromStartUp( )So it's not a big deal, I just think a different return value would be an improvment ...What I really do:I have a vbs which sits in the background of a given computer. This script reads from a ini file which contains all the tasks to be performed, all of which are autoitscripts. all tasks are run in order and waits for each task to complete before starting the next. This vbs script is in the startup menu and will be run everytime the computer starts up, it also gives the tasks (autoitscripts) 30seconds to start up.Now before anyone comments on wether or not the vbs file should be used, yes, yes it should, it does many other things, it's main feature if axually to reimage a pc automatically . A simple ini file might look like this......[Config]GiveProcess=30000[Default]1="\\server\AutoIt\AutoIt V1\7.3.0\Install\v0.04\Install.exe"2="\\server\AutoIt\AutoIt V1\7.3.0\Install\v0.04\Uninstall.exe"......Install is run, then uninstall is run. Everyone is happy. I want to put a program in the middle that will allow me to do a manual step (eg... run/use the software that i just installed). So the file would look like this.........[Config]GiveProcess=30000[Default]1="\\server\AutoIt\AutoIt V1\7.3.0\Install\v0.04\Install.exe"2="\\server\AutoIt\AutoIt V1\7.3.0\tools\Manual Step.exe"3="\\server\AutoIt\AutoIt V1\7.3.0\Install\v0.04\Uninstall.exe"......Manual Step.exe, I want manual step.exe (code) to look like this...#Include "\\server\AutoIt V1\7.3.0\Common Files\#functions.au3" AutoItSetOption("WinTitleMatchMode", 4) SaveToStartup( @ScriptFullPath, "", False );my function While MsgBox ( 0, "Manual Steps", "Please complete all manual steps and click ok when finished. This msgbox will be displayed again after a reboot if ok is not clicked." ) <> 1 WEnd DeleteFromStartUp( );my functionThe code I am using now because I need the cancel button is...#Include "\\server\AutoIt\AutoIt V1\7.3.0\Common Files\#functions.au3" AutoItSetOption("WinTitleMatchMode", 4) SaveToStartup( @ScriptFullPath, "", False ) While MsgBox ( 1, "Manual Steps", "Please complete all manual steps and click ok when finished. This msgbox will be displayed again after a reboot if ok is not clicked." ) = 2 WEnd DeleteFromStartUp( )So i mean it's not a big deal if this is not changed so that msgbox returns somthing different... but I thought it might be an improvment.These are 2 cases where i might like to use a msgbox box that returns different values on close.... Som1 else must want the same thing ... I cant be the only 1 can i ? Link to comment Share on other sites More sharing options...
LxP Posted October 21, 2005 Share Posted October 21, 2005 Well, this is quite a reasonable scenario and I can understand what you're wanting to do. However, the issue may be with Windows itself because AutoIt simply uses inbuilt Windows code to display message boxes and retrieve their values. This means that the MsgBox() function most likely won't be changed to accommodate your situation.If I were in your position I would ask myself: is there some sort of condition that AutoIt can detect, which would indicate that the manual steps are complete?If not, then I would go and program a custom GUI that looks like a message box, but obviously because it's a custom GUI it could perform different functionality based on whether Windows attempts to close the GUI during a reboot or whether the user clicks the button (which I suppose I would rename to something more appropriate like 'Continue'). You would also have the added benefit of being able to disable/remove the X button at the top of the dialogue. Link to comment Share on other sites More sharing options...
jpm Posted October 21, 2005 Share Posted October 21, 2005 There is nobug as stated by @LxP here so I move this topic in the support forum. Link to comment Share on other sites More sharing options...
BabyG Posted October 21, 2005 Author Share Posted October 21, 2005 Sorry.... no bug.... forgot windows was so "silly"... ----------- Thanx Yes, if the windows functions used to create the msgbox do not return an information on whether or not the window was closed or "oked" then I would not expect the code to be change for my specific situation. Ud just expect that the windows msgbox should have a specific return for "msgbox closed"... but I maybe not..... *shakes head and thinks disgusting words that discribe windows"... ... no matter, a cancel button isn't going to hurt nobody, so i'll leave the cancel button in as when the window is closed the return value is that of the cancel . MSDN messagebox - "If the function fails, the return value is zero."... is closing the msgbox classed as a fail? Ahh well no mater.... thanx ... Link to comment Share on other sites More sharing options...
LxP Posted October 21, 2005 Share Posted October 21, 2005 (edited) But a custom GUI can be made easily enough: #Include <GUIConstants.au3> Local $Continue, $Msg GUICreate('Manual Steps', 346, 86, -1, -1, BitOR($WS_CAPTION, $WS_POPUP)) GUICtrlCreateLabel("Please complete all manual steps and click 'Continue' " & _ 'when finished. Rebooting is permitted.', 12, 12, 322, 26) $Continue = GUICtrlCreateButton('Continue >>', 238, 50, 96, 24, _ $BS_DEFPUSHBUTTON) GUISetState() Do $Msg = GUIGetMsg() Until $Msg = $GUI_EVENT_CLOSE or $Msg = $Continue If $Msg = $Continue Then ; Do whatever is required when the user presses Continue MsgBox(0x40, 'Manual Steps', 'You clicked Continue.') Else ; Do whatever is required when the box is otherwise closed MsgBox(0x40, 'Manual Steps', 'The box is being closed.') EndIf Edited October 21, 2005 by LxP Link to comment Share on other sites More sharing options...
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