Jump to content

How Do I Enter A Command In a GUI Button?


Recommended Posts

First you need to learn GUI Concepts, like the difference between OnEvent and Message modes. When you created a GUI with Koda there was a way to select which type of GUI you want to use. It will even create a function for each action on a control. If you made a button Koda can create a function to run if the button is pressed. If you made a checkbox there should be a function to run when it gets checked or unchecked... I know for sure it does this in OnEvent mode if you tell it to...

Is there a "Opt("GUIOnEventMode", 1)" at the top of the code? If it's there and it's a 1 that means you're using OnEvent Mode.

Edit: How to put your GUI into OnEvent mode...

Go to Tools --> Generating Options or Ctrl+F9

Check "Generate OnEvent Code" and "Generate Events for all Controls"

Do that and you'll see what I mean. If you want to see a working example the help file has an OnEvent GUI example. Here's one...

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode 
$mainwindow = GUICreate("Hello World", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)
GUICtrlSetOnEvent($okbutton, "OKButton")
GUISetState(@SW_SHOW)

While 1
  Sleep(1000)  ; Idle around
WEnd

Func OKButton()
  ;Note: at this point @GUI_CTRLID would equal $okbutton,
  ;and @GUI_WINHANDLE would equal $mainwindow
  MsgBox(0, "GUI Event", "You pressed OK!")
EndFunc

Func CLOSEClicked()
  ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, 
  ;and @GUI_WINHANDLE would equal $mainwindow 
  MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
  Exit
EndFunc
Edited by MrMitchell
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...