Sign in to follow this  
Followers 0
engjcowi

Help Needed GUICtrlCreateTreeViewItem

7 posts in this topic

Hey Guys

I put together a small program that used a combobox and listed all the reg files in a directory then applied the one selected. Feeling pretty chuffed with myself i decided to try and go one step further byt creating a program to do the same but listing the reg files from various folders, Listing them under their respective branches and then being able to select numerous ones to run at the same time. However i think im starring into nothing'ness and my brain needs a rest as im just frustrating myself trying to get it to work.

Im using windows exe and dll files as a search for now.

Can someone please assist me.

Thank you in advance. its Much appreciated

#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#Include <File.au3>

Local $hItem[6], $hRandomItem, $hTreeView, $edit, $string, $msg
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
$harray=_FileListToArray(@WindowsDir,"*.dll")
$harray2=_FileListToArray(@WindowsDir,"*.exe")
GUICreate("TreeView Get Checked", 620, 300)

;$edit = GUICtrlCreateEdit("", 400, 10, 200)
$ok_button = GUICtrlCreateButton("Ok", 50, 250, 97, 25)
$exit_button = GUICtrlCreateButton("Exit", 150, 250, 97, 25)
GUICtrlSetOnEvent(-1, "exit_buttonclick")

$hTreeView = GUICtrlCreateTreeView(2, 2, 396, 200, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState()

$generalitem = GUICtrlCreateTreeViewItem("General", $htreeview)
_GUICtrlTreeView_BeginUpdate($generalitem)
For $x=0 To Ubound($harray)-1
    ;GUICtrlSetData($hcombo,$array[$x])
    ;$hItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x + 1), $hTreeView)
    $harray[$x] = GUICtrlCreateTreeViewItem($harray[$x], $generalitem)
Next

$displayitem = GUICtrlCreateTreeViewItem("Display", $htreeview)
_GUICtrlTreeView_BeginUpdate($displayitem)
For $x=0 To Ubound($harray2)-1
    ;GUICtrlSetData($hcombo,$array[$x])
    ;$hItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x + 1), $hTreeView)
    $harray2[$x] = GUICtrlCreateTreeViewItem($harray2[$x], $displayitem)
Next

_GUICtrlTreeView_EndUpdate($hTreeView)


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
            GUIDelete()
        Case $msg = $ok_button
           _execute()

        Case $msg = $exit_button
            exit_buttonclick()
    EndSelect

WEnd

Func _execute()

$item = GUICtrlRead($hTreeView)      ; 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)
                        _GUICtrlTreeView_SetSelected($hTreeView, $item)

                    EndIf
                EndIf

EndFunc

func exit_buttonclick()
exit
EndFunc

Drunken Frat-Boy Monkey Garbage

Share this post


Link to post
Share on other sites



Can anyone help at all please?


Drunken Frat-Boy Monkey Garbage

Share this post


Link to post
Share on other sites

engjcowi,

There is actually no question in your initial post, but I assume you are looking to determine which items in the Tree are checked. ;)

You will need to look at the state of each item like this:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>

Global $aItem[4]

$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

GUICreate("Checked", 200, 200)

$hTreeView = GUICtrlCreateTreeView(10, 10, 180, 140, $iStyle, $WS_EX_CLIENTEDGE)

GUISetState()

_GUICtrlTreeView_BeginUpdate($hTreeView)
For $i = 0 To 3
    $aItem[$i] = GUICtrlCreateTreeViewItem(" Item " & $i, $hTreeView)
Next
_GUICtrlTreeView_EndUpdate($hTreeView)

$hButton = GUICtrlCreateButton("Read", 10, 160, 80, 30)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            For $i = 0 To 3
                ; Get the state of the item
                Local $iState = _GUICtrlTreeView_GetState($hTreeView, $aItem[$i])
                ; See if the "checked" flag is set
                If BitAnd($iState, 0x2000) Then ConsoleWrite($i & " Checked" & @CRLF)
            Next
            ConsoleWrite(@CRLF)
    EndSwitch

WEnd

Is that what you wanted? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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 Melba23

Thats what im looking for thank you. I didnt even realise i hadnt posted a question. in my head i thought i did lol.

Im writing it so that the user can put reg files into the respective folders and the treeview will list them and when the user selects them and presses go then it will run the reg files to integrate into the registry.

I do have 1 other minor question if i could take up a little more of yor time please. I would like to set up 3 main folders, XP, Vista and 7. In my other incarnation of a reg tweaker i had a set of folders inside each of the 3 OS folders stating the type of tweaks, desktop, appearence etc... and i set these manually. Is there a way to have the treeview have XP then branch to the next folder then list whats in that directory with the directory being unknowm or dynamic so the user can arrange the tweaks how he or she wants?

Thanks

jamie

p.s im on the way with this now and ill update with code soon :)


Drunken Frat-Boy Monkey Garbage

Share this post


Link to post
Share on other sites

engjcowi,

Set up an ini file with this structure:

[Folders]
XP=Folder_Path
Vista=Folder_Path
Win7=Folder_Path

Then use some code along these lines to load the TreeView with the contents of the folders:

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

; Read folders
$aFolders = IniReadSection("Folders.ini", "Folders")

$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

$hGUI = GUICreate("Test", 400, 500)

$hTreeView = GUICtrlCreateTreeView(10, 10, 380, 480, $iStyle, $WS_EX_CLIENTEDGE)

; For each folder
For $i = 1 To $aFolders[0][0]

    ; Create a parent item
    $hParent = GUICtrlCreateTreeViewItem($aFolders[$i][0], $hTreeView)
    ; Read all files in that folder - adjust the mask as required
    $FileList = _FileListToArray($aFolders[$i][1], "*.*", 1)
    ; Add files to treeview
    For $j = 1 To $FileList[0]
        GUICtrlCreateTreeViewItem($FileList[$j], $hParent)
    Next

Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

I leave it to you to add a section where the user can change the folders for each OS. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

Brilliant thank you very much for all your help :)


Drunken Frat-Boy Monkey Garbage

Share this post


Link to post
Share on other sites

engjcowi,

My pleasure. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
Sign in to follow this  
Followers 0