Jump to content

GUISetOnEvent() fails?


Zachlr
 Share

Recommended Posts

Hi,

I am unable to have a function called when my button is pressed, because GUISetOnEvent() fails for some reason. Below is part of my script.

Opt("GUIOnEventMode", 1)
$WakeOnLanGUI = GUICreate("Wake On LAN", 500, 100, 190, 125)
$Status = GUICtrlCreateLabel("Status", 16, 16, 500 - 16, 34)
$button = GUICtrlCreateButton("Wake", 415, 65, 75, 25, 0)
GUICtrlSetState($button, $GUI_DISABLE)
GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")
If GUISetOnEvent($button, "button") = 0 Then Exit 2
GUISetState(@SW_SHOW)

Func button()
    If GUICtrlRead($button) = "Wake" Then WakePC()
    If GUICtrlRead($button) = "Shutdown" Then ShutdownPC(30)
    If GUICtrlRead($button) = "Abort" Then AbortShutdownPC()
EndFunc

As soon as I start the program: !>12:30:45 AutoIT3.exe ended.rc:2

Without the exit command, the button simply does nothing.

Please tell me what I am doing wrong.

Thanks,

Zach

Link to comment
Share on other sites

  • Moderators

Your example is a mess... using GUISetOnEvent for controls instead of GUICtrlSetOnEvent.

No loop to keep the script running.

No working example ( by working I mean I shouldn't get a au3check error for missing functions and syntax errors ).

Anyway, I'll give you more than you gave us.

Global $a_button_text[3] = ["Wake", "ShutDown", "Abort"]

Opt("GUIOnEventMode", 1)
$WakeOnLanGUI = GUICreate("Wake On LAN", 500, 100, 190, 125)
$Status = GUICtrlCreateLabel("Status", 16, 16, 500 - 16, 34)
$button = GUICtrlCreateButton("Wake", 415, 65, 75, 25, 0)
GUICtrlSetOnEvent($button, "button")
;~ GUICtrlSetState($button, $GUI_DISABLE)
GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")
GUISetState(@SW_SHOW)


While 1
    ControlSetText($WakeOnLanGUI, "", $button, $a_button_text[Random(0, 2, 1)])
    Sleep(10000)
WEnd

Func Terminate()
    Exit
EndFunc

Func button()
    Switch GUICtrlRead($button)
        Case "Wake"
            MsgBox(64, "Info", "Button text is ""Wake""")
        Case "Shutdown"
            MsgBox(64, "Info", "Button text is ""Shutdown""")
        Case "Abort"
            MsgBox(64, "Info", "Button text is ""Abort""")
    EndSwitch
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thank you for the information. I realize that the posted code was not working code, I only posted a small part of my (235 line) script. After all, the issue here was not why the script closes or doesn't work, it was why GUISetOnEvent() failed. I didn't realize there was a different function for GUI controls, but it makes sense now.

Thanks again,

Zach

Link to comment
Share on other sites

  • Moderators

Thank you for the information. I realize that the posted code was not working code, I only posted a small part of my (235 line) script. After all, the issue here was not why the script closes or doesn't work, it was why GUISetOnEvent() failed. I didn't realize there was a different function for GUI controls, but it makes sense now.

Thanks again,

Zach

That's not an excuse. Those of us that are willing to help shouldn't have to go out of our ways to.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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