Sign in to follow this  
Followers 0
SHAHRAM

GUI in function

6 posts in this topic

#1 ·  Posted (edited)

I have a GUI which at some point calls a function which will create another GUI,

I am using OnEventMode in my script , but I can't use it in/after the 2nd GUI,

here is a sample script,

How can I make it work?

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

$win1 = GUICreate("Win 1", 250, 70,-1,-1,$WS_CAPTION)
GUICtrlCreateLabel("This is win1", 10, 10)
$win = GUICtrlCreateButton("win2", 40, 40,80)
GUICtrlSetOnEvent(-1, "win2")
$ok = GUICtrlCreateButton("Ok", 140, 40,80)
GUICtrlSetOnEvent(-1, "ok")
GUISetState(@SW_SHOW)
While 1
  Sleep(1000)
WEnd


Func ok()
    Exit
EndFunc

Func win2()

$win2 = GUICreate("Win 2", 250, 70,-1,-1,$WS_CAPTION)
GUICtrlCreateLabel("This is win2", 10, 10)
$ok = GUICtrlCreateButton("Ok", 100, 40,80)
GUICtrlSetOnEvent(-1, "ok")
GUISetState(@SW_SHOW)
While 1
  Sleep(1000)
WEnd

EndFunc
Edited by SHAHRAM

Share this post


Link to post
Share on other sites



Remove the loop in the function and then try executing the script.

Share this post


Link to post
Share on other sites

it's strange,

it worked in this simple script,

but I have a little more script which does some other functions before getting to the 2nd window, and the window disapears immediately, the reason i put the sleep there,

I will try to see if I can find why the 2nd window dispears immediately without the sleep in the function?????

Share this post


Link to post
Share on other sites

The variable is expiring. When you declare a variable in local scope, it is destroyed when the function ends. The GUI code in AutoIt must have automatic cleanup routines.

Share this post


Link to post
Share on other sites

I will try to see if I can find why the 2nd window dispears immediately without the sleep in the function?????

As for the loop in the function, when you call the function, the 2nd Gui is created and then it gets trapped in the loop with the Sleep. This means that control is never returned from the function which the OnEvent message system is waiting for. The result is an unresponsive Gui that accepts no messages as the loop is never ending within the function.

Share this post


Link to post
Share on other sites

Remove the loop in the function and then try executing the script.

Thanks,

found the problem,

I had an extra "exit" somwehre causing just a simple exit after the 2nd GUI,

problem solved.

The variable is expiring. When you declare a variable in local scope, it is destroyed when the function ends. The GUI code in AutoIt must have automatic cleanup routines.

thanx

I am aware of that.

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  
Followers 0