Sign in to follow this  
Followers 0
katoNkatoNK

GUI Handle Array

3 posts in this topic

#1 ·  Posted (edited)

Hi all.

I've gotten fairly close to what i am trying to do but i am pretty sure that there is a more efficient way to create a gui from the same function.

The main gui doesn't change at all, but the hGUI2/3 array is used to create the 2nd and 3rd gui after the currently active gui is deleted when '$bGUI2' or '$bGUI3' is pressed.

The reason i am trying to do this is because in my main script gui3 has one less control and also used for something different than gui2.

Here's a working example of how far i have managed to get..it's a bit messy.

Any help is appreciated.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

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

Global $hGUI, $bGUI2, $bGUI3, $iMsg, $hGlobalStatus, $hGlobalHandle
Global $hHandle2[2] = [1000], $hStatus2[2] = [-1]
Global $hHandle3[2] = [1000], $hStatus3[2] = [-1]

$hGUI = GUICreate("hGUI", 200, 300, -1, -1)
$bGUI2 = GUICtrlCreateButton("hGUI2", 10, 10, 40, 22.5)
$bGUI3 = GUICtrlCreateButton("hGUI3", 60, 10, 40, 22.5)

GUISetState(@SW_SHOW, $hGUI)

While 1
    $iMsg = GUIGetMsg(1)
    Switch $iMsg[1]
        Case $hGUI
            Switch $iMsg[0]
                Case $bGUI2
                    If IsArray($hGlobalStatus) Then
                        If $hGlobalStatus[0] = 1 Then
                            GUIDelete($hGlobalHandle[0])
                            $hGlobalStatus[0] = -1
                            $hGlobalHandle[0] = 1000
                        EndIf
                    EndIf
                    GUICtrlSetState($bGUI3, $GUI_ENABLE)
                    $hGlobalHandle = _hHandle($hHandle2, "GUI 2")
                    $hStatus2[0] = 1
                    $hGlobalStatus = $hStatus2
                    GUICtrlSetState($bGUI2, $GUI_DISABLE)
                Case $bGUI3
                    If IsArray($hGlobalStatus) Then
                        If $hGlobalStatus[0] = 1 Then
                            GUIDelete($hGlobalHandle[0])
                            $hGlobalStatus[0] = -1
                            $hGlobalHandle[0] = 1000
                        EndIf
                    EndIf
                    GUICtrlSetState($bGUI2, $GUI_ENABLE)
                    $hGlobalHandle = _hHandle($hHandle3, "GUI 3")
                    $hStatus3[0] = 1
                    $hGlobalStatus = $hStatus3
                    GUICtrlSetState($bGUI3, $GUI_DISABLE)
                Case $GUI_EVENT_MINIMIZE
                    If $hGlobalStatus[0] = 1 Then
                        GUIDelete($hGlobalHandle[0])
                        $hGlobalStatus[0] = -1
                        $hGlobalHandle[0] = 1000
                    EndIf
                    GUICtrlSetState($bGUI2, $GUI_ENABLE)
                    GUICtrlSetState($bGUI3, $GUI_ENABLE)
                Case $GUI_EVENT_CLOSE
                    Exit
            EndSwitch
        Case $hHandle2[0]
            Switch $iMsg[0]
                Case $hHandle2[1]
                    MsgBox(0, $hHandle3[1], "GUI 2 - " & $hHandle3[0])
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hHandle2[0])
                    $hStatus2[0] = -1
                    GUICtrlSetState($bGUI2, $GUI_ENABLE)
            EndSwitch
        Case $hHandle3[0]
            Switch $iMsg[0]
                Case $hHandle3[1]
                    MsgBox(0, $hHandle3[1], "GUI 3 - " & $hHandle3[0])
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hHandle3[0])
                    $hStatus3[0] = -1
                    GUICtrlSetState($bGUI3, $GUI_ENABLE)
            EndSwitch
    EndSwitch
    If IsArray($hGlobalStatus) Then
        If $hGlobalStatus[0] = 1 Then ControlEnable("", "", $hGlobalHandle[1])
    EndIf
WEnd

Func _hHandle(ByRef $hGlobalHandle, $Test)
    $hGlobalHandle[0] = GUICreate($Test, 150, 100, -1, -1, $WS_SYSMENU)
    $hGlobalHandle[1] = GUICtrlCreateButton($Test, 60, 10, 40, 22.5)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState(@SW_SHOW, $hGlobalHandle[0])
    Return $hGlobalHandle
EndFunc   ;==>_hGUI3

P.S. Please keep the advanced parameter on GUIGetMsg() as i need this in my main script.

Edit:

I hope i explained it clear enough..

The main goal i guess is to 'toggle' the array to match the active gui so the correct case/switch statement is triggered.

Edit2:

Here's my attempt at combining hGUI2 & hGUI3 that works.. am i doing it correctly?

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

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

Global $hGUI, $bGUI2, $bGUI3, $iMsg, $hHandle = "", $hStatus[2] = [-1], $hGUI2[2] = [1000], $hGUI3[2] = [1000]

$hGUI = GUICreate("hGUI", 200, 300, -1, -1)
$bGUI2 = GUICtrlCreateButton("hGUI2", 10, 10, 40, 22.5)
$bGUI3 = GUICtrlCreateButton("hGUI3", 60, 10, 40, 22.5)

GUISetState(@SW_SHOW, $hGUI)

While 1
    $iMsg = GUIGetMsg(1)
    Switch $iMsg[1]
        Case $hGUI  ;main gui
            Switch $iMsg[0]
                Case $bGUI2
                    If IsArray($hStatus) Then
                        If $hStatus[0] = 1 Then
                            GUIDelete($hHandle[0])
                            $hStatus[0] = -1
                        EndIf
                    EndIf
                    GUICtrlSetState($bGUI3, $GUI_ENABLE)
                    $hGUI2 = _hHandle("GUI 2")
                    $hStatus[0] = 1
                    GUICtrlSetState($bGUI2, $GUI_DISABLE)
                    $hHandle = $hGUI2
                Case $bGUI3
                    If IsArray($hStatus) Then
                        If $hStatus[0] = 1 Then
                            GUIDelete($hHandle[0])
                            $hStatus[0] = -1
                        EndIf
                    EndIf
                    GUICtrlSetState($bGUI2, $GUI_ENABLE)
                    $hGUI3 = _hHandle("GUI 3")
                    $hStatus[0] = 1
                    GUICtrlSetState($bGUI3, $GUI_DISABLE)
                    $hHandle = $hGUI3
                Case $GUI_EVENT_MINIMIZE
                    If $hStatus[0] = 1 Then
                        GUIDelete($hHandle[0])
                        $hStatus[0] = -1
                    EndIf
                    $hHandle = ""
                    GUICtrlSetState($bGUI2, $GUI_ENABLE)
                    GUICtrlSetState($bGUI3, $GUI_ENABLE)
                Case $GUI_EVENT_CLOSE
                    Exit
            EndSwitch
        Case $hGUI2[0]  ;2ng gui
            Switch $iMsg[0]
                Case $hGUI2[1]
                    MsgBox(0, $hGUI2[1], "GUI 2 - " & $hGUI2[0])
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hGUI2[0])
                    $hStatus[0] = -1
                    $hHandle = ""   ;reset to default
                    GUICtrlSetState($bGUI2, $GUI_ENABLE)
            EndSwitch
        Case $hGUI3[0] ;3rd gui
            Switch $iMsg[0]
                Case $hGUI3[1]
                    MsgBox(0, $hGUI3[1], "GUI 3 - " & $hGUI3[0])
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hGUI3[0])
                    $hStatus[0] = -1
                    $hHandle = ""   ;reset to default
                    GUICtrlSetState($bGUI3, $GUI_ENABLE)
            EndSwitch
    EndSwitch
    If IsArray($hStatus) Then
        If $hStatus[0] = 1 Then ControlEnable("", "", $hHandle[1])
    EndIf
WEnd

Func _hHandle($Test)
    Local $hArray[2]
    $hArray[0] = GUICreate($Test, 150, 100, -1, -1, $WS_SYSMENU)
    $hArray[1] = GUICtrlCreateButton($Test, 60, 10, 40, 22.5)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState(@SW_SHOW, $hArray[0])
    Return $hArray
EndFunc   ;==>_hGUI3
Edited by katoNkatoNK

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

i still dont understand what you want... i guess is a function to create the GUIs, and set one of those GUIs with one less control.

You can add a parameter on the function and check in the function... if that parameter is true then create the control if NOT then don´t create the control

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

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

Global $hGUI, $bGUI2, $bGUI3, $iMsg, $hGlobalStatus, $hGlobalHandle
Global $hHandle2[2] = [1000], $hStatus2[2] = [-1]
Global $hHandle3[2] = [1000], $hStatus3[2] = [-1]

$hGUI = GUICreate("hGUI", 200, 300, -1, -1)
$bGUI2 = GUICtrlCreateButton("hGUI2", 10, 10, 40, 22.5)
$bGUI3 = GUICtrlCreateButton("hGUI3", 60, 10, 40, 22.5)

GUISetState(@SW_SHOW, $hGUI)

While 1
    $iMsg = GUIGetMsg(1)
    Switch $iMsg[1]
        Case $hGUI
            Switch $iMsg[0]
                Case $bGUI2
                    If IsArray($hGlobalStatus) Then
                        If $hGlobalStatus[0] = 1 Then
                            GUIDelete($hGlobalHandle[0])
                            $hGlobalStatus[0] = -1
                            $hGlobalHandle[0] = 1000
                        EndIf
                    EndIf
                    GUICtrlSetState($bGUI3, $GUI_ENABLE)
                    $hGlobalHandle = _hHandle($hHandle2, "GUI 2",true)
                    $hStatus2[0] = 1
                    $hGlobalStatus = $hStatus2
                    GUICtrlSetState($bGUI2, $GUI_DISABLE)
                Case $bGUI3
                    If IsArray($hGlobalStatus) Then
                        If $hGlobalStatus[0] = 1 Then
                            GUIDelete($hGlobalHandle[0])
                            $hGlobalStatus[0] = -1
                            $hGlobalHandle[0] = 1000
                        EndIf
                    EndIf
                    GUICtrlSetState($bGUI2, $GUI_ENABLE)
                    $hGlobalHandle = _hHandle($hHandle3, "GUI 3", false)
                    $hStatus3[0] = 1
                    $hGlobalStatus = $hStatus3
                    GUICtrlSetState($bGUI3, $GUI_DISABLE)
                Case $GUI_EVENT_MINIMIZE
                    If $hGlobalStatus[0] = 1 Then
                        GUIDelete($hGlobalHandle[0])
                        $hGlobalStatus[0] = -1
                        $hGlobalHandle[0] = 1000
                    EndIf
                    GUICtrlSetState($bGUI2, $GUI_ENABLE)
                    GUICtrlSetState($bGUI3, $GUI_ENABLE)
                Case $GUI_EVENT_CLOSE
                    Exit
            EndSwitch
        Case $hHandle2[0]
            Switch $iMsg[0]
                Case $hHandle2[1]
                    MsgBox(0, $hHandle3[1], "GUI 2 - " & $hHandle3[0])
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hHandle2[0])
                    $hStatus2[0] = -1
                    GUICtrlSetState($bGUI2, $GUI_ENABLE)
            EndSwitch
        Case $hHandle3[0]
            Switch $iMsg[0]
                Case $hHandle3[1]
                    MsgBox(0, $hHandle3[1], "GUI 3 - " & $hHandle3[0])
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hHandle3[0])
                    $hStatus3[0] = -1
                    GUICtrlSetState($bGUI3, $GUI_ENABLE)
            EndSwitch
    EndSwitch
    If IsArray($hGlobalStatus) Then
        If $hGlobalStatus[0] = 1 Then ControlEnable("", "", $hGlobalHandle[1])
    EndIf
WEnd

Func _hHandle(ByRef $hGlobalHandle, $Test,$Control)
    $hGlobalHandle[0] = GUICreate($Test, 150, 100, -1, -1, $WS_SYSMENU)
    If $Control = true then $hGlobalHandle[1] = GUICtrlCreateButton($Test, 60, 10, 40, 22.5)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState(@SW_SHOW, $hGlobalHandle[0])
    Return $hGlobalHandle
EndFunc   ;==>_hGUI3

this can be inproved, putting as parameter of the function the ammount of buttons you want... and you can add another function to set the event for every button... right now i dont have the time to do it... im going to eat something

Edited by monoscout999

Share this post


Link to post
Share on other sites

i still dont understand what you want... i guess is a function to create the GUIs, and set one of those GUIs with one less control.

You can add a parameter on the function and check in the function... if that parameter is true then create the control if NOT then don´t create the control

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

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

Global $hGUI, $bGUI2, $bGUI3, $iMsg, $hGlobalStatus, $hGlobalHandle
Global $hHandle2[2] = [1000], $hStatus2[2] = [-1]
Global $hHandle3[2] = [1000], $hStatus3[2] = [-1]

$hGUI = GUICreate("hGUI", 200, 300, -1, -1)
$bGUI2 = GUICtrlCreateButton("hGUI2", 10, 10, 40, 22.5)
$bGUI3 = GUICtrlCreateButton("hGUI3", 60, 10, 40, 22.5)

GUISetState(@SW_SHOW, $hGUI)

While 1
    $iMsg = GUIGetMsg(1)
    Switch $iMsg[1]
        Case $hGUI
            Switch $iMsg[0]
                Case $bGUI2
                    If IsArray($hGlobalStatus) Then
                        If $hGlobalStatus[0] = 1 Then
                            GUIDelete($hGlobalHandle[0])
                            $hGlobalStatus[0] = -1
                            $hGlobalHandle[0] = 1000
                        EndIf
                    EndIf
                    GUICtrlSetState($bGUI3, $GUI_ENABLE)
                    $hGlobalHandle = _hHandle($hHandle2, "GUI 2",true)
                    $hStatus2[0] = 1
                    $hGlobalStatus = $hStatus2
                    GUICtrlSetState($bGUI2, $GUI_DISABLE)
                Case $bGUI3
                    If IsArray($hGlobalStatus) Then
                        If $hGlobalStatus[0] = 1 Then
                            GUIDelete($hGlobalHandle[0])
                            $hGlobalStatus[0] = -1
                            $hGlobalHandle[0] = 1000
                        EndIf
                    EndIf
                    GUICtrlSetState($bGUI2, $GUI_ENABLE)
                    $hGlobalHandle = _hHandle($hHandle3, "GUI 3", false)
                    $hStatus3[0] = 1
                    $hGlobalStatus = $hStatus3
                    GUICtrlSetState($bGUI3, $GUI_DISABLE)
                Case $GUI_EVENT_MINIMIZE
                    If $hGlobalStatus[0] = 1 Then
                        GUIDelete($hGlobalHandle[0])
                        $hGlobalStatus[0] = -1
                        $hGlobalHandle[0] = 1000
                    EndIf
                    GUICtrlSetState($bGUI2, $GUI_ENABLE)
                    GUICtrlSetState($bGUI3, $GUI_ENABLE)
                Case $GUI_EVENT_CLOSE
                    Exit
            EndSwitch
        Case $hHandle2[0]
            Switch $iMsg[0]
                Case $hHandle2[1]
                    MsgBox(0, $hHandle3[1], "GUI 2 - " & $hHandle3[0])
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hHandle2[0])
                    $hStatus2[0] = -1
                    GUICtrlSetState($bGUI2, $GUI_ENABLE)
            EndSwitch
        Case $hHandle3[0]
            Switch $iMsg[0]
                Case $hHandle3[1]
                    MsgBox(0, $hHandle3[1], "GUI 3 - " & $hHandle3[0])
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hHandle3[0])
                    $hStatus3[0] = -1
                    GUICtrlSetState($bGUI3, $GUI_ENABLE)
            EndSwitch
    EndSwitch
    If IsArray($hGlobalStatus) Then
        If $hGlobalStatus[0] = 1 Then ControlEnable("", "", $hGlobalHandle[1])
    EndIf
WEnd

Func _hHandle(ByRef $hGlobalHandle, $Test,$Control)
    $hGlobalHandle[0] = GUICreate($Test, 150, 100, -1, -1, $WS_SYSMENU)
    If $Control = true then $hGlobalHandle[1] = GUICtrlCreateButton($Test, 60, 10, 40, 22.5)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState(@SW_SHOW, $hGlobalHandle[0])
    Return $hGlobalHandle
EndFunc   ;==>_hGUI3

this can be inproved, putting as parameter of the function the ammount of buttons you want... and you can add another function to set the event for every button... right now i dont have the time to do it... im going to eat something

Thanks for the reply mono, that's kind of what i've been trying to do. Have a look at the updated example ^

The problem now seems to be the monitoring of the controls (i have an 'If' statement enabling/disabling controls in the while loop) while the gui with the one control less is active - this gui 'freezes' once shown and i can only exit on the main gui.

So i added a check to the If statement as well which seems to be holding up..

If IsArray($hStatus) And IsArray ($hHandle) Then
    If $hStatus[0] >= 1 Then
        $hStatus[1] = GUICtrlRead($hHandle[1])  ;Preset Name
        $hStatus[2] = GUICtrlRead($hHandle[2])  ;Status ~ Checkbox of 'Use Adapter'
        $hStatus[3] = GUICtrlRead($hHandle[3])  ;Status ~ Installed Adapter
        $hStatus[4] = GUICtrlRead($hHandle[4])  ;Installed Adapter Name
        If $hStatus[0] = 1 Then $hStatus[5] = GUICtrlRead($hHandle[5])  ;Status ~ Use Installed Adapters current properties (Not in 'SaveAs')
        $hStatus[6] = GUICtrlRead($hHandle[6])  ;Status ~ Custom Adapter
        $hStatus[7] = GUICtrlRead($hHandle[7])  ;Custom Adapter Name
        If $hStatus[2] = $GUI_CHECKED Then
            ControlEnable("", "", $hHandle[3])
            ControlEnable("", "", $hHandle[6])
            If $hStatus[3] = $GUI_CHECKED Then
                ControlEnable("", "", $hHandle[4])
                If $hStatus[0] = 1 Then ControlEnable("", "", $hHandle[5])
                ControlDisable("", "", $hHandle[7])
            ElseIf $hStatus[6] = $GUI_CHECKED Then
                ControlEnable("", "", $hHandle[7])
                ControlDisable("", "", $hHandle[4])
                If $hStatus[0] = 1 Then ControlDisable("", "", $hHandle[5])
            EndIf
        ElseIf $hStatus[2] = $GUI_UNCHECKED Then
            ControlDisable("", "", $hHandle[3])
            ControlDisable("", "", $hHandle[4])
            If $hStatus[0] = 1 Then ControlDisable("", "", $hHandle[5])
            ControlDisable("", "", $hHandle[6])
            ControlDisable("", "", $hHandle[7])
        EndIf
    ElseIf $hStatus[0] = -1 Then
        GUICtrlSetState($New, $GUI_ENABLE)
        GUICtrlSetState($SaveAs, $GUI_ENABLE)
    EndIf
EndIf

I know it might be confusing with all the numbers :huh2: , but apart from adding the checks is this the best thing to have in a While loop?

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