Jump to content

New to the GUI. Need Buttons.


jimmer
 Share

Go to solution Solved by kylomas,

Recommended Posts

Hi, as you can see by the age of my account (2004). I've been writing very basic scripts with autoit for about a decade now. They've always been really small scripts for personal use so I never bothered with the GUI.

Just for reference: I have zero knowledge of the GUI functions.

What I need done:

- A button that changes text from "On" to "Off" when clicked.

- The button is a basic on off switch. Basically $onoff = 1 when pressed once, and $onoff = 0 when pressed again.

- 3 circular buttons.

Button1 - If selected then $button1 = 1

Button2 - If selected then $button2 = 1

Button3 - If selected then $button3 = 1

- A small image placed inside the GUI

If anyone could help me draft up something really basic so I could learn off that, or guide me in the right direction as to which functions I'll need for this task, that would be greatly appreciated.

Thank you.

Edited by jimmer
Link to comment
Share on other sites

Maybe this can help... Simple approach...

 
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
 
Global $onoff1 = 1
 
GUICreate("MY GUI")
 
$button1 = GUICtrlCreateButton("OFF", 50, 50, 50, 50)
$button2 = GUICtrlCreateButton("OFF", 150, 150, 50, 50)
$button3 = GUICtrlCreateButton("OFF", 250, 250, 50, 50)
 
GUISetState()
 
While 1
 
$msg = GUIGetMsg()
 
If $msg = -3 Then Exit
 
If $msg = $button1 Then
If $onoff1 = 1 Then
GUICtrlSetData($button1, "ON")
$onoff1 = 0
Else
GUICtrlSetData($button1, "OFF")
$onoff1 = 1
EndIf
EndIf
 
;continuwe here
 
WEnd
 

NEWHeader1.png

Link to comment
Share on other sites

  • Solution

Slightly more complicated approach...

#include <GUIConstantsEx.au3>

Local $aBTN[8]

Local $gui010 = GUICreate('Button Example', 400, 400)

For $1 = 0 To UBound($aBTN) - 1
    $aBTN[$1] = GUICtrlCreateButton('OFF', 20, $1 * 40 + 20, 360, 30)
Next

; the above loop is the same as the following button definitions
;~ $aBTN[0] = GUICtrlCreateButton('OFF', 20, 20, 360, 30)
;~ $aBTN[1] = GUICtrlCreateButton('OFF', 20, 60, 360, 30)
;~ $aBTN[2] = GUICtrlCreateButton('OFF', 20, 100, 360, 30)
;~ $aBTN[3] = GUICtrlCreateButton('OFF', 20, 140, 360, 30)
;~ $aBTN[4] = GUICtrlCreateButton('OFF', 20, 180, 360, 30)
;~ $aBTN[5] = GUICtrlCreateButton('OFF', 20, 220, 360, 30)
;~ $aBTN[6] = GUICtrlCreateButton('OFF', 20, 260, 360, 30)
;~ $aBTN[7] = GUICtrlCreateButton('OFF', 20, 300, 360, 30)

GUISetState()

While 1
    $iMSG = GUIGetMsg()
    Switch $iMSG
        Case $gui_event_close
            Exit
        Case $aBTN[0] To $aBTN[UBound($aBTN) - 1]
            _Toggle_BTN($iMSG)
    EndSwitch
WEnd

Func _Toggle_BTN($ctrlid)
    GUICtrlSetData($ctrlid, GUICtrlRead($ctrlid) = 'OFF' ? 'ON' : 'OFF')
EndFunc   ;==>_BTN

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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