Sign in to follow this  
Followers 0
8daysaweek.co.uk

Run exe program from button

10 posts in this topic

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

Share this post


Link to post
Share on other sites



Does this help?

;

;

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $button1

Run("pathtofile.exe")

Case Else

;;;

EndSelect

WEnd

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

something tells me you did a copy and paste.

Your GUISetState() is in the wrong place is all...

Yep :P saves screwing something up in the typing :mad2:

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

:P

Share this post


Link to post
Share on other sites

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?

:P

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...

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
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
Sign in to follow this  
Followers 0