Jump to content
Sign in to follow this  
kizsdet

Help with two GUI

Recommended Posts

kizsdet

gui1()

func gui1()

$gui1 = guicreate("Gui 1",200,200,-1,-1)
$button1 = GUICtrlCreateButton("Show Gui 1",20,20,40,20)
$button2= GUICtrlCreateButton("Msgbox",20,40,40,20)
GUISetState()


while 1
    $msg = GUIGetMsg()
if $msg = -3 Then
    ExitLoop
ElseIf $msg = $button1 Then
    gui2()
ElseIf $msg = $button2 Then
    msgbox("","msgbox","test")
EndIf
WEnd


EndFunc

func gui2()

$gui2= guicreate("Gui 2",200,200,-1,-1)
$button3 = GUICtrlCreateButton("Button1",20,20,40,20)
GUISetState()


while 1
    $msg2 = GUIGetMsg()
if $msg2 = -3 Then
    GUIDelete("$gui1")
    Return

EndIf
WEnd


EndFunc

hello, im new to autoit and have a simple problem with multiple gui's..

the problem here is when i press show gui button from gui1,gui2 will be visible and while gui 2 is still visible button2 from gui1 which opens a messagebox will not work until i close gui2..

can you correct this code that even if gui2 is visible, the buttons from gui1 will still work..

thanks in advance..

Share this post


Link to post
Share on other sites
Melba23

kizsdet,

You need to use GUIGetMsg with the advanced parameter so you can detect which GUI is sending the messages. :mellow:

Look at this:

#include <GUIConstantsEx.au3>

Global $gui2 = 9999, $button3 = 9999

gui1()

Func gui1()

    $gui1 = GUICreate("Gui 1", 200, 200, -1, -1)
    $button1 = GUICtrlCreateButton("Show Gui 1", 20, 20, 40, 20)
    $button2 = GUICtrlCreateButton("Msgbox", 20, 40, 40, 20)
    GUISetState()

    While 1
        $aMsg = GUIGetMsg(1) ; Use advanced parameter to get array
        Switch $aMsg[1] ; check which GUI sent the message
            Case $gui1
                Switch $aMsg[0] ; Now check for the messages for $gui1
                    Case $GUI_EVENT_CLOSE
                        ExitLoop
                    Case $button1
                        GUICtrlSetState($button1, $GUI_DISABLE)
                        gui2()
                    Case $button2
                        MsgBox("", "msgbox", "test from gui1")
                EndSwitch
            Case $gui2
                Switch $aMsg[0] ; Now check for the messages for $gui2
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($gui2)
                        GUICtrlSetState($button1, $GUI_ENABLE)
                    Case $button3
                        MsgBox("", "msgbox", "test from gui2")
                EndSwitch
        EndSwitch
    WEnd

EndFunc   ;==>gui1

Func gui2()

    $gui2 = GUICreate("Gui 2", 200, 200, -1, -1)
    $button3 = GUICtrlCreateButton("Button1", 20, 20, 40, 20)
    GUISetState()

EndFunc   ;==>gui2

I have added a few lines:

- The button is disabled once $gui2 is created and reenabled once it is deleted.

- I used the GUIConstantsEx include file to do the above, so I changed -3 to $GUI_EVENT_CLOSE.

- I made the button on $gui2 do something so you can see how it works.

I hope this helps - ask if anything is unclear. :P

m23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
kizsdet

Thanks Melba23..it works fine for me now..maybe example like this which uses advance parameter of guigetmsg should be included in the help file.

may i ask why gui2 and button3 was declared with a value of 9999? can i assign any value with it??

hmm, another question here is should it always be array [1] when checking for the gui which sents the message and array[0] for controls??

thanks again.. :mellow:

Share this post


Link to post
Share on other sites
Melba23

kizsdet,

why gui2 and button3 was declared with a value of 9999?

You need these variables to be Global in scope (that means available to all functions in the script). You only create the controls themselves within the $gui2 function, so they would be Local (only available within that function) unless we declare them earlier. We need to check the value of the variables on every pass of the loop. If we do not give a dummy value to these variables, they will fire each time - not what we want at all. :P You can use any number - as long as it has not been used by any other GUI/control. I tend to use 9999 all the time - I have yet to create a GUI with 10000 controls. :party:

should it always be array [1] when checking for the gui which sents the message and array[0] for controls??

That is what it says in the Help file! :mellow:

All clear?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
kizsdet

thanks for immediate reply. i think im gonna love autoit scripting and the people around here. thanks buddy. things are now clear.

Edited by kizsdet

Share this post


Link to post
Share on other sites
Melba23

kizsdet,

The command in question is GUIGetMsg, so I would look on that page if I were you! :mellow:

GUIGetMsg Help page

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.