Jump to content

_GUICtrlTreeViewGetTree vs _GUICtrlTreeView_GetTree


MadBoy
 Share

Recommended Posts

I have a TreeView. When i click on item i would like to get information from that Item (it's name and a full tree). While in production it works preety simple

;In production:
#Include <GuiTreeView.au3>
 _GUICtrlTreeViewGetTree ( $i_treeview,  $s_sep_char )
ConsoleWrite("-" & _GUICtrlTreeView_GetTree ($GUI_ServersView, "/") & @CRLF)oÝ÷ Ù«­¢+Øí%¸¹ÝÍÐÑè(%¹±Õ±ÐíÕ¥QÉY¥Ü¹ÔÌÐì)}U%
ÑɱQÉY¥Ý}ÑQÉ ÀÌØí¡]¹°ÀÌØí¡%Ñ´¤

The problem is that i don't know what $hItem it is and what to set. Before it was preety simple and kinda self explaining. And now after countless tries i failed to get the same thing from beta that i was getting in production version.

Any help with this would be great

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

I've used the 'example' from autoit beta to produce working example. Now whereever i press in the Treeview i am always getting 01 new item, instead of 02 new item or what i would realy like to get 01 new child, 02 new child etc. Can anyone tell me why and how to get it? I have spent a lot of time and checking testing already on it.

1. 2. 0x0005ECB8 3. False 4. 0x0005ECB8 5. False 6. False 7. [01] New Item

1. 2. 0x0005ECB8 3. False 4. 0x0005ECB8 5. 0x00000000 6. False 7. [01] New Item

1. 2. 0x0005ECB8 3. False 4. 0x0005ECB8 5. 0x00000000 6. False 7. [01] New Item

#include <GuiConstants.au3>
#include <GuiTreeView.au3>

Opt('MustDeclareVars', 1)

$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $hTreeView

_Main()

Func _Main()

    Local $GUI, $hItem
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
    $GUI = GUICreate("(External) TreeView Create", 400, 300)

    $hTreeView = _GUICtrlTreeView_Create ($GUI, 2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    _GUICtrlTreeView_BeginUpdate ($hTreeView)
    For $x = 1 To Random(2, 10, 1)
        $hItem = _GUICtrlTreeView_Add ($hTreeView, 0, StringFormat("[%02d] New Item", $x))
        For $y = 1 To Random(2, 10, 1)
            _GUICtrlTreeView_AddChild ($hTreeView, $hItem, StringFormat("[%02d] New Child", $y))
        Next
    Next
    _GUICtrlTreeView_EndUpdate ($hTreeView)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main
Func TreeListView_Click()
    ;ConsoleWrite("TreeListView_Click 1: " & _Now() & @CR)
    ConsoleWrite(@CR)
    
    Local $1 = _GUICtrlTreeView_GetTree ($hTreeView)
    Local $2 = _GUICtrlTreeView_GetItemHandle ($hTreeView)
    Local $3 = _GUICtrlTreeView_GetSelected ($hTreeView, $2)
    Local $4 = _GUICtrlTreeView_GetFirstItem ($hTreeView)
    Local $5 = _GUICtrlTreeView_GetParentHandle ($hTreeView)
    Local $6 = _GUICtrlTreeView_GetParentParam ($hTreeView)
    Local $7 = _GUICtrlTreeView_GetText ($hTreeView, $2)

    ConsoleWrite("1. " & $1)
    ConsoleWrite(@TAB)
    ConsoleWrite("2. " & $2)
    ConsoleWrite(@TAB)
    ConsoleWrite("3. " & $3)
    ConsoleWrite(@TAB)
    ConsoleWrite("4. " & $4)
    ConsoleWrite(@TAB)
    ConsoleWrite("5. " & $5)
    ConsoleWrite(@TAB)
    ConsoleWrite("6. " & $6)
    ConsoleWrite(@TAB)
    ConsoleWrite("7. " & $7)
    ConsoleWrite(@CR)
    ;_UpdateServerStats(_GUICtrlTreeView_GetTree ($GUI_ServersView, "/"))
    ;ConsoleWrite("TreeListView_Click 2: " & _Now() & @CR)
EndFunc   ;==>TreeListView_Click
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview = $hTreeView
    If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $NM_CLICK  ; The user has clicked the left mouse button within the control
                    ;_DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                    ;            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                    ;            "-->Code:" & @TAB & $iCode)
                    TreeListView_Click()
;~                     Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_DBLCLK  ; The user has double-clicked the left mouse button within the control
                    ;_DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                ;            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                ;            "-->Code:" & @TAB & $iCode)
;~                     Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RCLICK  ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                     Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RDBLCLK  ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                     Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                    #cs
                        Case $NM_KILLFOCUS ; control has lost the input focus
                        _DebugPrint("$NM_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                        "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                        "-->Code:" & @TAB & $iCode)
                        ; No return value
                        Case $NM_RETURN ; control has the input focus and that the user has pressed the key
                        _DebugPrint("$NM_RETURN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                        "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                        "-->Code:" & @TAB & $iCode)
                        ;~                     Return 1 ; nonzero to not allow the default processing
                        Return 0 ; zero to allow the default processing
                        ;~                 Case $NM_SETCURSOR ; control is setting the cursor in response to a WM_SETCURSOR message
                        ;~                     Local $tinfo = DllStructCreate($tagNMMOUSE, $ilParam)
                        ;~                     $hWndFrom = HWnd(DllStructGetData($tinfo, "hWndFrom"))
                        ;~                     $iIDFrom = DllStructGetData($tinfo, "IDFrom")
                        ;~                     $iCode = DllStructGetData($tinfo, "Code")
                        ;~                     _DebugPrint("$NM_SETCURSOR" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                        ;~                             "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                        ;~                             "-->Code:" & @TAB & $iCode & @LF & _
                        ;~                             "-->ItemSpec:" & @TAB & DllStructGetData($tinfo, "ItemSpec") & @LF & _
                        ;~                             "-->ItemData:" & @TAB & DllStructGetData($tinfo, "ItemData") & @LF & _
                        ;~                             "-->X:" & @TAB & DllStructGetData($tinfo, "X") & @LF & _
                        ;~                             "-->Y:" & @TAB & DllStructGetData($tinfo, "Y") & @LF & _
                        ;~                             "-->HitInfo:" & @TAB & DllStructGetData($tinfo, "HitInfo"))
                        ;~                     Return 0 ; to enable the control to set the cursor
                        ;~                     Return 1 ; nonzero to prevent the control from setting the cursor
                        Case $NM_SETFOCUS ; control has received the input focus
                        _DebugPrint("$NM_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                        "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                        "-->Code:" & @TAB & $iCode)
                        ; No return value
                        Case $TVN_BEGINDRAG, $TVN_BEGINDRAGW
                        _DebugPrint ("$TVN_BEGINDRAG")
                        Case $TVN_BEGINLABELEDIT, $TVN_BEGINLABELEDITW
                        _DebugPrint ("$TVN_BEGINLABELEDIT")
                        Case $TVN_BEGINRDRAG, $TVN_BEGINRDRAGW
                        _DebugPrint ("$TVN_BEGINRDRAG")
                        Case $TVN_DELETEITEM, $TVN_DELETEITEMW
                        _DebugPrint ("$TVN_DELETEITEM")
                        Case $TVN_ENDLABELEDIT, $TVN_ENDLABELEDITW
                        _DebugPrint ("$TVN_ENDLABELEDIT")
                        Case $TVN_GETDISPINFO, $TVN_GETDISPINFOW
                        _DebugPrint ("$TVN_GETDISPINFO")
                        Case $TVN_GETINFOTIP, $TVN_GETINFOTIPW
                        _DebugPrint ("$TVN_GETINFOTIP")
                        Case $TVN_ITEMEXPANDED, $TVN_ITEMEXPANDEDW
                        _DebugPrint ("$TVN_ITEMEXPANDED")
                        Case $TVN_ITEMEXPANDING, $TVN_ITEMEXPANDINGW
                        _DebugPrint ("$TVN_ITEMEXPANDING")
                        Case $TVN_KEYDOWN
                        _DebugPrint ("$TVN_KEYDOWN")
                        Case $TVN_SELCHANGED, $TVN_SELCHANGEDW
                        _DebugPrint ("$TVN_SELCHANGED")
                        Case $TVN_SELCHANGING, $TVN_SELCHANGINGW
                        _DebugPrint ("$TVN_SELCHANGING")
                        Case $TVN_SETDISPINFO, $TVN_SETDISPINFOW
                        _DebugPrint ("$TVN_SETDISPINFO")
                        Case $TVN_SINGLEEXPAND
                        _DebugPrint ("$TVN_SINGLEEXPAND")
                    #ce
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

If you want selected item handle, use _GUICtrlTreeView_GetSelection

Although if you're doing it during NM_CLICK, you should use _GUICtrlTreeView_HitTestItem, because at that point the item isn't selected yet.

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

If you want selected item handle, use _GUICtrlTreeView_GetSelection

Although if you're doing it during NM_CLICK, you should use _GUICtrlTreeView_HitTestItem, because at that point the item isn't selected yet.

It seems like it was a lot simpler in production...

_GUICtrlTreeView_GetTree ($GUI_ServersView, "/")

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

It was simpler if all you want is to get the tree path for selected item, because that's all that function could do.

In beta it's more powerful, since it lets you get tree path for ANY item. Adding one argument is small price to pay, I think.

"be smart, drink your wine"

Link to comment
Share on other sites

It was simpler if all you want is to get the tree path for selected item, because that's all that function could do.

In beta it's more powerful, since it lets you get tree path for ANY item. Adding one argument is small price to pay, I think.

Siao i got this to work

$iYRand = Random(0, 130, 1)

$iXRand = Random(0, 100, 1)

$8 = _GUICtrlTreeView_GetText ($GUI_ServersView, _GUICtrlTreeView_HitTestItem ($GUI_ServersView, $iXRand, $iYRand))

The only problem is, how to get a position of mouse in a TreeView.

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

Thanks, it worked finally but i had to use _GUICtrlListView_Create and not GUICtrlCreateTreeView as i had orginally. Otherwise your function was always returning 0. But i worked it out, THANK YOU VERY VERY MUCH. Time to fix all my projects to new beta <_<

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

Well, it's pretty shoddy, since I was working only with handle, so I didn't bother to add treeview control id as an option nor any error checking.

You can still use GUICtrlCreateTreeView (I did), just have to get the handle of such control using GUICtrlGetHandle.

Although if _GUICtrlListView_Create works fine for you, it doesn't really matter...

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

  • 1 month later...

Don't want to hijack this thread , but I believe the new function _GUICtrlTreeView_GetTree has a bug.

Somehow when used with GuiCtrlTreeView it is never traversing the tree because hItems it finds are considered to be negative (<0) and it quits right on first hItem.

Only after I changed all (<0) to (<> 0) did the function work and produce the path to the root of the tree.

CODE

#include <GUIConstants.au3>

#Include <nutTreeView.au3>

#include <GuiTreeView.au3>

$TreeView1 = 0

$Label4 = ""

Func showselected()

$selected = _GUICtrlTreeView_GetTree($TreeView1, 0)

GuiCtrlSetData($Label4 , $selected) ;display the path to root from currently selected item

EndFunc

#Region ### START Koda GUI section ### Form=c:\winnut\winnut\listvars.kxf

$guilistvar = GUICreate("Test Tree", 365, 331, 196, 108)

$TreeView1 = GUICtrlCreateTreeView(0, 8, 361, 169)

$Group1 = GUICtrlCreateGroup("Item properties", 0, 184, 361, 105, $BS_CENTER)

$Label1 = GUICtrlCreateLabel("Path :", 8, 200, 38, 17)

$Label4 = GUICtrlCreateLabel("", 50, 200, 291, 17, $SS_SUNKEN)

GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

_addPath($TreeView1 , "test4.text1.text21")

_addPath($TreeView1 , "test4.text1.11")

;_WalkTree1($TreeView1 , 0)

_GUICtrlTreeView_Expand($TreeView1)

AdlibEnable("showselected",500)

While 1

$nMsg = GUIGetMsg(1)

if ($nMsg[0] == $GUI_EVENT_CLOSE) Then

Exit

EndIf

WEnd

Don't mind the _addPath function.

What it does is simply adding a subtree to the tree made of the items separated by "."

I believe the effect should be the same if you add the items manually using the usual one item adding functions

Link to comment
Share on other sites

Don't want to hijack this thread , but I believe the new function _GUICtrlTreeView_GetTree has a bug.

Somehow when used with GuiCtrlTreeView it is never traversing the tree because hItems it finds are considered to be negative (<0) and it quits right on first hItem.

Only after I changed all (<0) to (<> 0) did the function work and produce the path to the root of the tree.

CODE

#include <GUIConstants.au3>

#Include <nutTreeView.au3>

#include <GuiTreeView.au3>

$TreeView1 = 0

$Label4 = ""

Func showselected()

$selected = _GUICtrlTreeView_GetTree($TreeView1, 0)

GuiCtrlSetData($Label4 , $selected) ;display the path to root from currently selected item

EndFunc

#Region ### START Koda GUI section ### Form=c:\winnut\winnut\listvars.kxf

$guilistvar = GUICreate("Test Tree", 365, 331, 196, 108)

$TreeView1 = GUICtrlCreateTreeView(0, 8, 361, 169)

$Group1 = GUICtrlCreateGroup("Item properties", 0, 184, 361, 105, $BS_CENTER)

$Label1 = GUICtrlCreateLabel("Path :", 8, 200, 38, 17)

$Label4 = GUICtrlCreateLabel("", 50, 200, 291, 17, $SS_SUNKEN)

GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

_addPath($TreeView1 , "test4.text1.text21")

_addPath($TreeView1 , "test4.text1.11")

;_WalkTree1($TreeView1 , 0)

_GUICtrlTreeView_Expand($TreeView1)

AdlibEnable("showselected",500)

While 1

$nMsg = GUIGetMsg(1)

if ($nMsg[0] == $GUI_EVENT_CLOSE) Then

Exit

EndIf

WEnd

Don't mind the _addPath function.

What it does is simply adding a subtree to the tree made of the items separated by "."

I believe the effect should be the same if you add the items manually using the usual one item adding functions

Yes, it doesn't show anything else then the 1st entry. I wasn't sure if it's a design or bug so i found another way to get the information i need from TreeView.

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

I think it is a bug so I have rewritten the function to always work

Here is my rewritten function that works fine

CODE

Func _GUICtrlTreeViewGetTree1($i_treeview, $s_sep_char , $h_item)

If Not _WinAPI_IsClassName ($i_treeview, "SysTreeView32") Then

Return SetError(-1, -1, "")

EndIf

Local $szPath = "", $hParent

If Not IsHWnd($i_treeview) Then $i_treeview = GUICtrlGetHandle($i_treeview)

If $h_item = 0 Then $h_item = _SendMessage($i_treeview, $TVM_GETNEXTITEM, $TVGN_CARET, 0)

;$h_item = GUICtrlSendMsg($i_treeview, $TVM_GETNEXTITEM, $TVGN_CARET, 0)

If $h_item > 0 Then

$szPath = _GUICtrlTreeView_GetText($i_treeview, $h_item)

Do; Get now the parent item handle if there is one

$hParent = _SendMessage($i_treeview, $TVM_GETNEXTITEM, $TVGN_PARENT, $h_item)

If $hParent > 0 Then $szPath = _GUICtrlTreeView_GetText($i_treeview, $hParent) & $s_sep_char & $szPath

$h_item = $hParent

Until $h_item <= 0

EndIf

Return $szPath

EndFunc ;==>_GUICtrlTreeViewGetTree

I have slightly changed it to make it more comfortable for my needs.

The error checking part in the beginning is a leftover from the previous version.

I also have added the separator char back as a parameter since I find it more convenient then using Opt which affects things on a global scope and might affect behavior of code in other places.

Link to comment
Share on other sites

Yes, it doesn't show anything else then the 1st entry. I wasn't sure if it's a design or bug so i found another way to get the information i need from TreeView.

There will be a fix in the 3.2.11.0 beta, due to the change in the SendMessage in the 3.2.10.0 and the last beta the return type being checked in the Condition statements was checking for the wrong value.

Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Well, it's pretty shoddy, since I was working only with handle, so I didn't bother to add treeview control id as an option nor any error checking.

You can still use GUICtrlCreateTreeView (I did), just have to get the handle of such control using GUICtrlGetHandle.

Although if _GUICtrlListView_Create works fine for you, it doesn't really matter...

Well when you work with over 1600 functions mistakes can happen. Your welcome very much...mumbles "shoddy"......

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

It seems like it was a lot simpler in production...

_GUICtrlTreeView_GetTree ($GUI_ServersView, "/")

Just call the opt before the call then reset it after words, may have been simpler for you but didn't work in well with all the new functions.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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...