Sign in to follow this  
Followers 0
danielp

Problems when using multiple GUIs

4 posts in this topic

Hey! big problem for me, but no problem for u! :)

Here is some code opening one gui with button for second one. i am using hide/show for my guis. no problem so far...

is there a way to change the behaviour for "$GUI_EVENT_CLOSE" of my second gui (ONLY SECOND). script should not exit on click.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 633, 449, 192, 124)
$Button1 = GUICtrlCreateButton("open Gui2", 248, 200, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)

$Form2 = GUICreate("Form2", 179, 142, 292, 224)
$Label1 = GUICtrlCreateLabel("2222222", 64, 48, 58, 17)
$Button2 = GUICtrlCreateButton("Close Gui2", 48, 72, 75, 25, $WS_GROUP)
GUISetState(@SW_HIDE)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE 
            Exit
    

        Case $Button1
                GUISetState(@SW_SHOW,$Form2)    
            Case $Button2
                    GUISetState(@SW_HIDE,$Form2)    
    EndSwitch
WEnd

Thanks a lot

Share this post


Link to post
Share on other sites



danielp,

Look in the Help file for GUIGetMsg and study the use of the "advanced" parameter. By using it you can tell which GUI is responding and so decide whether to exit the script or just hide the GUI.

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

#3 ·  Posted (edited)

Sry for stupid question... :party:

You are right! sometimes the helpfile is your best friend...

on the second look i decided to use eventmode. should be the best way for me.

because i had little probs understanding it: here is my working code :)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1) 


$Form1 = GUICreate("Form1", 633, 449, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")
$btnOpenForm2 = GUICtrlCreateButton("open Gui2", 248, 200, 75, 25, $WS_GROUP)
GUICtrlSetOnEvent($btnOpenForm2, "btnOpenForm2_click")
GUISetState(@SW_SHOW)

$Form2 = GUICreate("Form2", 179, 142, 292, 224)
GUISetOnEvent($GUI_EVENT_CLOSE, "btnCloseForm2_click")
$Label1 = GUICtrlCreateLabel("2222222", 64, 48, 58, 17)
$btnCloseForm2 = GUICtrlCreateButton("Close Gui2", 48, 72, 75, 25, $WS_GROUP)
GUICtrlSetOnEvent($btnCloseForm2, "btnCloseForm2_click")
GUISetState(@SW_SHOW)

Func btnOpenForm2_click()
    GUISetState(@SW_SHOW,$Form2)
EndFunc

Func btnCloseForm2_click()
    GUISetState(@SW_HIDE,$Form2)
EndFunc

Func CLOSE()
    Exit
EndFunc

While 1
    Sleep(100)
Wend

.

Edited by danielp

Share this post


Link to post
Share on other sites

danielp,

Glad you solved it yourself - always more satisfying that way. :-)

For interest, here is some code showing how to use the "advanced" parameter with GUIGetMsg():

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 633, 449, 192, 124)
$btnOpenForm2 = GUICtrlCreateButton("open Gui2", 248, 200, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)

$Form2 = GUICreate("Form2", 179, 142, 292, 224)
$Label1 = GUICtrlCreateLabel("2222222", 64, 48, 58, 17)
$btnCloseForm2 = GUICtrlCreateButton("Close Gui2", 48, 72, 75, 25, $WS_GROUP)
GUISetState(@SW_HIDE)

While 1
    ; Use the advanced parameter to get an array of information
    $aMsg = GUIGetMsg(1)
    ; The [0] element of the array is the Event/ControlID
    Switch $aMsg[0]
        Case $btnOpenForm2
            GUISetState(@SW_SHOW,$Form2)
        Case $btnCloseForm2
            GUISetState(@SW_HIDE,$Form2)
        Case $GUI_EVENT_CLOSE
            ; The [1] element of the array is the window handle
            If $aMsg[1] = $Form2 Then
                GUISetState(@SW_HIDE,$Form2)
            Else
                Exit
            EndIf
    EndSwitch
Wend

It may come in handy some time. ;-)

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