Jump to content

Assign a function to a button


Hypnotik
 Share

Go to solution Solved by FireFox,

Recommended Posts

Hi. 

I used search function and readed so much topics but i didn't understand yet how to assing a function to a GUIed button.

I didn't understand how that Switch and Select work.

Could someone make me an example assigning a function to a button ?

Link to comment
Share on other sites

I have read this already but i surely be wrong on something. I didn't understand how it works

 
   
Local $iMsg = 0
    While 1
        $iMsg = GUIGetMsg()
        Select
            Case $Button1
                MsgBox($MB_SYSTEMMODAL, "Test", "Test")
                ExitLoop
        EndSelect
    WEnd
Link to comment
Share on other sites

It's not that i didn't apply it,it's that i didn't understand what to do with them 

I used also that variable but i didn't work neither

What about making a pratic example? Something stupid just like showing up a msgbox after pressing a button

And about the help file, in my personal mind i think that the 60% of the examples there are just confusing for newbies like me.

Link to comment
Share on other sites

  • Solution

There are examples everywhere, even in the helpfile. I don't get it.

Anyway :

#include <GUIConstantsEx.au3>

GUICreate("MyGUI")

$iButton1 = GUICtrlCreateButton("Button1", 20, 20, 80, 22)

GUISetState(@SW_SHOW)

Local $iMsg = 0

While 1
    $iMsg = GUIGetMsg()

    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $iButton1
            MsgBox(0, "", "Button1 clicked")
    EndSwitch
WEnd

Br, FireFox.

Link to comment
Share on other sites

First you draw a GUIDE ago by koda 
 
 
Then we will handle: D 
 
A simple example
 
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode",1) ; Enable GUI Event Mode with 1
; Start Create GUI
$hGUI = GUICreate("Example",500,500,-1,-1)
$But = GUICtrlCreateButton("Click",100,100,100,100)
GUISetState() ; Show GUI
;Set Event Click
GUISetOnEvent($GUI_EVENT_CLOSE,"Exit1") ; If you press the X button ---> Call Function Exit1
GUICtrlSetOnEvent($But,"Notepad") ; If Click to Button ---> Call Function Note

Func Notepad()
    Run("notepad.exe")
EndFunc

Func Exit1()
    Exit
EndFunc

; mandatory
While 1
    Sleep(10)
WEnd
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...