Jump to content
Sign in to follow this  
Achilles

GUICtrlTreeView

Recommended Posts

Achilles

Is there a relatively simple way to make a GuiCtrlListView item act like a tab item. Basically each item you click on will have it's open little set of controls to put on the GUI and whenever an item is selected it's items get shown. I don't know if there would be a way to combine it some way with a tab control but that's what I was thinking.

Any ideas would be nice.


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
BrettF

Set an event when one of the nodes or whatever you call them is clicked? It sounds good in theory... 'cept I really have no idea how to do it. LOL.

Hope that gives some ideas.

Share this post


Link to post
Share on other sites
Achilles

This kind of works, it's pretty sloppy:

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

$timer = TimerInit()

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

GUIRegisterMsg($WM_NOTIFY, "MY_WM_COMMAND")

GUISetState()

Do 
    $msg = GuiGetMsg()
    Sleep(10) 
Until $msg = $GUI_EVENT_CLOSE 

GUIDelete()

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    If $wParam = $treeview then 
        If String($lParam) = '0x008AF564' or String($lParam) = '0x008AF050' then 
            If TimerDiff($timer) > 100 then 
                ConsoleWrite('CHANGE!!! ' & TimerDiff($timer) & @CRLF)
                $timer = TimerInit()
            EndIf
        EndIf 
    EndIf 
    Return $GUI_RUNDEFMSG
EndFunc  ;==>MY_WM_COMMAND

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
smashly

Hi, I didn't quite understand what you were trying to accomplish, so if I missed the point then sorry.

Your example above doesn't output anything in scite console for me when I click on an item.

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

$hGUI = GUICreate("My GUI with treeview", 250, 160)

$TV = GUICtrlCreateTreeView(5, 5, 150, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$Item = GUICtrlCreateTreeViewItem("Static Controls", $TV)
GUICtrlCreateTreeViewItem("Icon", $Item)
GUICtrlCreateTreeViewItem("Label", $Item)
GUICtrlCreateTreeViewItem("Picture", $Item)
$Icon = GUICtrlCreateIcon("shell32.dll", -6, 165, 5, 40, 40)
$Label = GUICtrlCreateLabel("This is a label", 165, 50, 100, 20)
$Pic = GUICtrlCreatePic(@WindowsDir & "\Blue Lace 16.bmp", 165, 75, 50, 50)
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $msg = GuiGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            ;;;
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hTV
    $hTV = $TV
    If Not IsHWnd($TV) Then $hTV = GUICtrlGetHandle($TV)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hTV
            Switch $iCode
                Case $NM_CLICK
                    Local $MGP, $TV_HTI
                    $MGP = _WinAPI_GetMousePos(True, $hTV)
                    $TV_HTE = _GUICtrlTreeView_HitTestEx($hTV, DllStructGetData($MGP, "X"), DllStructGetData($MGP, "Y"))
                    If DLLStructGetData($TV_HTE, "Flags") = $TVHT_ONITEMLABEL Then 
                        Switch _GUICtrlTreeView_GetText($hTV, DLLStructGetData($TV_HTE, "Item"))
                            Case "Static Controls"
                                GUICtrlSetState($Icon, $GUI_SHOW)
                                GUICtrlSetState($Label, $GUI_SHOW)
                                GUICtrlSetState($Pic, $GUI_SHOW)
                            Case "Icon"
                                GUICtrlSetState($Icon, $GUI_SHOW)
                                GUICtrlSetState($Label, $GUI_HIDE)
                                GUICtrlSetState($Pic, $GUI_HIDE)
                            Case "Label"
                                GUICtrlSetState($Icon, $GUI_HIDE)
                                GUICtrlSetState($Label, $GUI_SHOW)
                                GUICtrlSetState($Pic, $GUI_HIDE)
                            Case "Picture"
                                GUICtrlSetState($Icon, $GUI_HIDE)
                                GUICtrlSetState($Label, $GUI_HIDE)
                                GUICtrlSetState($Pic, $GUI_SHOW)
                    EndSwitch
                EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Cheers

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  

×