MarcW Posted May 8, 2010 Share Posted May 8, 2010 I have created a GUI with an "Exit" submenu, but do not know how to code it so when clicked the script closes. Help? Link to comment Share on other sites More sharing options...
GEOSoft Posted May 8, 2010 Share Posted May 8, 2010 And the variable for that menuitem is? Are you using a Switch in your message loop or Select? Did you even think that posting a few lines of your oh-so-secret code might give us something to work with? While we are asking questions, I have this piece of code that isn't returning what I expect. Can you tell me what is wrong with it? George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
MarcW Posted May 9, 2010 Author Share Posted May 9, 2010 "And the variable for that menuitem is?" "Are you using a Switch in your message loop or Select? "Did you even think that posting a few lines of your oh-so-secret code might give us something to work with?" $MenuItem Opt (GUIOnEventMode, 1) (I think thats what you mean...) I'm writing a script to perform an automated QC process for servers I image utilizing a GUI and cmd. Regardless of the intent of the script, an exit button is an exit button...correct me if I'm wrong. Appreciate the help! Link to comment Share on other sites More sharing options...
adik2dmax666 Posted May 9, 2010 Share Posted May 9, 2010 (edited) #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("sample", 416, 216, 192, 114) $Button1 = GUICtrlCreateButton("Click me to close", 16, 32, 371, 153, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;exits if close button is clicked Exit 1 Case $Button1 ;exits if $Button1 is clicked Exit 1 EndSwitch WEnd Edited May 9, 2010 by adik2dmax666 First learn computer science and all the theory. Next develop a programming style. Then forget all that and just hack. -George Carrette[sub]GD Keylogger Creator (never released)[/sub][sub]Garena Autojoin v3.0[/sub] Link to comment Share on other sites More sharing options...
MarcW Posted May 9, 2010 Author Share Posted May 9, 2010 #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Sample", 178, 50, 192, 114) $Label1 = GUICtrlCreateLabel("Click the close button to exit!", 16, 16, 140, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd The above code doesn't work when Opt("GUIOnEventMode", 1). And as I have other menu items that are supposed to do something when clicked, I need it explained how to link a mouse click on that control to an action. For example, $mnuHelp = GUICtrlCreateMenuItem("&Help", $mnuFile) should bring up a help file. $mnuExit = GUICtrlCreateMenuItem("&Exit", $mnuFile) should exit when clicked. $mnuOpen = GUICtrlCreateMenuItem("&Open", $mnuFile) should bring up a Select File dialog box. Trying... GUICtrlSetOnEvent ( $mnuOpen, FileOpenDialog ("Select a file", "C:\", ".txt")) But that doesn't work either... So my real question would be: how does the script detect WHEN the mouse is clicked, WHERE the mouse is clicked, and WHAT to do when clicked...? Link to comment Share on other sites More sharing options...
somdcomputerguy Posted May 9, 2010 Share Posted May 9, 2010 GUICtrlSetOnEvent - Defines a user-defined function to be called when a control is clicked.So code like this will work:GUICtrlSetOnEvent($mnuOpen, "FODder") Func FODder() FileOpenDialog("Select a file", "C:\", ".txt") EndFuncor maybe this, but probably not, but I haven't tried it..GUICtrlSetOnEvent($mnuOpen, "FileOpenDialog ('Select a file', 'C:\', '.txt')") - Bruce /*somdcomputerguy */Ā If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Makaule Posted May 9, 2010 Share Posted May 9, 2010 If you are yousing Opt("GUIOnEventMode", 1), then you would need to use GUISetOnEvent and GUICtrlSetOnEvent. GUISetOnEvent should be used with button like $GUI_EVENT_CLOSE, while GUICtrlSetOnEvent should be used with buttons or something more created by user.For example:#include <GuiConstantsEx.au3> Opt("GUIOnEventMode", 1) $MainGUI = GUICreate("My Test",400,300) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $Button = GUICtrlCreateButton("Msg Me...", "15", "15") GUICtrlSetOnEvent($Button, "_Msg") $ButtonExit = GUICtrlCreateButton("Please Exit..", "55", "55") GUICtrlSetOnEvent($ButtonExit, "_Exit") While 1 GUISetState(@SW_SHOW, $MainGUI) WEnd Func _Exit() Exit EndFunc Func _Msg() MsgBox(0, "Message Box", "You have pressed button") EndFunc Link to comment Share on other sites More sharing options...
MarcW Posted May 9, 2010 Author Share Posted May 9, 2010 Yes, that works for buttons, but not for a Menu item. I'm following the line of thought that when coding: GUICtrlSetOnEvent ($mnuExit, "_EXIT") Instead of the variable name ($mnuExit), I may need to use the controlID. However when I use the AutoIT Window Info tool, there is no controlID for that control. So how do I identify the controlID of the File>Exit control? Alternatively, how else can I identify that control without using the controlID? Link to comment Share on other sites More sharing options...
Bowmore Posted May 9, 2010 Share Posted May 9, 2010 Example using a menu and event modeĀ #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) $Form1 = GUICreate("sample", 416, 216, 192, 114) GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit_Clicked",$Form1) $mnuFile = GUICtrlCreateMenu("&File") $mnuHelp = GUICtrlCreateMenuItem("&Help", $mnuFile); should bring up a help file. GUICtrlSetOnEvent ($mnuHelp, "_Help_Clicked") $mnuExit = GUICtrlCreateMenuItem("&Exit", $mnuFile); should exit when clicked. GUICtrlSetOnEvent($mnuExit, "_Exit_Clicked") $mnuOpen = GUICtrlCreateMenuItem("&Open", $mnuFile); should bring up a Select File dialog box. GUICtrlSetOnEvent($mnuOpen, "_Open_Clicked") GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func _Help_Clicked() ;your code here EndFunc Func _Exit_Clicked() Exit EndFunc Func _Open_Clicked() Local $sFileToOpen = "" $sFileToOpen = FileOpenDialog ("Select a file", "C:\", "Text Files(*.txt)") EndFunc "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
MarcW Posted May 9, 2010 Author Share Posted May 9, 2010 Yes! Thats it! Thank you! Now I just have to go back and figure out what I was doing wrong... Again, thank you so much! 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