Jump to content
roeselpi

stoping a complete reload of a main gui window

Recommended Posts

hello,

i have made a dual gui window that works the way i would like it to... allmost. i have a bug in it, otherwise i would not be asking question(s) here:

here is my code at present. (it is just a basic mockup without any features at all):

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

general()
$show=0
dialogbox(0)

Func general()
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 203, 137, -1, -1)
$MenuItem2 = GUICtrlCreateMenu("MenuItem2")
$MenuItem1 = GUICtrlCreateMenuItem("MenuItem1", $MenuItem2)
$Edit1 = GUICtrlCreateEdit("", 24, 32, 161, 57)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem1
            ;GUISetState($form1, $GUI_DISABLE)
            $show = 1
            dialogbox(1)

    EndSwitch
WEnd
EndFunc

Func dialogbox($show)
#Region ### START Koda GUI section ### Form=
Global $Form2 = GUICreate("Form2", 365, 136, -1, -1)
$Combo1 = GUICtrlCreateCombo("Combo1", 32, 24, 297, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Button1 = GUICtrlCreateButton("Button1", 32, 88, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 256, 88, 75, 25)
If $show = 1 Then
    GUISetState(@SW_SHOW)
    ElseIf $show = 0 Then
GUISetState(@SW_HIDE)
EndIf
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            hidedialogbox()
    EndSwitch
WEnd
EndFunc

Func hidedialogbox()
    GUISetState(@SW_HIDE)
    general()
EndFunc

here is what happens: when the script is launched both gui are created and the second gui is just "hidden" until it is called via menu, then it is displayed. when it second gui is closed it is just hidden again, which is what i want but now comes the tricky part. when it is being closed it reloads the first gui with the default values and that is what i would like to avoid. but if i take the general() command out of the hidedialogbox() function then i can no longer call up the second gui and i can not close the main gui either.

yes, i have read the tutorials on multiple gui interfaces but the one which impressed me most of all was this one from @Melba23 

 

 

because it is perfect in every way. you can interact with all gui's and open and close them like you want and have them do stuff like you want, so that was my goal, only difference is that i have only two gui's and not so many but the genal idea was so great of having the gui all generated at the beginning and just hiding them instead of killing them and only when the main gui is closed getting them all closed.

that was my plan but somehow i am getting it wrong somewhere in a modified rebuild stripped down to the basic elements: 

create at launch but hide until needed and rehide when not needed and reshow when needed, etc. 

what am i missing?

kind regards

Share this post


Link to post
Share on other sites

roeselpi,

You are not redisplaying the GUIs - you are recreating them each time, which is why you get the original values each time you "redisplay" the main GUI. Plus I am pretty sure you are getting into some serious recursion with all those calls - which usually ends in tears.

You need to do something like this:

#include <GUIConstantsEx.au3>

; Create main GUI
$Form1 = GUICreate("Form1", 203, 137, -1, -1)
$MenuItem2 = GUICtrlCreateMenu("MenuItem2")
$MenuItem1 = GUICtrlCreateMenuItem("MenuItem1", $MenuItem2)
$Edit1 = GUICtrlCreateEdit("", 24, 32, 161, 57)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)

; Create and hide dialog
$Form2 = GUICreate("Form2", 365, 136, -1, -1)
$Combo1 = GUICtrlCreateCombo("Combo1", 32, 24, 297, 25)
$Button1 = GUICtrlCreateButton("Button1", 32, 88, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 256, 88, 75, 25)
GUISetState(@SW_HIDE)

; Now do everything in your idle loop
While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $Form1
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE ; Exit the whole script
                    Exit
                Case $MenuItem1 ; Disable main GUI and show dialog
                    GUISetState($Form1, $GUI_DISABLE)
                    GUISetState(@SW_SHOW, $Form2)
            EndSwitch

        Case $Form2
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE ; Hide dialog and reenable main GUI
                    GUISetState(@SW_HIDE, $Form2)
                    GUISetState($Form1, $GUI_ENABLE)

            EndSwitch
    EndSwitch
WEnd

No functions, no recursive calls - and the same GUIs are used each time. Please ask if you have any questions.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

hi, 

it works like a charm, thank you very much. i do however have some questions, even if they may seem a bit stupid:

i have a strange thing (a good thing, but it is strange):

Case $Form2
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE ; Hide dialog and reenable main GUI
                    GUISetState(@SW_HIDE, $Form2)
                    GUISetState($Form1, $GUI_ENABLE)
                Case $Button1
                    $editboxtext = GUICtrlRead($Edit1)
                    msgbox(0,0,$editboxtext)

first of all: i did not think that i can 'cross-call' the content of the edit box (main gui) from within the second gui because it is like calling upon data from a second open file, but it works and that is fantastic. but now to my question: when i enter text into the edit box and call the second gui with the menu, then i get the hidden gui and the first gui should really be disabled as far as i can tell, but if i move the second gui out of the way i can still continue editing the text in the editbox. after i have finished the editing i used the menu again to call the second gui (which was still visable the whole time) and it did not jump to or reactivate the second gui, but however if i use the button as specified above then i did still get the new version of the content of the editbox even though i never closed the second gui. 

that results in the question: how is the data passed from gui to gui and how many times is it passed or rather more how does the script determine that content of the first gui has been altered to resend the information although it has been sent before?

as i say, this is great but it puzzles me somewhat.

this is even better than i had hoped it would be.

really great. thanks a million for that

kind regards 

Share this post


Link to post
Share on other sites

roeselpi,

There is no mystery! GUIs within the same script are not separate and you can usually communicate between them without problem - the only problem being any limitations set by the scope of the variables concerned (see the using Global, Local, Static and ByRef tutorial in the Wiki for more detail. So you can quite easily read the content of the editbox in one GUI when you action a button in another.

However, the script does not automatically determine that the content of the editbox has changed - you force the read by auctioning the button and running the GUICtrlRead command. You can check dynamically, but that requires a Windows message handler - see here for an example.

If you action the menu item to show the second GUI while it is visible then of course nothing will happen - the GUI is already visible and will remain so. The fact that you can further edit the content of the editbox is due to an error on my part - I used the incorrect syntax to disable the main GUI, so if you would prefer the main GUI to be disabled when the second is visible then use this code:

#include <GUIConstantsEx.au3>

; Create main GUI
$Form1 = GUICreate("Form1", 203, 137, -1, -1)
$MenuItem2 = GUICtrlCreateMenu("MenuItem2")
$MenuItem1 = GUICtrlCreateMenuItem("MenuItem1", $MenuItem2)
$Edit1 = GUICtrlCreateEdit("", 24, 32, 161, 57)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)

; Create and hide dialog
$Form2 = GUICreate("Form2", 365, 136, -1, -1)
$Combo1 = GUICtrlCreateCombo("Combo1", 32, 24, 297, 25)
$Button1 = GUICtrlCreateButton("Button1", 32, 88, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 256, 88, 75, 25)
GUISetState(@SW_HIDE)

; Now do everything in your idle loop
While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $Form1
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE ; Exit the whole script
                    Exit
                Case $MenuItem1 ; Disable main GUI and show dialog
                    GUISetState(@SW_DISABLE, $Form1) ; Correct syntax
                    GUISetState(@SW_SHOW, $Form2)
            EndSwitch

        Case $Form2
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE ; Hide dialog and reenable main GUI
                    GUISetState(@SW_HIDE, $Form2)
                    GUISetState(@SW_ENABLE, $Form1) ; Correct syntax
                    WinActivate($Form1) ; Force main GUI to be activated

            EndSwitch
    EndSwitch
WEnd

Any more questions?

M23

.


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

×
×
  • Create New...