Jump to content

Recommended Posts

Posted

Hey,

I'm a newbie at AutoIt programming and I am trying to figure out how to use buttons. I know in C# and VB there is a function... OnButtonclick. I was just wondering how to do this in AutoIt... So lets say I wanted a button to display a MessageBox that said Hi... Anyone have any idea on how to do this?

Posted

Hi and welcome to the forums :)

AutoIt uses two different methods on how to handle events.

First is the simply GUIGetMsg() method:

#include <GUIConstantsEx.au3>
GUICreate("Test GUI")
$button=GUICtrlCreateButton("Click me",10,10)
GUISetState()
Do
    $msg=GUIGetMsg()
    If $msg=$button Then MsgBox(0,"Hello","Hi!")
Until $msg=$GUI_EVENT_CLOSEoÝ÷ Ù'¢wb°éĽéí^Â++y©eÊk·­µêðéÝy©b"¶¨­ç(^Äejëh×6#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode",1)
GUICreate("Test GUI")
GUICtrlCreateButton("Click me",10,10)
GUICtrlSetOnEvent(-1,"clicked")
GUISetOnEvent($GUI_EVENT_CLOSE,"close")
GUISetState()

while 1+1=2
    sleep(100)
WEnd

Func close ()
    Exit
EndFunc

Func clicked()
    MsgBox(0,"Hello","Hi!")
EndFunc

:(

Broken link? PM me and I'll send you the file!

Posted (edited)

Thanks. I've always wondered that :). Is there any chance that a OnButtonclick function is going to be made...

If I were to make one would it go like this?

$msg=GUIGetMsg()
GUICreate("Test GUI")
$button=GUICtrlCreateButton("Click me",10,10)
GUISetState()

Func OnButtonclick()
Do
    $msg=GUIGetMsg()
    If $msg=$button Then MsgBox(0,"Hello","Hi!")
Until $msg=$GUI_EVENT_CLOSE
EndFunc

OnButtonclick()

Would this work?

Edited by Hok
Posted

Thanks. I've always wondered that :). Is there any chance that a OnButtonclick function is going to be made...

If I were to make one would it go like this?

$msg=GUIGetMsg()
GUICreate("Test GUI")
$button=GUICtrlCreateButton("Click me",10,10)
GUISetState()

Func OnButtonclick()
Do
    $msg=GUIGetMsg()
    If $msg=$button Then MsgBox(0,"Hello","Hi!")
Until $msg=$GUI_EVENT_CLOSE
EndFunc

OnButtonclick()

Would this work?

GUISetOnEvent is 100% Exactly what you are looking for.
Posted

Thanks. I've always wondered that :) . Is there any chance that a OnButtonclick function is going to be made...

If I were to make one would it go like this?

$msg=GUIGetMsg()
 GUICreate("Test GUI")
 $button=GUICtrlCreateButton("Click me",10,10)
 GUISetState()
 
 Func OnButtonclick()
 Do
     $msg=GUIGetMsg()
     If $msg=$button Then MsgBox(0,"Hello","Hi!")
 Until $msg=$GUI_EVENT_CLOSE
 EndFunc
 
 OnButtonclick()

Would this work?

Nope, because you never call the function. But OnEvent mode is actually almost exactly like you want it, you connect a button to a function, like OnButtonclick.

Broken link? PM me and I'll send you the file!

Posted

Don't I call it at the end when I say- OnButtonclick() ...?

And just wondering :), Would this work?

include <GUIConstantsEx.au3>
Opt("GUIOnEventMode",1)
GUICreate("Test GUI")
GUICtrlCreateButton("Click me",10,10)
GUICtrlSetOnEvent(-1,"clicked")
GUISetOnEvent($GUI_EVENT_CLOSE,"close")
GUISetState()

Func clicked()
    MsgBox(0,"Hello","Hi!")
EndFunc

It doesn't make much sense to me though...

Posted

Don't I call it at the end when I say- OnButtonclick() ...?

And just wondering :) , Would this work?

include <GUIConstantsEx.au3>
 Opt("GUIOnEventMode",1)
 GUICreate("Test GUI")
 GUICtrlCreateButton("Click me",10,10)
 GUICtrlSetOnEvent(-1,"clicked")
 GUISetOnEvent($GUI_EVENT_CLOSE,"close")
 GUISetState()
 
 Func clicked()
     MsgBox(0,"Hello","Hi!")
 EndFunc

It doesn't make much sense to me though...

Sorry missed that, I'm not used to function being written before they are called :(

And yes that works.

Broken link? PM me and I'll send you the file!

Posted

OK Cool. I'm just wondering why you've got all the wierd -1 and 1 for some of the parameters...

Posted

OK Cool. I'm just wondering why you've got all the wierd -1 and 1 for some of the parameters...

Instead of -1 you could have written it like this:

$button=GUICtrlCreateButton("Click me",10,10)

GUICtrlSetOnEvent($button,"clicked")

But if you use -1 it falls back to the last used GUI element or something. Just for laziness :)

Broken link? PM me and I'll send you the file!

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
×
×
  • Create New...