Sign in to follow this  
Followers 0
jhinesyo

Autoit with Multiple GUI windows

6 posts in this topic

Problem: I have a main auto it script w/ GUI code. When I launch a function to create an additional GUI window- with other functions, the new GUI window appears and runs as it should, however, when I click the X to close the 2nd GUI window, the whole program terminates- not just the "child" gui window.

Is there some code I should be using to spawn this additional child GUI window and close it without affecting my main program?

I looked through some example code, but I haven't seen anything that matches my specific problem.

thanks!

Share this post


Link to post
Share on other sites



Problem: I have a main auto it script w/ GUI code. When I launch a function to create an additional GUI window- with other functions, the new GUI window appears and runs as it should, however, when I click the X to close the 2nd GUI window, the whole program terminates- not just the "child" gui window.

Is there some code I should be using to spawn this additional child GUI window and close it without affecting my main program?

I looked through some example code, but I haven't seen anything that matches my specific problem.

thanks!

Write a small example that shows your issue (Only because I don't feel like or feel that I should have too to do it myself). The issue can be corrected more than likely with 1 small thing.

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.

Share this post


Link to post
Share on other sites

Hi SmOke_N,

I just found this code example that might suit my needs:

$Form 1 = GuiCreate(...)

..

..

launch function to child gui()

...

...

Func ChildGui()

$Form2 = GuiCreate(.....)

... gui 2 stuff ....

GUISetState(@SW_ENABLE,$Form1)

GUIDelete($Form2)

EndFunc

Write a small example that shows your issue (Only because I don't feel like or feel that I should have too to do it myself). The issue can be corrected more than likely with 1 small thing.

If the above code does not fit the bill, I will be posting my code shortly after,

thanks!

Share this post


Link to post
Share on other sites

Hi SmOke_N,

I just found this code example that might suit my needs:

$Form 1 = GuiCreate(...)

..

..

launch function to child gui()

...

...

Func ChildGui()

$Form2 = GuiCreate(.....)

... gui 2 stuff ....

GUISetState(@SW_ENABLE,$Form1)

GUIDelete($Form2)

EndFunc

If the above code does not fit the bill, I will be posting my code shortly after,

thanks!

I think what's needed is a small example piece of code which can be run to show the problem. Something we could copy, paste and run without having to write anything.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

You have to work with both (or all) of the windows at once, just as a basic guideline. So when you close a window, instead of using "Exit" (which is what I usually do), just use GuiDelete and keep running through the program.

To see which window you received the Close command from, use "If WinGetActive($myGui)" and delete it. If both windows are deleted, then exit the program. Most child windows need to be defined, but hey, working from the ground up is the way for me!

Share this post


Link to post
Share on other sites

Problem: I have a main auto it script w/ GUI code. When I launch a function to create an additional GUI window- with other functions, the new GUI window appears and runs as it should, however, when I click the X to close the 2nd GUI window, the whole program terminates- not just the "child" gui window.

Is there some code I should be using to spawn this additional child GUI window and close it without affecting my main program?

I looked through some example code, but I haven't seen anything that matches my specific problem.

thanks!

Here's an example using the "advanced" parameter defined in GUIGetMsg(). In the example, I've just set it to hide the child window when its "X" is closed, however, if you don't need the form again, you could use GUIDelete() instead there.

#include <GUIConstants.au3>
$ParentGUIWidth = 400
$ParentGUIHeight = 500
$ChildGUIWidth = 300
$ChildGUIHeight = 400

$ParentGUI = GUICreate("Parent GUI", $ParentGUIWidth, $ParentGUIHeight, (@DesktopWidth - $ParentGUIWidth) / 2, (@DesktopHeight - $ParentGUIHeight) / 2)
$ButtonParentMsg = GUICtrlCreateButton("Click me", 100, 100, 50, 20)
$ButtonOpenChild = GUICtrlCreateButton("Open Child Window", 100, 200, 100, 20)

$ChildGUI = GUICreate("Child GUI", $ChildGUIWidth, $ChildGUIHeight, (@DesktopWidth - $ChildGUIWidth) / 2, (@DesktopHeight - $ChildGUIHeight) / 2)
$ButtonChildMsg = GUICtrlCreateButton("Click me", 100, 100, 50, 20)
GUISetState(@SW_SHOW,$ParentGUI)

While 1
    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = $GUI_EVENT_CLOSE
            If $msg[1] = $ParentGUI Then
                Exit
            ElseIf $msg[1] = $ChildGUI Then
                GUISetState(@SW_ENABLE,$ParentGUI)
                GUISetState(@SW_HIDE,$ChildGUI)
            EndIf
        Case $msg[0] = $ButtonOpenChild
            GUISetState(@SW_DISABLE,$ParentGUI)
            GUISetState(@SW_SHOW,$ChildGUI)
        Case $msg[0] = $ButtonParentMsg
            _ParentMsgBox()
        Case $msg[0] = $ButtonChildMsg
            _ChildMsgBox()
    EndSelect
WEnd

Func _ParentMsgBox()
    MsgBox(64, "Parent Window MsgBox", "This is from the parent window")
EndFunc

Func _ChildMsgBox()
    MsgBox(64, "Child Window MsgBox", "This is from the child window")
EndFunc

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

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