katoNkatoNK Posted June 14, 2011 Share Posted June 14, 2011 (edited) Thanks to Melba23's GUIExtender UDF, gui's are way more dynamic!I have a small problem though, when trying to use 'custom' controls..I have three sections each with a few IP Address Controls, and if i don't manage the placement of the each section's controls individually (ControlMove ~ in this case) when expanding/retracting they won't be displayed correctly..I managed to get it to display correctly with the '_GUIExtender_UpdateControls()' in my example, but i'm not 100 percent happy with it, the controls are overlapped/misplaced when certain sections are shown/hidden.Here's my script, is there more 'stable' way of getting this done?expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <GuiIPAddress.au3> #include <GuiComboBox.au3> #include "GUIExtender.au3" Global $hGUI, $iMsg, $View, $vIP, $vDNS, $vWINS, $ipAdd, $Subnet, $Gateway, $PrefDns, $AltDns, $PrefWins, $AltWins Global $sStatic1, $sStatic2, $sStatic3, $ipSection, $dnsSection, $winsSection, $sGUIip_State, $sGUIdns_State, $sGUIwins_State $hGUI = GUICreate("hGui", 290, 610, -1, -1) $View = GUICtrlCreateMenu("View") $vIP = GUICtrlCreateMenuItem("IP Settings", $View) $vDNS = GUICtrlCreateMenuItem("DNS Settings", $View) $vWINS = GUICtrlCreateMenuItem("WINS Settings", $View) _GUIExtender_Init($hGUI) $sStatic1 = _GUIExtender_Section_Start(0, 90) GUICtrlCreateGroup("", 5, 0, 285, 70) GUICtrlCreateCheckbox("IP Address", 35, 75) _GUIExtender_Section_Action($sStatic1 + 1, "", "", 13, 78, 15, 15) _GUIExtender_Section_End() $ipSection = _GUIExtender_Section_Start(90, 140) GUICtrlCreateGroup("", 5, 125, 280, 110) $ipAdd = _GUICtrlIpAddress_Create($hGUI, 140, 145, 135, 20) $Subnet = _GUICtrlIpAddress_Create($hGUI, 140, 175, 135, 20) $Gateway = _GUICtrlIpAddress_Create($hGUI, 140, 205, 135, 20) _GUIExtender_Section_End() $sStatic2 = _GUIExtender_Section_Start(230, 25) GUICtrlCreateCheckbox("DNS Servers", 35, 240) _GUIExtender_Section_Action($sStatic2 + 1, "", "", 13, 243, 15, 15) _GUIExtender_Section_End() $dnsSection = _GUIExtender_Section_Start(255, 110) GUICtrlCreateGroup("", 5, 290, 280, 80) $PrefDns = _GUICtrlIpAddress_Create($hGUI, 140, 310, 135, 20) $AltDns = _GUICtrlIpAddress_Create($hGUI, 140, 340, 135, 20) _GUIExtender_Section_End() $sStatic3 = _GUIExtender_Section_Start(365, 25) GUICtrlCreateCheckbox("WINS Server", 35, 375) _GUIExtender_Section_Action($sStatic3 + 1, "", "", 13, 378, 15, 15) _GUIExtender_Section_End() $winsSection = _GUIExtender_Section_Start(390, 110) GUICtrlCreateGroup("", 5, 425, 280, 80) $PrefWins = _GUICtrlIpAddress_Create($hGUI, 140, 445, 135, 20) $AltWins = _GUICtrlIpAddress_Create($hGUI, 140, 475, 135, 20) _GUIExtender_Section_End() _GUIExtender_Section_Start(500, 95) GUIStartGroup() GUICtrlCreateGroup("", 5, 535, 280, 50) GUICtrlCreateRadio("radio1", 15, 510) GUICtrlCreateRadio("radio2:", 15, 530) _GUIExtender_Section_End() _GUIExtender_Section_Extend(0, False) GUISetState(@SW_SHOW, $hGUI) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $vIP If BitAND(GUICtrlRead($vIP), $GUI_CHECKED) = $GUI_CHECKED Then _GUIExtender_Section_Extend($ipSection, False) GUICtrlSetState($vIP, $GUI_UNCHECKED) Else _GUIExtender_Section_Extend($ipSection) GUICtrlSetState($vIP, $GUI_CHECKED) EndIf Case $vDNS If BitAND(GUICtrlRead($vDNS), $GUI_CHECKED) = $GUI_CHECKED Then _GUIExtender_Section_Extend($dnsSection, False) GUICtrlSetState($vDNS, $GUI_UNCHECKED) Else _GUIExtender_Section_Extend($dnsSection) GUICtrlSetState($vDNS, $GUI_CHECKED) EndIf Case $vWINS If BitAND(GUICtrlRead($vWINS), $GUI_CHECKED) = $GUI_CHECKED Then _GUIExtender_Section_Extend($winsSection, False) GUICtrlSetState($vWINS, $GUI_UNCHECKED) Else _GUIExtender_Section_Extend($winsSection) GUICtrlSetState($vWINS, $GUI_CHECKED) EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch _GUIExtender_Action($iMsg) $sGUIip_State = _GUIExtender_Section_State($ipSection) $sGUIdns_State = _GUIExtender_Section_State($dnsSection) $sGUIwins_State = _GUIExtender_Section_State($winsSection) _GUIExtender_UpdateControls($sGUIip_State, $sGUIdns_State) ;~ Custom update function If $sGUIip_State = 0 Then ControlHide($hGUI, "", $ipAdd) ControlHide($hGUI, "", $Subnet) ControlHide($hGUI, "", $Gateway) If BitAND(GUICtrlRead($vIP), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($vIP, $GUI_UNCHECKED) ElseIf $sGUIip_State = 1 Then If BitAND(GUICtrlRead($vIP), $GUI_CHECKED) <> $GUI_CHECKED Then GUICtrlSetState($vIP, $GUI_CHECKED) ControlShow($hGUI, "", $ipAdd) ControlShow($hGUI, "", $Subnet) ControlShow($hGUI, "", $Gateway) EndIf If $sGUIdns_State = 0 Then ControlHide($hGUI, "", $PrefDns) ControlHide($hGUI, "", $AltDns) If BitAND(GUICtrlRead($vDNS), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($vDNS, $GUI_UNCHECKED) ElseIf $sGUIdns_State = 1 Then If BitAND(GUICtrlRead($vDNS), $GUI_CHECKED) <> $GUI_CHECKED Then GUICtrlSetState($vDNS, $GUI_CHECKED) ControlShow($hGUI, "", $PrefDns) ControlShow($hGUI, "", $AltDns) EndIf If $sGUIwins_State = 0 Then ControlHide($hGUI, "", $PrefWins) ControlHide($hGUI, "", $AltWins) If BitAND(GUICtrlRead($vWINS), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($vWINS, $GUI_UNCHECKED) ElseIf $sGUIwins_State = 1 Then If BitAND(GUICtrlRead($vWINS), $GUI_CHECKED) <> $GUI_CHECKED Then GUICtrlSetState($vWINS, $GUI_CHECKED) ControlShow($hGUI, "", $PrefWins) ControlShow($hGUI, "", $AltWins) EndIf WEnd Func _GUIExtender_UpdateControls($sIP, $sDNS) ;~ Set the relevant ip control's position. If $sIP = 0 Then ControlMove($hGUI, "", $PrefDns, 140, 170) ControlMove($hGUI, "", $AltDns, 140, 200) If $sDNS = 0 Then ControlMove($hGUI, "", $PrefWins, 140, 195) ControlMove($hGUI, "", $AltWins, 140, 225) Else ControlMove($hGUI, "", $PrefWins, 140, 305) ControlMove($hGUI, "", $AltWins, 140, 335) EndIf Else ControlMove($hGUI, "", $PrefDns, 140, 310) ControlMove($hGUI, "", $AltDns, 140, 340) If $sDNS = 0 Then ControlMove($hGUI, "", $PrefWins, 140, 335) ControlMove($hGUI, "", $AltWins, 140, 365) Else ControlMove($hGUI, "", $PrefWins, 140, 445) ControlMove($hGUI, "", $AltWins, 140, 475) EndIf EndIf EndFunc ;==>_GUIExtender_Update_ControlsThanks in advance..Here's the Edit:Cleaned up the script a bit. Edited June 14, 2011 by katoNkatoNK Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now