8daysaweek.co.uk Posted September 16, 2005 Share Posted September 16, 2005 This is my first experiment with an AutoIt GUI. I want to create a menu with buttons that, when clicked, start an executable file. Sounds simple. I have created the menu quite easily, but I can't find out how to associate the buttons with the exe to run when clicked. I have searched for a couple of hours before posting, but it's been a long day! If someone could give me some example code that I can work with I would appreciate it. Here's what I have so far: #include <GuiConstants.au3> ; GUI GuiCreate("Menu", 400, 380) GuiSetIcon("Icon1.ico", 0) ; BUTTONS $button1 = GUICtrlCreateButton ("1", 30,120,40,40,$BS_ICON) GUICtrlSetImage (-1, "Icon2.ico",-1) TIA, [size=15]James :)[/size]www.8daysaweek.co.uk - A User-Focused OOo site, with Forums, Help Centre,Easy Installation CDs & OOo on USB Key Link to comment Share on other sites More sharing options...
mr_carter Posted September 16, 2005 Share Posted September 16, 2005 Does this help? ; ; While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $button1 Run("pathtofile.exe") Case Else ;;; EndSelect WEnd Link to comment Share on other sites More sharing options...
8daysaweek.co.uk Posted September 16, 2005 Author Share Posted September 16, 2005 Thanks for replying mr_carter. This is what I have now, but the menu no longer appears ; AutoIt 3.1.1 #include <GuiConstants.au3> ; GUI GuiCreate("Menu", 400, 380) GuiSetIcon("Icon1.ico", 0) ; PIC GuiCtrlCreatePic("pic.jpg", 75, 10, 250, 87) ; BUTTONS $button1 = GUICtrlCreateButton ("1", 30,120,40,40,$BS_ICON) GUICtrlSetImage (-1, "Icon2.ico",-1) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $button1 Run("pathtofile.exe") Case Else ;;; EndSelect WEnd ; GUI MESSAGE LOOP GuiSetState() While GuiGetMsg() <> $GUI_EVENT_CLOSE WEnd [size=15]James :)[/size]www.8daysaweek.co.uk - A User-Focused OOo site, with Forums, Help Centre,Easy Installation CDs & OOo on USB Key Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 17, 2005 Moderators Share Posted September 17, 2005 Look at the bottom of your script, you have ; GUI MESSAGE LOOP, something tells me you did a copy and paste. Your GUISetState() is in the wrong place is all... ; AutoIt 3.1.1 #include <GuiConstants.au3> ; GUI GuiCreate("Menu", 400, 380) GuiSetIcon("Icon1.ico", 0) ; PIC GuiCtrlCreatePic("pic.jpg", 75, 10, 250, 87) ; BUTTONS $button1 = GUICtrlCreateButton ("1", 30,120,40,40,$BS_ICON) GUICtrlSetImage (-1, "Icon2.ico",-1) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $button1 Run("pathtofile.exe") Case Else ;;; EndSelect WEnd Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
8daysaweek.co.uk Posted September 17, 2005 Author Share Posted September 17, 2005 something tells me you did a copy and paste.Your GUISetState() is in the wrong place is all...Yep saves screwing something up in the typing I started with the imagebutton.au3 example and pasted in mr_carter's suggested code above.Thanks for the tip, it works now.I tried repeating the code...While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $button1 Run("pathtofile1.exe") Case Else ;;; EndSelect While 2 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $button2 Run("pathtofile2.exe") Case Else ;;; EndSelect...for each additional button, but it doesn't work. I obviously don't understand what's going on with it yet. If someone could let me know how to add second and thrid buttons etc, I *should* be able to run with it from there.BFN , [size=15]James :)[/size]www.8daysaweek.co.uk - A User-Focused OOo site, with Forums, Help Centre,Easy Installation CDs & OOo on USB Key Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 17, 2005 Moderators Share Posted September 17, 2005 Your stuck in the first loop and never leaving w/out an ExitLoop and when you do leave... What makes the 2nd While statement 2 true? Just add another Case $msg = $button# to the original While. While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE Exit Case $MSG = $button1 Run("pathtofile1.exe") Case $MSG = $button2 Run("pathtofile2.exe") Case $MSG = $button3 etc etc etc EndSelect Wend Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
8daysaweek.co.uk Posted September 18, 2005 Author Share Posted September 18, 2005 Ron, that's great, thank you. I'm understanding it better now. I've also found out how to insert labels, format the text and open a URL from a button, so things are looking up BFN, [size=15]James :)[/size]www.8daysaweek.co.uk - A User-Focused OOo site, with Forums, Help Centre,Easy Installation CDs & OOo on USB Key Link to comment Share on other sites More sharing options...
ojuarez Posted December 6, 2005 Share Posted December 6, 2005 I need help doing the same, but I am a little bit lost. can someone post or send me the code to run an app "exe" using a button? Link to comment Share on other sites More sharing options...
Angelia Posted December 8, 2005 Share Posted December 8, 2005 I need help doing the same, but I am a little bit lost. can someone post or send me the code to run an app "exe" using a button? I would like the complete code as well. Also... Is there a place to find a "gui gallery" (for lack of better term) of code for guis that beginners like myself could check out...? Thank you... Link to comment Share on other sites More sharing options...
Bert Posted December 13, 2005 Share Posted December 13, 2005 there is a example folder that has everything you need. It is located in the autoit directory on your PC. Open the file by viewing it in you script editor. You can run the script to see how things look. IMPORTANT!!! If you make any changes to the examples, save thm with a different file name. That way, if you blow up the script making changes, you have your original to revert to. Enjoy! The Vollatran project My blog: http://www.vollysinterestingshit.com/ 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