Jump to content

Recommended Posts

Posted

how do you make a button actually function like if the user presses the button a message box pops up

From the Help file:

#include <GUIConstantsEx.au3>

GUICreate("Hello World", 200, 100)
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)
GUISetState(@SW_SHOW)

While 1
  $msg = GUIGetMsg()

  Select
    Case $msg = $okbutton
      MsgBox(0, "GUI Event", "You pressed OK!")

    Case $msg = $GUI_EVENT_CLOSE
      MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
      ExitLoop
  EndSelect
WEnd
Posted (edited)

Or in OnEventMode

#include <GUIConstantsEx.au3>
Opt('GuiOnEventMode',1)
GUICreate("Hello World", 200, 100)
GuiSetOnEvent($GUI_EVENT_CLOSE, "Quit")
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)
GuiCtrlSetOnEvent(-1, "Button")
GUISetState(@SW_SHOW)

While 1
Sleep(100)
WEnd

Func Quit()
Exit
EndFunc

Func Button()
MsgBox(0, "", "You pressed the button!")
EndFunc
Edited by Paulie
Posted

From the Help file:

#include <GUIConstantsEx.au3>

GUICreate("Hello World", 200, 100)
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)
GUISetState(@SW_SHOW)

While 1
  $msg = GUIGetMsg()

  Select
    Case $msg = $okbutton
      MsgBox(0, "GUI Event", "You pressed OK!")

    Case $msg = $GUI_EVENT_CLOSE
      MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
      ExitLoop
  EndSelect
WEnd
im still lost could someone comment the above code and tell me what it does
Posted (edited)

#include <GUIConstantsEx.au3>

GUICreate("Hello World", 200, 100); Create the GUI
GUICtrlCreateLabel("Hello world! How are you?", 30, 10); Create the label
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60); This creates the button. Notice the variable, $okbutton
GUISetState(@SW_SHOW); Make the GUI visible

While 1 ; Start a loop to keep the GUI visible while it checks to see what the user does
  $msg = GUIGetMsg(); Watch the GUI to see if the user does anything. Another variable, which will interact with the one above

  Select
    Case $msg = $okbutton; If the user clicks the OK button Then...
      MsgBox(0, "GUI Event", "You pressed OK!"); Display the message box

    Case $msg = $GUI_EVENT_CLOSE; If user click the GUI's close button Then...
      MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting..."); Display the message box
      ExitLoop; Get out of the loop that keeps the GUI visible
  EndSelect
WEnd

Edited by pete1234
Posted (edited)

#include <GUIConstantsEx.au3>

GUICreate("Hello World", 200, 100); Create the GUI
GUICtrlCreateLabel("Hello world! How are you?", 30, 10); Create the label
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60); This creates the button. Notice the variable, $okbutton
GUISetState(@SW_SHOW); Make the GUI visible

While 1 ; Start a loop to keep the GUI visible while it checks to see what the user does
  $msg = GUIGetMsg(); Watch the GUI to see if the user does anything. Another variable, which will interact with the one above

  Select
    Case $msg = $okbutton; If the user clicks the OK button Then...
      MsgBox(0, "GUI Event", "You pressed OK!"); Display the message box

    Case $msg = $GUI_EVENT_CLOSE; If user click the GUI's close button Then...
      MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting..."); Display the message box
      ExitLoop; Get out of the loop that keeps the GUI visible
  EndSelect
WEnd
thank you so much i was always so lost when working with a gui but i get it now and my programming knowledge is really starting to grow with this language Edited by 2words4uready

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...