Holger Posted June 17, 2005 Posted June 17, 2005 (edited) Hi so here is my first step into "DllCreateStruct" With this you see how to get i.e. the complete-tree-structure or path of the current selected treeview-item in a _GUI-TreeView_. Feel free to use and modify it Newest Autoit3-Beta is needed. expandcollapse popup; ---------------------------------------------------------------------------- ; ; AutoIt Version: 3.1.1.48 ; Author: Holger Kotsch ; ; Script Function: ; Gets the treeview-structure-text (i.e.path) for the current selected ; treeview item ; ; ---------------------------------------------------------------------------- #include <GUIConstants.au3> Opt("GUIDataSeparatorChar","\") ;--------------------------------------------------------------- ; Some additional constants ;--------------------------------------------------------------- Global $TV_FIRST = 0x1100 Global $TVM_GETITEM = $TV_FIRST + 12 Global $TVM_GETNEXTITEM = $TV_FIRST + 10 Global $TVGN_CARET = 0x0009 Global $TVGN_PARENT = 0x0003 Global $TVIF_TEXT = 0x0001 ;--------------------------------------------------------------- ; Main sample program ;--------------------------------------------------------------- $szDataSep = Opt("GUIDataSeparatorChar") $hGUI = GUICreate("TreeTest") $nTree = GUICtrlCreateTreeView(10,10,150,150) $hTree = ControlGetHandle($hGUI,"",$nTree); Later important for getting item information $nItem1 = GUICtrlCreateTreeViewItem("Item1",$nTree) $nItem2 = GUICtrlCreateTreeViewItem("Item2",$nTree) $nSubItem1 = GUICtrlCreateTreeViewItem("SubItem1",$nItem1) $nSubItem2 = GUICtrlCreateTreeViewItem("SubItem2",$nItem1) $nSubItem3 = GUICtrlCreateTreeViewItem("SubItem3",$nSubItem1) $nButton = GUICtrlCreateButton("Path?",70,170,70,20) GUISetState() While 1 $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE ExitLoop Case $nMsg = $nButton Msgbox(0,"Path",_GUICtrlTreeViewItemGetTree()) EndSelect WEnd Exit ;--------------------------------------------------------------- ; Get all items text beginning by the current selected item ;--------------------------------------------------------------- Func _GUICtrlTreeViewItemGetTree() $szPath = "" $hItem = GUICtrlSendMsg($nTree,$TVM_GETNEXTITEM,$TVGN_CARET,0) If $hItem > 0 Then $szPath = TreeViewGetItemText($hItem) Do; Get now the parent item handle if there is one $hParent = GUICtrlSendMsg($nTree,$TVM_GETNEXTITEM,$TVGN_PARENT,$hItem) If $hParent > 0 Then $szPath = TreeViewGetItemText($hParent) & $szDataSep & $szPath $hItem = $hParent Until $hItem <= 0 EndIf Return $szPath EndFunc ;--------------------------------------------------------------- ; Retrieve the item text by sending a right item handle ;--------------------------------------------------------------- Func TreeViewGetItemText($hItem) $szText = "" $TEXT_struct = DllStructCreate("char[260]"); create a text 'area' for receiving the text $TVITEM_struct = DllStructCreate("uint;int;uint;uint;ptr;int;int;int;int;int") DllStructSetData($TVITEM_struct,1,$TVIF_TEXT) DllStructSetData($TVITEM_struct,2,$hItem) DllStructSetData($TVITEM_struct,5,DllStructGetPtr($TEXT_struct)) DllStructSetData($TVITEM_struct,6,260) DllCall("user32.dll","int","SendMessage","hwnd",$hTree,"int",$TVM_GETITEM,"int",0,"ptr",DllStructGetPtr($TVITEM_struct)) $szText = DllStructGetData($TEXT_struct,1) DllStructDelete($TEXT_struct) DllStructDelete($TVITEM_struct) Return $szText EndFunc Regards Holger Edited June 17, 2005 by Holger Old project:GUI/Tray menu with icons and colors Other old stuff:IconFileScanner, TriState/ThreeState GUI TreeView, GUI ContextMenu created out of a TreeView
GaryFrost Posted June 17, 2005 Posted June 17, 2005 Nice, now I can start working on the TreeView UDF's Thanks, Gary SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
Wb-FreeKill Posted June 18, 2005 Posted June 18, 2005 Just edited the func's a bit for my personal use, maybe someone can use this:Test script:#include <GUIConstants.au3> #include <GUITreeView.au3> $hGUI = GUICreate("TreeTest") $TreeView = GUICtrlCreateTreeView(10,10,150,150) $Handle = ControlGetHandle($hGUI,"",$TreeView) $nItem1 = GUICtrlCreateTreeViewItem("Item1",$TreeView) $nItem2 = GUICtrlCreateTreeViewItem("Item2",$TreeView) $nSubItem1 = GUICtrlCreateTreeViewItem("SubItem1",$nItem1) $nSubItem2 = GUICtrlCreateTreeViewItem("SubItem2",$nItem1) $nSubItem3 = GUICtrlCreateTreeViewItem("SubItem3",$nSubItem1) $nButton = GUICtrlCreateButton("Path?",70,170,70,20) GUISetState() While 1 $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE ExitLoop Case $nMsg = $nButton Msgbox(0,"Path",_GUICtrlTreeViewItemGetTree($TreeView,$Handle)) EndSelect WEnd Exit"GUITreeView.au3" Include fileexpandcollapse popupGlobal $TV_FIRST = 0x1100 Global $TVM_GETITEM = $TV_FIRST + 12 Global $TVM_GETNEXTITEM = $TV_FIRST + 10 Global $TVGN_CARET = 0x0009 Global $TVGN_PARENT = 0x0003 Global $TVIF_TEXT = 0x0001 ;--------------------------------------------------------------- ; Get all items text beginning by the current selected item ;--------------------------------------------------------------- Func _GUICtrlTreeViewItemGetTree($nTree,$hTree) $szPath = "" $hItem = GUICtrlSendMsg($nTree,$TVM_GETNEXTITEM,$TVGN_CARET,0) If $hItem > 0 Then $szPath = TreeViewGetItemText($hItem,$hTree) Do; Get now the parent item handle if there is one $hParent = GUICtrlSendMsg($nTree,$TVM_GETNEXTITEM,$TVGN_PARENT,$hItem) If $hParent > 0 Then $szPath = TreeViewGetItemText($hParent,$hTree) & "\" & $szPath $hItem = $hParent Until $hItem <= 0 EndIf Return $szPath EndFunc ;--------------------------------------------------------------- ; Retrieve the item text by sending a right item handle ;--------------------------------------------------------------- Func TreeViewGetItemText($hItem,$hTree) $szText = "" $TEXT_struct = DllStructCreate("char[260]"); create a text 'area' for receiving the text $TVITEM_struct = DllStructCreate("uint;int;uint;uint;ptr;int;int;int;int;int") DllStructSetData($TVITEM_struct,1,$TVIF_TEXT) DllStructSetData($TVITEM_struct,2,$hItem) DllStructSetData($TVITEM_struct,5,DllStructGetPtr($TEXT_struct)) DllStructSetData($TVITEM_struct,6,260) DllCall("user32.dll","int","SendMessage","hwnd",$hTree,"int",$TVM_GETITEM,"int",0,"ptr",DllStructGetPtr($TVITEM_struct)) $szText = DllStructGetData($TEXT_struct,1) DllStructDelete($TEXT_struct) DllStructDelete($TVITEM_struct) Return $szText EndFunc
Zedna Posted June 21, 2005 Posted June 21, 2005 HiCan you help me with manipulating treeview in other application please?It's the same as your function TreeViewGetItemTextbut it doesn't work if I'm trying this on treeview inside other application.Note that TVM_GETNEXTITEM, TVM_SELECTITEM are working OKonly TVM_GETITEM for obtain item text is not OK.My first post about it is here:TreeViewGetItemText from another appThank youGlobal $TV_FIRST = 0x1100 Global $TVM_GETITEM = $TV_FIRST + 12 Global $TVM_GETNEXTITEM = $TV_FIRST + 10 Global $TVGN_CARET = 0x0009 Global $TVIF_TEXT = 0x0001 Run("treeview_app.exe");.au3 WinWaitActive("App with treeview") $hTree = ControlGetHandle("App with treeview", "", "SysTreeView321") ;$hItem = GUICtrlSendMsg($nTree,$TVM_GETNEXTITEM,$TVGN_CARET,0) $result = dllcall("user32.dll","int","SendMessage","hWnd",$hTree,"int",$TVM_GETNEXTITEM,"int",$TVGN_CARET,"int",0) ;Msgbox(0,"hItem",$result[0]); it's OK $sItemText = TreeViewGetItemText($result[0]); it's not OK Msgbox(0,"Item text",$sItemText) Exit Func TreeViewGetItemText($hItem) $szText = "" $TEXT_struct = DllStructCreate("char[260]"); create a text 'area' for receiving the text $TVITEM_struct = DllStructCreate("uint;int;uint;uint;ptr;int;int;int;int;int") DllStructSetData($TVITEM_struct,1,$TVIF_TEXT) DllStructSetData($TVITEM_struct,2,$hItem) DllStructSetData($TVITEM_struct,5,DllStructGetPtr($TEXT_struct)) DllStructSetData($TVITEM_struct,6,260) DllCall("user32.dll","int","SendMessage","hwnd",$hTree,"int",$TVM_GETITEM,"int",0,"ptr",DllStructGetPtr($TVITEM_struct)) $szText = DllStructGetData($TEXT_struct,1) DllStructDelete($TEXT_struct) DllStructDelete($TVITEM_struct) Return $szText EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search
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