Jump to content

GuiButton to run an script


Recommended Posts

Hi, I know this probably sounds like an really easy thing to do but please bear with me, im just starting with gui's in autoit.

I need to be able to select an option in the combobox on my GUI and select the button which will then run the specified function.

Heres what i have so far for my test script

CODE
#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <GuiButton.au3>

#Include <GuiComboBox.au3>

Global $btn, $hGUI

Example1()

Func Example1()

Local $msg

$hGUI = GUICreate("My GUI") ; will create a dialog box that when displayed is centered

GUISetState(@SW_SHOW) ; will display an empty dialog box

;Create an Button

$btn = _GUICtrlButton_Create($hGUI, "Button1", 10, 10, 90, 50)

;Combo Selection Box

$hcombo = _GUICtrlComboBox_Create($hGUI, "", 50, 120, 100, 120)

_GUICtrlComboBox_AddString($hcombo, "Script 1")

_GUICtrlComboBox_AddString($hcombo, "Script 2")

;Pass Value to function to find which script to run

_ComboCompare(GUICtrlRead($hcombo))

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

GUIDelete()

EndFunc ;==>Example1

Func _ComboCompare($hmsg)

If $hmsg = "Script 1" Then

_myscript1()

Else

_myscript2()

EndIf

EndFunc

Func _myscript1()

MsgBox(0,"", "Hello1")

EndFunc

Func _myscript2()

MsgBox(0,"", "Hello2")

EndFunc

What i cant figure out is how to get the part in italics to run when i press the button. please help

Link to comment
Share on other sites

Hi, I know this probably sounds like an really easy thing to do but please bear with me, im just starting with gui's in autoit.

I need to be able to select an option in the combobox on my GUI and select the button which will then run the specified function.

Heres what i have so far for my test script

CODE
#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <GuiButton.au3>

#Include <GuiComboBox.au3>

Global $btn, $hGUI

Example1()

Func Example1()

Local $msg

$hGUI = GUICreate("My GUI") ; will create a dialog box that when displayed is centered

GUISetState(@SW_SHOW) ; will display an empty dialog box

;Create an Button

$btn = _GUICtrlButton_Create($hGUI, "Button1", 10, 10, 90, 50)

;Combo Selection Box

$hcombo = _GUICtrlComboBox_Create($hGUI, "", 50, 120, 100, 120)

_GUICtrlComboBox_AddString($hcombo, "Script 1")

_GUICtrlComboBox_AddString($hcombo, "Script 2")

;Pass Value to function to find which script to run

_ComboCompare(GUICtrlRead($hcombo))

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

GUIDelete()

EndFunc ;==>Example1

Func _ComboCompare($hmsg)

If $hmsg = "Script 1" Then

_myscript1()

Else

_myscript2()

EndIf

EndFunc

Func _myscript1()

MsgBox(0,"", "Hello1")

EndFunc

Func _myscript2()

MsgBox(0,"", "Hello2")

EndFunc

What i cant figure out is how to get the part in italics to run when i press the button. please help

Look up GuiGetMsg in the help and the example.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...