Sign in to follow this  
Followers 0
harrisms

Help!

5 posts in this topic

I'm relatively new to autoit but have some background in coding with C++, I was wondering about the GUI command guictrlcreatebutton.

If I create a button and want to have my script do something once that button has been pushed how do I find out when the button has been pushed.

all I have is guictrlcreatebutton("Click Here To Continue", 10, 330, 100, 30)

what I'm asking for I guess is how do I obtain the a return value from the button?

any suggestions?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

GUIGetMsg()

Here is the example from the help file:

Example

;-------------------------------------------------------------------------------------
; Example - Press the button to see the value of the radio boxes
; The script also detects state changes (closed/minimized/timeouts, etc).

#include <GUIConstants.au3>

Opt("GUICoordMode", 1)
GUICreate("Radio Box Demo", 400,280)

; Create the controls
$button_1 = GUICtrlCreateButton ("B&utton 1", 30, 20, 120, 40)
$group_1 = GUICtrlCreateGroup ("Group 1", 30, 90, 165, 160)
GUIStartGroup()
$radio_1 = GUICtrlCreateRadio ("Radio &0", 50, 120, 70, 20)
$radio_2 = GUICtrlCreateRadio ("Radio &1", 50, 150, 60, 20)
$radio_3 = GUICtrlCreateRadio ("Radio &2", 50, 180, 60, 20)

; Init our vars that we will use to keep track of GUI events
$radioval1 = 0    ; We will assume 0 = first radio button selected, 2 = last button
$radioval2 = 2

; Show the GUI
GUISetState ()

; In this message loop we use variables to keep track of changes to the radios, another
; way would be to use GUICtrlRead() at the end to read in the state of each control
While 1
   $msg = GUIGetMsg()
   Select
       Case $msg = $GUI_EVENT_CLOSE
         MsgBox(0, "", "Dialog was closed") 
         Exit
      Case $msg = $GUI_EVENT_MINIMIZE
         MsgBox(0,"", "Dialog minimized",2)
      Case $msg = $GUI_EVENT_MAXIMIZE
         MsgBox(0,"", "Dialog restored",2)
   
      Case $msg = $button_1
         MsgBox(0, "Default button clicked", "Radio " & $radioval1 )
         
      Case $msg >= $radio_1 AND $msg <= $radio_3
         $radioval1 = $msg - $radio_1

   EndSelect
WEnd
Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

that really doesn't help all that much...i looked at the help files and they dont help...

i was kinda hoping someone could write a sample line of code for me...

i have:

guictrlcreatebutton("Click Here To Continue", 10, 330, 100, 30)

if ( "the button is clicked" ) then GUICtrlCreatePic("picture.jpg", 120 , 10 , 370 , 480)

endif

i just need to know how to set up "the button is clicked"

i tried setting:

$button=guictrlcreatebutton("Click Here To Continue", 10, 330, 100, 30)

if ( $button=1 ) then GUICtrlCreatePic("picture.jpg", 120 , 10 , 370 , 480)

endif

but my picture never comes up...

any real help?

Share this post


Link to post
Share on other sites

Posting code always helps. This is why:

#include <GUIConstants.au3>
$mainGUI = GUICreate("This is a GUI")
$button=guictrlcreatebutton("Click Here To Continue", 10, 20, 200, 30)
GUISetState();this makes the actual change to the GUI, without this, you won't see anything

While 1
    $msg = GUIGetMsg()
    If $msg = $button  Then
        GUICtrlCreatePic("picture.jpg", 50 , 20 , 370 , 480)
        GUISetState();this makes the actual change to the GUI
    ElseIf $msg = $GUI_EVENT_CLOSE Then
        Exitloop;You can also use Exit to directly close the script from here, but if you use exitloop it will execute stuff after the Wend
    EndIF
;Keywords in autoit and other visual basic scripting languages can be in capitol letters, unlike c++
Wend

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#include <GUIConstants.au3>;this allows all the GUI functions to be run

GUICreate("RADS WINDOW",128,128)
$button = GUICtrlCreateButton("RADS BUTTON",2,2,124,124)
GUISetState()

While 1;This is your infinite loop, once this stops your script will close
    $Msg = GUIGetMsg() 
;this is like your "triggering event" if you've played warcraft 3 and made a map ^_^
    
    If $msg = $Button Then msgbox(0,"title","You pushed the button, RADS BUTTON! Its not yours!") 
; if (trigger) is (button) then show a MSGBOX... which you can switch with your GUICtrlCreatePic() etc...!
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    ;GUI_EVENT_CLOSE is when you press the X, or terminate the program in some other way...
WEnd

Exit;closes your script when While 1 is exited.

Read the comments, and ill tell you right now if you havent already, use the helpfile for extra functions and methods... and i recommend you use SciTE for editing scrpts, it lets you beta run and compile and other neat stuff easy:

http://www.autoitscript.com/cgi-bin/getfil...iTE4AutoIt3.exe

Edited by Rad

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