Jump to content

How do I make a button open a program?


Recommended Posts

This is what I have. I want to make the " OK " button to open up a program. What is the cmd for that?

#include <GuiConstants.au3>

; Create the GUI.
GuiCreate("LmH ", 300, 135) 
GuiSetIcon( "", 1) 

Global $defaultstatus = "Ready"
Global $status

$filemenu = GUICtrlCreateMenu ("&File")
$fileitem = GUICtrlCreateMenuitem ("WHAT",$filemenu)
GUICtrlSetState(-1,$GUI_DISABLE)
$helpmenu = GUICtrlCreateMenu ("About Us")
$saveitem = GUICtrlCreateMenuitem ("Save",$filemenu)
GUICtrlSetState(-1,$GUI_DISABLE)
$infoitem = GUICtrlCreateMenuitem ("Info",$helpmenu)
$exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)
$recentfilesmenu = GUICtrlCreateMenu ("Recent Files",$filemenu,1)

$separator1 = GUICtrlCreateMenuitem ("",$filemenu,2); create a separator line

$viewmenu = GUICtrlCreateMenu("View",-1,1); is created before "?" menu
$viewstatusitem = GUICtrlCreateMenuitem ("Statusbar",$viewmenu)
GUICtrlSetState(-1,$GUI_CHECKED)
$okbutton = GUICtrlCreateButton ("OK",25,50,107,20)
GUICtrlSetState(-1,$GUI_FOCUS)
$cancelbutton = GUICtrlCreateButton ("Cancel",150,50,70,20)

$statuslabel = GUICtrlCreateLabel ($defaultstatus,0,165,300,16,BitOr($SS_SIMPLE,$SS_SUNKEN))

GUISetState ()
While 1
    $msg = GUIGetMsg()
    
    
    If $msg = $viewstatusitem Then
        If BitAnd(GUICtrlRead($viewstatusitem),$GUI_CHECKED) = $GUI_CHECKED Then
            GUICtrlSetState($viewstatusitem,$GUI_UNCHECKED)
            GUICtrlSetState($statuslabel,$GUI_HIDE)
        Else
            GUICtrlSetState($viewstatusitem,$GUI_CHECKED)
            GUICtrlSetState($statuslabel,$GUI_SHOW)
        EndIf
    EndIf
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Or $msg = $exititem Then ExitLoop
    If $msg = $infoitem Then Msgbox(0,"Info","*****************.")
WEnd
GUIDelete()

Exit

"I think, therefore I am"[size="1"]René Descartes[/size]

Link to comment
Share on other sites

Ok, but I'm trying to make OK to run this

Sleep(3000);3 seconds


$i = 1
While $i <= 41
 
$variable = ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<'
Send($variable & @CRLF)

    $i += 1
Wend

Exit

Edited by dgarrett8

"I think, therefore I am"[size="1"]René Descartes[/size]

Link to comment
Share on other sites

My mistake, I meant that it will be added to the original script and all together compressed as an exe. So I guess to answer your question, that this would be a function

Sleep(3000);3 seconds



$i = 1
While $i <= 41

$variable = ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<'
Send($variable & @CRLF)

    $i += 1
Wend

Exit

"I think, therefore I am"[size="1"]René Descartes[/size]

Link to comment
Share on other sites

@dgarret8

Try this:

#include <GUIConstants.au3>

$gui = GUICreate("", 200, 200)
GUISetState()
$ok = GUICtrlCreateButton("OK", 10, 10)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_Event_Close
            Exit 0
        Case $msg = $ok
            func1()
    EndSelect
WEnd

Func func1()
    Sleep(3000); Sleep 3 seconds
    $i = 1
    While $i <= 41
        $variable = ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<'
        Send($variable & @CRLF)
        $i += 1
    Wend
Exit
EndFunc

This just gives you the basic understanding, you can incorporate your code from wherever.

While Alive() {
	 DrinkWine();
}
AutoIt Programmer
Link to comment
Share on other sites

Put all of that code into a function, and set the button to call the function like so:

...Your GUI code

While 1
     If GUIGetMsg() = $Button_1 Then
         _MyFunc()
     EndIf
Wend

Edit:

Got beat by someone on their first post. Welcome to the forums FireLordZi

Edited by Senton-Bomb
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...