Jump to content
Sign in to follow this  
Hypnotik

Assign a function to a button

Recommended Posts

Hypnotik

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 ?

Share this post


Link to post
Share on other sites
FireFox

Hi,

Take a look at the helpfile (F1 in SciTE) for the GUIGetMsg or GUICtrlSetOnEvent function.

Br, FireFox.

  • Like 1

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Hypnotik

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

Share this post


Link to post
Share on other sites
FireFox

It's a Switch statement you need, not a Select.

Switch $iMsg
    Case $Button1
        ...


;Or (but not recommended)
Select
    Case $iMsg = $Button1
        ...

_

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
FireFox

Switch $iMsg

There's a variable to compare with Case statements.

Take a look at the helpfile you will find all informations you need, it seems like you're not applying carrefuly the examples.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Hypnotik

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.

Share this post


Link to post
Share on other sites
FireFox

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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
scila1996
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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.