Jump to content
Sign in to follow this  
jimmer

Need buttons to alter variables.

Recommended Posts

Howdy!

This is essentially my first time in 10 years creating a GUI for AutoIt. I've spent my entire weekend learning how to implement the GUI, so I apologize for the very terribly written code.

I need a few thinks achieved here:

- If Checkbox is checked, I need $var1 = 1

- If Checkbox is not checked, I need $var1 = 0

- I also need the the number translated into a variable in the input box.

So if user defined number is 40, then I need $timer = 40

(Edit, I realize it's more realistic to ask for $InputVariable to = 40, which is fine, because I can use that in place of $timer... right?)

- I also need all my buttons to interact in real time if the user decides to press [sTART] again.

------------------------------------------------------------

I believe I have already accomplished the following, but I will explain anyways to make sense of things in my poorly written script... Also, if any kind soul would like to help me clean up the code :-)

- If user selects [sTART] then I need it to execute the script.

- If radio1 is selected then I need $z8 = 1

- If radio2 is selected then I need $z9 = 1

- If radio3 is selected then I need $z10 = 1

#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
Global $button2 = 0, $button3 = 0, $button1 = 0
$goldpump = GUICreate("MyFirstGUI", 400, 700, -1 ,-1)
GUISetState(@SW_SHOW)


;Buttons ----------------------------


Opt("GUIOnEventMode", 1)
$Button_1 = GUICtrlCreateButton("START", 75, 650, 150)
$Button_2 = GUICtrlCreateButton("Stop / Exit", 225, 650, 100)


    GUICtrlCreateGroup("Title 1", 34, 34, 325, 400)
$radio1 = GUICtrlCreateRadio("Option 1", 50, 50, 160, 20)
GUICtrlCreateLabel("Description 1", 50, 130)
$radio2 = GUICtrlCreateRadio("Option 2", 50, 150, 160, 20)
GUICtrlCreateLabel("Description 2", 50, 170)
$radio3 = GUICtrlCreateRadio("Option 3", 50, 250, 160, 20)
GUICtrlCreateLabel("Description 3", 50, 270)
GUICtrlCreateGroup("", -99, -99, 1, 1)


$InputVariable = GUICtrlCreateInput("40", 34, 500, 20, 20, $ES_NUMBER)
    GUICtrlSetLimit(-1, 2)
GUICtrlCreateLabel("User defined number (40 being default)", 60, 502)


GuiSetOnEvent($GUI_EVENT_CLOSE, "Quit")
GuICtrlSetOnEvent($Button_2, "Term")
GuiCtrlSetOnEvent($Button_1, "DoScript")
GUICtrlSetOnEvent($radio1, "z8")
GUICtrlSetOnEvent($radio2, "z9")
GUICtrlSetOnEvent($radio3, "z10")


;Looping images ------------------------


Global $hGUI, $hImage, $hGraphic


_GDIPlus_StartUp()
$hImage   = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\811.png")




$hGraphic = _GDIPlus_GraphicsCreateFromHWND($goldpump)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 55, 68)


_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)


$hImage   = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\812.png")


$hGraphic = _GDIPlus_GraphicsCreateFromHWND($goldpump)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 110, 575)


_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()


Box()


;Functions --------------------------------


Func DoScript()
MouseMove(1200, 400)
EndFunc


Func Term()
Exit
EndFunc


Func z8()
$8 = 1
$9 = 0
$10 = 0
EndFunc


Func z9()
$8 = 0
$9 = 1
$10 = 0
EndFunc


Func z10()
$8 = 0
$9 = 0
$10 = 1
EndFunc


Func Box()
$idCheckbox = GUICtrlCreateCheckbox("Standard Checkbox", 34, 465, 185, 25)
While 1
        Switch GUIGetMsg()
Case $idCheckbox
                If _IsChecked($idCheckbox) Then
Checked()
                Else
Unchecked()
                EndIf


        EndSwitch
WEnd
EndFunc


Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc


Func Checked()
$var1 = 1
EndFunc


Func Unchecked()
$var1 = 0
EndFunc
Edited by jimmer

Share this post


Link to post
Share on other sites

1) If checkbox is checked

$cbx_1 = GUICtrlCreateCheckbox()

If IsChecked($cbx_1) Then ...

Func IsChecked($control)
    Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED
EndFunc

2) content of edit to variable

$ed_1 = GUICtrlCreateInput() 

$value = GUICtrlRead($ed_1)
Edited by Zedna

Share this post


Link to post
Share on other sites

Here is fixed and rewritten script to GUI message mode

#include <GUIConstants.au3>
#include <GuiConstantsEx.au3>

$goldpump = GUICreate("MyFirstGUI", 400, 700, -1, -1)
$idCheckbox = GUICtrlCreateCheckbox("Standard Checkbox", 34, 465, 185, 25)

$Button_1 = GUICtrlCreateButton("START", 75, 650, 150)
$Button_2 = GUICtrlCreateButton("Stop / Exit", 225, 650, 100)

GUICtrlCreateGroup("Title 1", 34, 34, 325, 400)
$radio1 = GUICtrlCreateRadio("Option 1", 50, 50, 160, 20)
GUICtrlCreateLabel("Description 1", 50, 130)
$radio2 = GUICtrlCreateRadio("Option 2", 50, 150, 160, 20)
GUICtrlCreateLabel("Description 2", 50, 170)
$radio3 = GUICtrlCreateRadio("Option 3", 50, 250, 160, 20)
GUICtrlCreateLabel("Description 3", 50, 270)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$InputVariable = GUICtrlCreateInput("40", 34, 500, 20, 20, $ES_NUMBER)
GUICtrlSetLimit(-1, 2)
GUICtrlCreateLabel("User defined number (40 being default)", 60, 502)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button_1
            DoScript()
        Case $Button_2
            Exit
    EndSwitch
WEnd

Func DoScript()
    Local $number, $var1 = 0, $8 = 0, $9 = 0, $10 = 0
    
    $number = GUICtrlRead($InputVariable)
    If IsChecked($idCheckbox) Then $var1 = 1
    If IsChecked($radio1) Then $8 = 1
    If IsChecked($radio2) Then $9 = 1
    If IsChecked($radio3) Then $10 = 1
    
    ; here do whatever want with these variables ...
    MsgBox(0,'Do', _
    'Number: ' & $number & @CRLF & _
    'CheckBox: ' & $var1 & @CRLF & _
    'Option1: ' & $8 & @CRLF & _
    'Option2: ' & $9 & @CRLF & _
    'Option3: ' & $10)

;~     MouseMove(1200, 400)
EndFunc   ;==>DoScript

Func IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>IsChecked
Edited by Zedna

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...