Jump to content

Any simple way to hide all items within groupcontrol?


Recommended Posts

So, since i have like 50 items per each control group(labels and checkboxes) and i have like 40 controlgroups like this you can imagine what the mess i have here unless there is a simple way to hide everything within groupcontrol.

What i did is placed those items as children of controlgroups then tried

guictrlsetstate($ctrlgroup1, $GUI_HIDE) but to my dissapointment this only hides control group and it leaves children intact.

I am creating a scheduler that needs entire week for each option(5 of them * 7 weeks = bazillion of items)

insipired by autoit treview example from the help manual. / the idea is to click on a treview which sends a message to gui and tells it which item was clicked so my gui then needs to hide everything that is not related to the option clicked in the treeview and only show whats needed, rinse and repeat when other treeview items are clicked.

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

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $treeview, $generalitem, $displayitem, $aboutitem, $compitem
    Local $useritem, $resitem, $otheritem, $startlabel, $aboutlabel
    Local $compinfo, $togglebutton, $infobutton, $statebutton, $cancelbutton
    Local $msg, $item, $text, $hItem
    
    GUICreate("My GUI with treeview", 350, 215)

    $treeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    $generalitem = GUICtrlCreateTreeViewItem("General", $treeview)
    GUICtrlSetColor(-1, 0x0000C0)
    $displayitem = GUICtrlCreateTreeViewItem("Display", $treeview)
    GUICtrlSetColor(-1, 0x0000C0)
    $aboutitem = GUICtrlCreateTreeViewItem("About", $generalitem)
    $compitem = GUICtrlCreateTreeViewItem("Computer", $generalitem)
    $useritem = GUICtrlCreateTreeViewItem("User", $generalitem)
    $resitem = GUICtrlCreateTreeViewItem("Resolution", $displayitem)
    $otheritem = GUICtrlCreateTreeViewItem("Other", $displayitem)

    $startlabel = GUICtrlCreateLabel("TreeView Demo", 190, 90, 100, 20)
    $aboutlabel = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
    GUICtrlSetState(-1, $GUI_HIDE)  ; Hides the "aboutlabel"-text during initialization
    $compinfo = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80)
    GUICtrlSetState(-1, $GUI_HIDE)  ; Hides the "compinfo"-text during initialization

    GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN)
    $togglebutton = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20)
    $infobutton = GUICtrlCreateButton("&Info", 105, 185, 70, 20)
    $statebutton = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20)
    $cancelbutton = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20)

    GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))    ; Expand the "General"-item and paint in bold
    GUICtrlSetState($displayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))    ; Expand the "Display"-item and paint in bold

    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $cancelbutton Or $msg = $GUI_EVENT_CLOSE
                ExitLoop

            Case $msg = $togglebutton   ; Toggle the bold painting
                If BitAND(GUICtrlRead($generalitem), $GUI_DEFBUTTON) Then
                    GUICtrlSetState($generalitem, 0)
                    GUICtrlSetState($displayitem, 0)
                Else
                    GUICtrlSetState($generalitem, $GUI_DEFBUTTON)
                    GUICtrlSetState($displayitem, $GUI_DEFBUTTON)
                EndIf

            Case $msg = $infobutton
                $item = GUICtrlRead($treeview)      ; Get the controlID of the current selected treeview item
                If $item = 0 Then
                    MsgBox(64, "TreeView Demo", "No item currently selected")
                Else
                    $text = GUICtrlRead($item, 1) ; Get the text of the treeview item
                    If $text == "" Then
                        MsgBox(16, "Error", "Error while retrieving infos about item")
                    Else
                        MsgBox(64, "TreeView Demo", "Current item selected is: " & $text)
                    EndIf
                EndIf

            Case $msg = $statebutton
                $item = GUICtrlRead($treeview)
                If $item > 0 Then
                    $hItem = GUICtrlGetHandle($item)
                    DllCall("user32.dll", "int", "SendMessage", "hwnd", GUICtrlGetHandle($treeview), "int", $TVM_EXPAND, "int", $TVE_TOGGLE, "hwnd", $hItem)
                EndIf

                ; The following items will hide the other labels (1st and 2nd parameter) and then show the 'own' labels (3rd and 4th parameter)
            Case $msg = $generalitem
                GUIChangeItems($aboutlabel, $compinfo, $startlabel, $startlabel)

            Case $msg = $aboutitem
                GUICtrlSetState($compinfo, $GUI_HIDE)
                GUIChangeItems($startlabel, $startlabel, $aboutlabel, $aboutlabel)

            Case $msg = $compitem
                GUIChangeItems($startlabel, $aboutlabel, $compinfo, $compinfo)
        EndSelect
    WEnd

    GUIDelete()
EndFunc   ;==>Example

Func GUIChangeItems($hidestart, $hideend, $showstart, $showend)
    Local $idx

    For $idx = $hidestart To $hideend
        GUICtrlSetState($idx, $GUI_HIDE)
    Next
    For $idx = $showstart To $showend
        GUICtrlSetState($idx, $GUI_SHOW)
    Next
EndFunc   ;==>GUIChangeItems

I guess this example is much more simple then i thought :unsure:

Edited by Aktonius
Link to comment
Share on other sites

Probably one way to handle this is...

Set up some sort of system for associating each clicked treeview item with its own set of label and checkbox controls, such as: using a two-dimensional array (I will explain), and build a function which destroys all the label and checkbox controls showing in the target gui, and then builds the next set of needed label and checkbox controls as per the user clicking on treeview items.

The first dimension should have enough elements to iterate through all the treeview items, and the second dimension should have enough elements to increment the largest number of controls ( labels plus checkbox controls ) associated with any treeview item.

Link to comment
Share on other sites

SquirrelyOne thanks for suggestion but i can't destroy those items every time other items are needed because when the script runs it needs to hold information for every item, not only the last one that was edited.

For example: When the script runs it needs to know for option 1 - option 5 it knows if it should run for every monday-sunday hour for each option(depending if checkbox makes the hour active).

Link to comment
Share on other sites

You could separate your controls into different arrays, separated by your groups. When you need to disable the group of controls, loop through the corresponding array and use the ControlHide function to hide each one, use ControlShow to show it again.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You could separate your controls into different arrays, separated by your groups. When you need to disable the group of controls, loop through the corresponding array and use the ControlHide function to hide each one, use ControlShow to show it again.

This will probably do it, even i will need to type alot but i guess i dont have much choices here, thanks

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...