Jump to content

GuiSetOnEvent "function" parameter


Angel
 Share

Recommended Posts

Hi,

while trying to write a GUI I tried to do the following:

GuiSetOnEvent($GUI_EVENT_CLOSE, "Exit")

I thought that that would make my GUI simply exit when the window was closed. However nothing happened!

I guess that the reason is that Exit is not really a function and what I was trying to do is to "evaluate" "Exit" when the GUI_EVENT_CLOSE was received.

I understand the current limitation, but it would be great if something like this was possible. In fact it would be great if we could put any expression as the "function" argument and that the expression would simply be evaluated upon reception of the event as it would be when calling the "Eval" function.

With this change for instance it would be possible to do:

GuiSetOnEvent($GUI_EVENT_CLOSE, "Exit 4")

That is, directly ask the function to exit giving a certain exit code.

I know that I could simply create a function which would call "Exit 4" but calling Eval on the funcition string seems a pretty natural and simple syntax. Also it would avoid the need to define a funciton per gui element when using the event mode.

Cheers,

Angel

Link to comment
Share on other sites

Hi,

while trying to write a GUI I tried to do the following:

    GuiSetOnEvent($GUI_EVENT_CLOSE, "Exit")

I thought that that would make my GUI simply exit when the window was closed. However nothing happened!

I guess that the reason is that Exit is not really a function and what I was trying to do is to "evaluate" "Exit" when the GUI_EVENT_CLOSE was received.

I understand the current limitation, but it would be great if something like this was possible. In fact it would be great if we could put any expression as the "function" argument and that the expression would simply be evaluated upon reception of the event as it would be when calling the "Eval" function.

With this change for instance it would be possible to do:

  GuiSetOnEvent($GUI_EVENT_CLOSE, "Exit 4")

That is, directly ask the function to exit giving a certain exit code.

I know that I could simply create a function which would call "Exit 4" but calling Eval on the funcition string seems a pretty natural and simple syntax. Also it would avoid the need to define a funciton per gui element when using the event mode.

Cheers,

Angel

<{POST_SNAPBACK}>

exit is a function but not a user function so it cannot be called by the SetOnEvent :)
Link to comment
Share on other sites

Yeah, create a function that calls exit.

GuiSetOnEvent($GUI_EVENT_CLOSE, "ExitMe")
Func ExitMe()
  Exit
EndFunc

<{POST_SNAPBACK}>

I know, and that is what I did. But it forces you to add lots of functions when you could do the work much more easilly if you could put any string in there and have it evaluated with "Eval".

For instance, not being able to call "Exit" directly means that you always need to create a function to be able to close the window when you click on the "close" button.

Angel

Link to comment
Share on other sites

See, this is why somebody invented include files.

; GUI.au3
Func OnExit()
    Exit
EndFunc

Func GuiWaitClose($hWnd)
    While WinExists($hWnd)
        Sleep(25)
    Wend
EndFunc

Now, when you write a GUI script, include that file and you can now reference the functions and use them over and over. This is a scripting language, after-all, people are allowed to write and re-use their own code.

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