;-- TIME_STAMP   2018-01-25 19:03:55   v 0.1

#Region ;************ Includes ************
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#EndRegion ;************ Includes ************


Global $g_hMainGUI, $g_idButton_C, $g_aChildGUIs[3][10], $g_aGroups[3][2]

Global $g_aDiffGuiColors = [0x667F7F, 0x440000, 0x004400, 0x000044]
Global $g_aSameGuiColors = [0x667F7F, 0x667F7F, 0x667F7F, 0x667F7F]
Global $g_aButtonColors  = [0xC270CD, 0x5F3060, 0xFF8080, 0x7F4040, 0x80FF80, 0x407F40, 0x8080FF, 0x40407F, 0xD0FF00, 0x88B701, 0xA0FF00, 0x58B701]

_Example()

#Tidy_Off
Func _Example()
	#Region - GUI Create
	$g_hMainGUI = GUICreate('MainGUI', 1000, 550, -1, -1, -1, $WS_EX_TOPMOST)
	GUISetBkColor($g_aDiffGuiColors[0], $g_hMainGUI)

	Local $idComboBox = GUICtrlCreateCombo('Wähle eine Gruppe aus...', 10, 10, 980, 25)
	GUICtrlSetData($idComboBox, 'Gruppe 1 anzeigen|Gruppe 2 anzeigen|Gruppe 3 anzeigen')

	Local $idButton_0 = _CreateButton('Hide all child', 10, 40, 980, 25, $g_aButtonColors[0], $g_aButtonColors[1])
	Local $idButton_1 = _CreateButton('Toggle child 1, ignore all other childs',  10, 70, 320, 25, $g_aButtonColors[0], $g_aButtonColors[1])
	Local $idButton_2 = _CreateButton('Toggle child 2, ignore all other childs', 340, 70, 320, 25, $g_aButtonColors[0], $g_aButtonColors[1])
	Local $idButton_3 = _CreateButton('Toggle child 3, ignore all other childs', 670, 70, 320, 25, $g_aButtonColors[0], $g_aButtonColors[1])

	Local $idButton_4 = _CreateButton('Show child 1, hide all other childs',  10, 100, 320, 25, $g_aButtonColors[0], $g_aButtonColors[1])
	Local $idButton_5 = _CreateButton('Hide child 2, show all other childs', 340, 100, 320, 25, $g_aButtonColors[0], $g_aButtonColors[1])
	Local $idButton_6 = _CreateButton('Show child 1, hide child 2, toggle child 3, ignore all other childs', 670, 100, 320, 25, $g_aButtonColors[0], $g_aButtonColors[1])
	$g_idButton_C = _CreateButton('Switch GUI-BkColor', 10, 130, 980, 25, $g_aButtonColors[8], $g_aButtonColors[9])

	Local $sButton_0_Search = 'Show|Hide', $sButton_0_Replace = 'Hide|Show', $aStates_Button_0 = [['?h'], ['?s']], $i0 = 0
	Local $sButton_4_Search = 'Show|hide', $sButton_4_Replace = 'Hide|show', $aStates_Button_4 = [['1s', '?h'], ['1h', '?s']], $i4 = 0
	Local $sButton_5_Search = 'Hide|show', $sButton_5_Replace = 'Show|hide', $aStates_Button_5 = [['2h', '?s'], ['2s', '?h']], $i5 = 0
	Local $sButton_6_Search = 'Show|hide|toggle|ignore', $sButton_6_Replace = 'Hide|show|toggle|ignore', $aStates_Button_6 = [['1s', '2h', '3t', '?i'], ['1h', '2s', '3t', '?i']], $i6 = 0

	Local $idButton_Focus = GUICtrlCreateButton('', 0, 0, 1, 1)
	Local $hButton_Focus = GUICtrlGetHandle($idButton_Focus)

	_CreateControlGroups()

	ControlFocus($hButton_Focus, '', '')

	GUISetState(@SW_SHOW, $g_hMainGUI)
	#EndRegion - GUI Create

	Local $iMsg, $iState, $sComboRead

	_SwitchControlGroups('?s')

	#Region - GUI SwitchLoop
	While True
		$iMsg = GUIGetMsg()
		Switch $iMsg
			Case $GUI_EVENT_CLOSE
				Exit
			Case $idComboBox
				ControlFocus($hButton_Focus, '', '')
				$sComboRead = StringRegExpReplace(GUICtrlRead($idComboBox), '.+(1|2|3).+', '\1s|?h')
				ConsoleWrite('$sComboRead = ' & $sComboRead & @CRLF)
				If Int($sComboRead) Then _SwitchControlGroups($sComboRead)
			Case $idButton_0 ; Show/Hilde all child
				ControlFocus($hButton_Focus, '', '')
				ConsoleWrite(StringFormat('\r\n+ %s\r\n', _ArrayToString($aStates_Button_0, '|', $i0, $i0)))
				_SwitchControlGroups(_ArrayToString($aStates_Button_0, '|', $i0, $i0))
				_Toggle($idButton_0, $sButton_0_Search, $sButton_0_Replace)
				$i0 = $i0 = 0 ? 1 : 0
				ConsoleWrite(StringFormat('\r\n+ %s\r\n', _ArrayToString($aStates_Button_0, '|', $i0, $i0)))
			Case $idButton_1 ; Toggle child 1, ignore all other childs
				ControlFocus($hButton_Focus, '', '')
				_SwitchControlGroups('1t|?i')
			Case $idButton_2 ; Toggle Child 2, ignore all other childs
				ControlFocus($hButton_Focus, '', '')
				_SwitchControlGroups('2t|?i')
			Case $idButton_3 ; Toggle Child 3, ignore all other childs
				ControlFocus($hButton_Focus, '', '')
				_SwitchControlGroups('3t|?i')
			Case $idButton_4 ; Toggle "Show child 1, hide all other childs"
				ControlFocus($hButton_Focus, '', '')
				ConsoleWrite(StringFormat('\r\n+ %s\r\n', _ArrayToString($aStates_Button_4, '|', $i4, $i4)))
				_SwitchControlGroups(_ArrayToString($aStates_Button_4, '|', $i4, $i4))
				_Toggle($idButton_4, $sButton_4_Search, $sButton_4_Replace)
				$i4 = $i4 = 0 ? 1 : 0
				ConsoleWrite(StringFormat('! %s\r\n', _ArrayToString($aStates_Button_4, '|', $i4, $i4)))
			Case $idButton_5 ; Toggle "Hide child 2, show all other childs"
				ControlFocus($hButton_Focus, '', '')
				ConsoleWrite(StringFormat('\r\n+ %s\r\n', _ArrayToString($aStates_Button_5, '|', $i5, $i5)))
				_SwitchControlGroups(_ArrayToString($aStates_Button_5, '|', $i5, $i5))
				_Toggle($idButton_5, $sButton_5_Search, $sButton_5_Replace)
				$i5 = $i5 = 0 ? 1 : 0
				ConsoleWrite(StringFormat('! %s\r\n', _ArrayToString($aStates_Button_5, '|', $i5, $i5)))
			Case $idButton_6 ; Toggle "Show child 1, hide child 2, toggle child 3, ignore all other childs"
				ControlFocus($hButton_Focus, '', '')
				ConsoleWrite(StringFormat('\r\n+ %s\r\n', _ArrayToString($aStates_Button_6, '|', $i6, $i6)))
				_SwitchControlGroups(_ArrayToString($aStates_Button_6, '|', $i6, $i6))
				_Toggle($idButton_6, $sButton_6_Search, $sButton_6_Replace)
				$i6 = $i6 = 0 ? 1 : 0
				ConsoleWrite(StringFormat('! %s\r\n', _ArrayToString($aStates_Button_6, '|', $i6, $i6)))
			Case $g_idButton_C
				ControlFocus($hButton_Focus, '', '')
				_SwitchChildsBkColor()
			Case $g_aGroups[0][0] To $g_aGroups[0][1]
				ControlFocus($hButton_Focus, '', '')
				Switch $iMsg
					Case $g_aChildGUIs[0][1]
						MsgBox(262208, 'Button gedrückt', 'ChildGUI_1 Button_1')
					Case $g_aChildGUIs[0][2]
						MsgBox(262208, 'Button gedrückt', 'ChildGUI_1 Button_2')
					Case $g_aChildGUIs[0][3]
						MsgBox(262208, 'Button gedrückt', 'ChildGUI_1 Button_3')
				EndSwitch
			Case $g_aGroups[1][0] To $g_aGroups[1][1]
				ControlFocus($hButton_Focus, '', '')
				Switch $iMsg
					Case $g_aChildGUIs[1][1]
						MsgBox(262208, 'Button gedrückt', 'ChildGUI_2 Button_1')
					Case $g_aChildGUIs[1][2]
						MsgBox(262208, 'Button gedrückt', 'ChildGUI_2 Button_2')
					Case $g_aChildGUIs[1][3]
						MsgBox(262208, 'Button gedrückt', 'ChildGUI_2 Button_3')
					Case $g_aChildGUIs[1][4]
						MsgBox(262208, 'Button gedrückt', 'ChildGUI_2 Button_4')
				EndSwitch
			Case $g_aGroups[2][0] To $g_aGroups[2][1]
				ControlFocus($hButton_Focus, '', '')
				Switch $iMsg
					Case $g_aChildGUIs[2][1]
						MsgBox(262208, 'Button gedrückt', 'ChildGUI_3 Button_1')
					Case $g_aChildGUIs[2][2]
						MsgBox(262208, 'Button gedrückt', 'ChildGUI_3 Button_2')
					Case $g_aChildGUIs[2][3]
						MsgBox(262208, 'Button gedrückt', 'ChildGUI_3 Button_3')
					Case $g_aChildGUIs[2][4]
						MsgBox(262208, 'Button gedrückt', 'ChildGUI_3 Button_4')
					Case $g_aChildGUIs[2][5]
						MsgBox(262208, 'Button gedrückt', 'ChildGUI_3 Button_5')
				EndSwitch
;~ 	 		Case Else
		EndSwitch
	WEnd
#EndRegion - GUI SwitchLoop
EndFunc  ;==>_Example

Func _SwitchControlGroups($vID)
	; ? = Other Childs, i = Ignore, h = Hide, s = Show, t = Toggle
	Local $iState, $sShow, $iIndex, $aChilds[1], $aSplit, $hWnd, $hChild

	If IsArray($vID) Then
		$aChilds = $vID
	ElseIf StringInStr($vID, '|') Then
		$aChilds = StringSplit($vID, '|', 2)
	Else
		$aChilds[0] = $vID
	EndIf
	ConsoleWrite('! $vID     = ' & $vID & @CRLF)
	ConsoleWrite('! $aChilds = ' & _ArrayToString($aChilds, '|') & @CRLF)

	$iIndex = _ArraySearch($aChilds, '?', 0, 0, 0, 1)
	If $iIndex > -1 Then
		$aSplit = StringRegExp($aChilds[$iIndex], '(\d+|\?)(\w)', 1)
		If @error Then Return SetError(1, $iIndex, False)
		_ArrayDelete($aChilds, $iIndex)
		If $aSplit[1] <> 'i' Then
			ConsoleWrite('- $aSplit = ' & _ArrayToString($aSplit, '|') & @CRLF)
			$sShow = $aSplit[1]
			For $i = 0 To UBound($g_aChildGUIs) - 1 Step 1
				$hWnd = $g_aChildGUIs[$i][0]
				$iIndex = $i
				For $j = 0 To UBound($aChilds) - 1 Step 1
					$aSplit = StringRegExp($aChilds[$j], '(\d+|\?)(\w)', 1)
					$hChild = $g_aChildGUIs[$aSplit[0] - 1][0]
					If $hWnd = $hChild Then $iIndex = -1
				Next
				If $iIndex > -1 Then
					ConsoleWrite('> $hWnd   = ' & $hWnd & @CRLF)
					$hWnd = $g_aChildGUIs[$iIndex][0]
					Switch True
						Case $sShow = 'h'
							$iState = @SW_HIDE
						Case $sShow = 's'
							$iState = @SW_SHOW
						Case $sShow = 't'
							$iState = BitAND(WinGetState($hWnd), 2) ? @SW_HIDE : @SW_SHOW
					EndSwitch
					GUISetState($iState, $hWnd)
				EndIf
			Next
		EndIf
	EndIf

	For $i = 0 To UBound($aChilds) - 1 Step 1
		$aSplit = StringRegExp($aChilds[$i], '(\d+|\?)(\w)', 1)
		If @error Or $aSplit[0] < 1 Then Return SetError(1, $i, False)
		ConsoleWrite('+ $aSplit = ' & _ArrayToString($aSplit, '|') & @CRLF)
		$hChild = $g_aChildGUIs[$aSplit[0] - 1][0]
		ConsoleWrite('+ $hChild = ' & $hChild & @CRLF)
		Switch True
			Case $aSplit[1] = 'h'
				$iState = @SW_HIDE
			Case $aSplit[1] = 's'
				$iState = @SW_SHOW
			Case $aSplit[1] = 't'
				$iState = BitAND(WinGetState($hChild), 2) ? @SW_HIDE : @SW_SHOW
		EndSwitch

		GUISetState($iState, $hChild)
	Next

	Return True
EndFunc  ;==>_SwitchControlGroups

Func _SwitchChildsBkColor()
	Local Static $iSwitch = 0, $aBtnColor = [[8, 9], [10, 11]]

	Local $aColors = $iSwitch = 0 ? $g_aSameGuiColors : $g_aDiffGuiColors

	GUISetBkColor($aColors[0], $g_hMainGUI)
	GUISetBkColor($aColors[1], $g_aChildGUIs[0][0])
	GUISetBkColor($aColors[2], $g_aChildGUIs[1][0])
	GUISetBkColor($aColors[3], $g_aChildGUIs[2][0])

	GUICtrlSetColor($g_idButton_C, $g_aButtonColors[$aBtnColor[$iSwitch][0]])
	GUICtrlSetBkColor($g_idButton_C, $g_aButtonColors[$aBtnColor[$iSwitch][1]])

	$iSwitch = $iSwitch = 0 ? 1 : 0
EndFunc  ;==>_SwitchChildsBkColor

Func _GetGroupsMinMaxIDs()
	Local $j
	For $i = 0 To UBound($g_aGroups) - 1 Step 1
		If $g_aChildGUIs[$i][$j] = '' Then ContinueLoop
		$j = 1
		$g_aGroups[$i][0] = $g_aChildGUIs[$i][$j]
		Do
			$j += 1
		Until $g_aChildGUIs[$i][$j] = '' Or $j >= UBound($g_aChildGUIs, 2)
		$g_aGroups[$i][1] = $j < UBound($g_aChildGUIs, 2) ? $g_aChildGUIs[$i][$j - 1] : $g_aGroups[$i][0]
	Next
EndFunc  ;==>_GetGroupsMinMaxIDs

Func _Toggle($idCtrl, ByRef $sSearch, ByRef $sReplace)
	Local $sTemp, $aSearch = StringSplit($sSearch & '|#', '|', 2), $aReplace = StringSplit($sReplace & '|#', '|', 2)
	If @error Or UBound($aSearch) <> UBound($aReplace) Then Exit 9999

	For $i = 0 To UBound($aSearch) - 2 Step 1
		If $i = 0 Then $sTemp = GUICtrlRead($idCtrl)
		$sTemp = StringReplace($sTemp, $aSearch[$i], $aReplace[$i], 1, 1)
	Next
	GUICtrlSetData($idCtrl, $sTemp)

	$sTemp = $sSearch
	$sSearch = $sReplace
	$sReplace = $sTemp
EndFunc  ;==>_Toggle

Func _CreateControlGroups()
	$g_aChildGUIs[0][0] = GUICreate('ChildGUI_1', 900, 100, 10, 175, $WS_CHILD, -1, $g_hMainGUI)
	GUISetBkColor(0x440000, $g_aChildGUIs[0][0])
	$g_aChildGUIs[0][1] = _CreateButton('ChildGUI_1 Button_1',  10, 10, 250, 25, 0xFF8080, 0x7F4040)
	$g_aChildGUIs[0][2] = _CreateButton('ChildGUI_1 Button_2', 270, 10, 250, 25, 0xFF8080, 0x7F4040)
	$g_aChildGUIs[0][3] = _CreateButton('ChildGUI_1 Button_3', 530, 10, 250, 25, 0xFF8080, 0x7F4040)

	$g_aChildGUIs[1][0] = GUICreate('ChildGUI_2', 900, 100, 50, 300, $WS_CHILD, -1, $g_hMainGUI)
	GUISetBkColor(0x004400, $g_aChildGUIs[1][0])
	$g_aChildGUIs[1][1] = _CreateButton('ChildGUI_2 Button_1',  10, 10, 250, 25, 0x80FF80, 0x407F40)
	$g_aChildGUIs[1][2] = _CreateButton('ChildGUI_2 Button_2', 270, 10, 250, 25, 0x80FF80, 0x407F40)
	$g_aChildGUIs[1][3] = _CreateButton('ChildGUI_2 Button_3', 530, 10, 250, 25, 0x80FF80, 0x407F40)
	$g_aChildGUIs[1][4] = _CreateButton('ChildGUI_2 Button_4',  10, 50, 770, 25, 0x80FF80, 0x407F40)

	$g_aChildGUIs[2][0] = GUICreate('ChildGUI_3', 900, 100, 90, 425, $WS_CHILD, -1, $g_hMainGUI)
	GUISetBkColor(0x000044, $g_aChildGUIs[2][0])
	$g_aChildGUIs[2][1] = _CreateButton('ChildGUI_3 Button_1',  10, 10, 250, 25, 0x8080FF, 0x40407F)
	$g_aChildGUIs[2][2] = _CreateButton('ChildGUI_3 Button_2', 270, 10, 250, 25, 0x8080FF, 0x40407F)
	$g_aChildGUIs[2][3] = _CreateButton('ChildGUI_3 Button_3', 530, 10, 250, 25, 0x8080FF, 0x40407F)
	$g_aChildGUIs[2][4] = _CreateButton('ChildGUI_3 Button_4',  10, 50, 380, 25, 0x8080FF, 0x40407F)
	$g_aChildGUIs[2][5] = _CreateButton('ChildGUI_3 Button_5', 400, 50, 380, 25, 0x8080FF, 0x40407F)

	_GetGroupsMinMaxIDs()
EndFunc  ;==>_CreateControlGroups

Func _CreateButton($sText, $x, $y, $w, $h, $sColor = 0x8F8F8F, $sBkColor = 0x2F2F2F)
	Local $idButton = GUICtrlCreateButton($sText, $x, $y, $w, $h)
	GUICtrlSetColor(-1, $sColor)
	GUICtrlSetBkColor(-1, $sBkColor)
	Return $idButton
EndFunc  ;==>_CreateButton
