GuiTreeView.au3 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508
  1. #include-once
  2. #include "GuiImageList.au3"
  3. #include "Memory.au3"
  4. #include "SendMessage.au3"
  5. #include "StructureConstants.au3"
  6. #include "TreeViewConstants.au3"
  7. #include "UDFGlobalID.au3"
  8. #include "WinAPIConv.au3"
  9. #include "WinAPIGdi.au3"
  10. #include "WinAPIRes.au3"
  11. #include "WinAPISysInternals.au3"
  12. ; #INDEX# =======================================================================================================================
  13. ; Title .........: TreeView
  14. ; AutoIt Version : 3.3.14.5
  15. ; Language ......: English
  16. ; Description ...: Functions that assist with TreeView control management.
  17. ; A TreeView control is a window that displays a hierarchical list of items, such as the headings in a document,
  18. ; the entries in an index, or the files and directories on a disk. Each item consists of a label and an optional
  19. ; bitmapped image, and each item can have a list of subitems associated with it. By clicking an item, the user
  20. ; can expand or collapse the associated list of subitems.
  21. ; Author(s) .....: Paul Campbell (PaulIA), Gary Frost (gafrost), Holger Kotsch
  22. ; ===============================================================================================================================
  23. ; Default treeview item extended structure
  24. ; http://msdn.microsoft.com/en-us/library/bb773459.aspx
  25. ; Min.OS: 2K, NT4 with IE 4.0, 98, 95 with IE 4.0
  26. ; #VARIABLES# ===================================================================================================================
  27. Global $__g_hTVLastWnd
  28. ; ===============================================================================================================================
  29. ; #CONSTANTS# ===================================================================================================================
  30. Global Const $__TREEVIEWCONSTANT_ClassName = "SysTreeView32"
  31. Global Const $__TREEVIEWCONSTANT_WM_SETREDRAW = 0x000B
  32. Global Const $__TREEVIEWCONSTANT_DEFAULT_GUI_FONT = 17
  33. ; ===============================================================================================================================
  34. ; #NO_DOC_FUNCTION# =============================================================================================================
  35. ; Not working/documented/implemented at this time
  36. ;
  37. ; _GUICtrlTreeView_GetOverlayImageIndex
  38. ; _GUICtrlTreeView_MapAccIDToItem
  39. ; _GUICtrlTreeView_MapItemToAccID
  40. ; _GUICtrlTreeView_SetOverlayImageIndex
  41. ; ===============================================================================================================================
  42. ; #CURRENT# =====================================================================================================================
  43. ; _GUICtrlTreeView_Add
  44. ; _GUICtrlTreeView_AddChild
  45. ; _GUICtrlTreeView_AddChildFirst
  46. ; _GUICtrlTreeView_AddFirst
  47. ; _GUICtrlTreeView_BeginUpdate
  48. ; _GUICtrlTreeView_ClickItem
  49. ; _GUICtrlTreeView_Create
  50. ; _GUICtrlTreeView_CreateDragImage
  51. ; _GUICtrlTreeView_CreateSolidBitMap
  52. ; _GUICtrlTreeView_Delete
  53. ; _GUICtrlTreeView_DeleteAll
  54. ; _GUICtrlTreeView_DeleteChildren
  55. ; _GUICtrlTreeView_Destroy
  56. ; _GUICtrlTreeView_DisplayRect
  57. ; _GUICtrlTreeView_DisplayRectEx
  58. ; _GUICtrlTreeView_EditText
  59. ; _GUICtrlTreeView_EndEdit
  60. ; _GUICtrlTreeView_EndUpdate
  61. ; _GUICtrlTreeView_EnsureVisible
  62. ; _GUICtrlTreeView_Expand
  63. ; _GUICtrlTreeView_ExpandedOnce
  64. ; _GUICtrlTreeView_FindItem
  65. ; _GUICtrlTreeView_FindItemEx
  66. ; _GUICtrlTreeView_GetBkColor
  67. ; _GUICtrlTreeView_GetBold
  68. ; _GUICtrlTreeView_GetChecked
  69. ; _GUICtrlTreeView_GetChildCount
  70. ; _GUICtrlTreeView_GetChildren
  71. ; _GUICtrlTreeView_GetCount
  72. ; _GUICtrlTreeView_GetCut
  73. ; _GUICtrlTreeView_GetDropTarget
  74. ; _GUICtrlTreeView_GetEditControl
  75. ; _GUICtrlTreeView_GetExpanded
  76. ; _GUICtrlTreeView_GetFirstChild
  77. ; _GUICtrlTreeView_GetFirstItem
  78. ; _GUICtrlTreeView_GetFirstVisible
  79. ; _GUICtrlTreeView_GetFocused
  80. ; _GUICtrlTreeView_GetHeight
  81. ; _GUICtrlTreeView_GetImageIndex
  82. ; _GUICtrlTreeView_GetImageListIconHandle
  83. ; _GUICtrlTreeView_GetIndent
  84. ; _GUICtrlTreeView_GetInsertMarkColor
  85. ; _GUICtrlTreeView_GetISearchString
  86. ; _GUICtrlTreeView_GetItemByIndex
  87. ; _GUICtrlTreeView_GetItemHandle
  88. ; _GUICtrlTreeView_GetItemParam
  89. ; _GUICtrlTreeView_GetLastChild
  90. ; _GUICtrlTreeView_GetLineColor
  91. ; _GUICtrlTreeView_GetNext
  92. ; _GUICtrlTreeView_GetNextChild
  93. ; _GUICtrlTreeView_GetNextSibling
  94. ; _GUICtrlTreeView_GetNextVisible
  95. ; _GUICtrlTreeView_GetNormalImageList
  96. ; _GUICtrlTreeView_GetParentHandle
  97. ; _GUICtrlTreeView_GetParentParam
  98. ; _GUICtrlTreeView_GetPrev
  99. ; _GUICtrlTreeView_GetPrevChild
  100. ; _GUICtrlTreeView_GetPrevSibling
  101. ; _GUICtrlTreeView_GetPrevVisible
  102. ; _GUICtrlTreeView_GetScrollTime
  103. ; _GUICtrlTreeView_GetSelected
  104. ; _GUICtrlTreeView_GetSelectedImageIndex
  105. ; _GUICtrlTreeView_GetSelection
  106. ; _GUICtrlTreeView_GetSiblingCount
  107. ; _GUICtrlTreeView_GetState
  108. ; _GUICtrlTreeView_GetStateImageIndex
  109. ; _GUICtrlTreeView_GetStateImageList
  110. ; _GUICtrlTreeView_GetText
  111. ; _GUICtrlTreeView_GetTextColor
  112. ; _GUICtrlTreeView_GetToolTips
  113. ; _GUICtrlTreeView_GetTree
  114. ; _GUICtrlTreeView_GetUnicodeFormat
  115. ; _GUICtrlTreeView_GetVisible
  116. ; _GUICtrlTreeView_GetVisibleCount
  117. ; _GUICtrlTreeView_HitTest
  118. ; _GUICtrlTreeView_HitTestEx
  119. ; _GUICtrlTreeView_HitTestItem
  120. ; _GUICtrlTreeView_Index
  121. ; _GUICtrlTreeView_InsertItem
  122. ; _GUICtrlTreeView_IsFirstItem
  123. ; _GUICtrlTreeView_IsParent
  124. ; _GUICtrlTreeView_Level
  125. ; _GUICtrlTreeView_SelectItem
  126. ; _GUICtrlTreeView_SelectItemByIndex
  127. ; _GUICtrlTreeView_SetBkColor
  128. ; _GUICtrlTreeView_SetBold
  129. ; _GUICtrlTreeView_SetChecked
  130. ; _GUICtrlTreeView_SetCheckedByIndex
  131. ; _GUICtrlTreeView_SetChildren
  132. ; _GUICtrlTreeView_SetCut
  133. ; _GUICtrlTreeView_SetDropTarget
  134. ; _GUICtrlTreeView_SetFocused
  135. ; _GUICtrlTreeView_SetHeight
  136. ; _GUICtrlTreeView_SetIcon
  137. ; _GUICtrlTreeView_SetImageIndex
  138. ; _GUICtrlTreeView_SetIndent
  139. ; _GUICtrlTreeView_SetInsertMark
  140. ; _GUICtrlTreeView_SetInsertMarkColor
  141. ; _GUICtrlTreeView_SetItemHeight
  142. ; _GUICtrlTreeView_SetItemParam
  143. ; _GUICtrlTreeView_SetLineColor
  144. ; _GUICtrlTreeView_SetNormalImageList
  145. ; _GUICtrlTreeView_SetScrollTime
  146. ; _GUICtrlTreeView_SetSelected
  147. ; _GUICtrlTreeView_SetSelectedImageIndex
  148. ; _GUICtrlTreeView_SetState
  149. ; _GUICtrlTreeView_SetStateImageIndex
  150. ; _GUICtrlTreeView_SetStateImageList
  151. ; _GUICtrlTreeView_SetText
  152. ; _GUICtrlTreeView_SetTextColor
  153. ; _GUICtrlTreeView_SetToolTips
  154. ; _GUICtrlTreeView_SetUnicodeFormat
  155. ; _GUICtrlTreeView_Sort
  156. ; ===============================================================================================================================
  157. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  158. ; $tagTVINSERTSTRUCT
  159. ; __GUICtrlTreeView_AddItem
  160. ; __GUICtrlTreeView_ExpandItem
  161. ; __GUICtrlTreeView_GetItem
  162. ; __GUICtrlTreeView_ReverseColorOrder
  163. ; __GUICtrlTreeView_SetItem
  164. ; __GUICtrlTreeView_SortGetFirstChild
  165. ; ===============================================================================================================================
  166. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  167. ; Name...........: $tagTVINSERTSTRUCT
  168. ; Description ...: Contains information used to add a new item to a tree-view control
  169. ; Fields ........: Parent - Handle to the parent item. If this member is $TVI_ROOT, the item is inserted at the root
  170. ; InsertAfter - Handle to the item after which the new item is to be inserted, or one of the following values:
  171. ; |$TVI_FIRST - Inserts the item at the beginning of the list
  172. ; |$TVI_LAST - Inserts the item at the end of the list
  173. ; |$TVI_ROOT - Add the item as a root item
  174. ; |$TVI_SORT - Inserts the item into the list in alphabetical order
  175. ; Mask - Flags that indicate which of the other structure members contain valid data:
  176. ; |$TVIF_CHILDREN - The Children member is valid
  177. ; |$TVIF_DI_SETITEM - The will retain the supplied information and will not request it again
  178. ; |$TVIF_HANDLE - The hItem member is valid
  179. ; |$TVIF_IMAGE - The Image member is valid
  180. ; |$TVIF_INTEGRAL - The Integral member is valid
  181. ; |$TVIF_PARAM - The Param member is valid
  182. ; |$TVIF_SELECTEDIMAGE - The SelectedImage member is valid
  183. ; |$TVIF_STATE - The State and StateMask members are valid
  184. ; |$TVIF_TEXT - The Text and TextMax members are valid
  185. ; hItem - Item to which this structure refers
  186. ; State - Set of bit flags and image list indexes that indicate the item's state. When setting the state
  187. ; +of an item, the StateMask member indicates the bits of this member that are valid. When retrieving the state
  188. ; +of an item, this member returns the current state for the bits indicated in the StateMask member. Bits 0
  189. ; +through 7 of this member contain the item state flags. Bits 8 through 11 of this member specify the one based
  190. ; +overlay image index.
  191. ; StateMask - Bits of the state member that are valid. If you are retrieving an item's state, set the bits
  192. ; +of the stateMask member to indicate the bits to be returned in the state member. If you are setting an item's
  193. ; +state, set the bits of the stateMask member to indicate the bits of the state member that you want to set.
  194. ; Text - Pointer to a null-terminated string that contains the item text.
  195. ; TextMax - Size of the buffer pointed to by the Text member, in characters
  196. ; Image - Index in the image list of the icon image to use when the item is in the nonselected state
  197. ; SelectedImage - Index in the image list of the icon image to use when the item is in the selected state
  198. ; Children - Flag that indicates whether the item has associated child items. This member can be one of the
  199. ; +following values:
  200. ; |0 - The item has no child items
  201. ; |1 - The item has one or more child items
  202. ; Param - A value to associate with the item
  203. ; Integral - Height of the item
  204. ; Author ........: Paul Campbell (PaulIA)
  205. ; Modified ......: jpm
  206. ; Remarks .......:
  207. ; ===============================================================================================================================
  208. Global Const $tagTVINSERTSTRUCT = "handle Parent;handle InsertAfter;" & $tagTVITEMEX
  209. ; #FUNCTION# ====================================================================================================================
  210. ; Author ........: Paul Campbell (PaulIA)
  211. ; Modified.......: Gary Frost (gafrost)
  212. ; ===============================================================================================================================
  213. Func _GUICtrlTreeView_Add($hWnd, $hSibling, $sText, $iImage = -1, $iSelImage = -1)
  214. Return __GUICtrlTreeView_AddItem($hWnd, $hSibling, $sText, $TVNA_ADD, $iImage, $iSelImage)
  215. EndFunc ;==>_GUICtrlTreeView_Add
  216. ; #FUNCTION# ====================================================================================================================
  217. ; Author ........: Paul Campbell (PaulIA)
  218. ; Modified.......: Gary Frost (gafrost)
  219. ; ===============================================================================================================================
  220. Func _GUICtrlTreeView_AddChild($hWnd, $hParent, $sText, $iImage = -1, $iSelImage = -1)
  221. Return __GUICtrlTreeView_AddItem($hWnd, $hParent, $sText, $TVNA_ADDCHILD, $iImage, $iSelImage)
  222. EndFunc ;==>_GUICtrlTreeView_AddChild
  223. ; #FUNCTION# ====================================================================================================================
  224. ; Author ........: Paul Campbell (PaulIA)
  225. ; Modified.......: Gary Frost (gafrost)
  226. ; ===============================================================================================================================
  227. Func _GUICtrlTreeView_AddChildFirst($hWnd, $hParent, $sText, $iImage = -1, $iSelImage = -1)
  228. Return __GUICtrlTreeView_AddItem($hWnd, $hParent, $sText, $TVNA_ADDCHILDFIRST, $iImage, $iSelImage)
  229. EndFunc ;==>_GUICtrlTreeView_AddChildFirst
  230. ; #FUNCTION# ====================================================================================================================
  231. ; Author ........: Paul Campbell (PaulIA)
  232. ; Modified.......: Gary Frost (gafrost)
  233. ; ===============================================================================================================================
  234. Func _GUICtrlTreeView_AddFirst($hWnd, $hSibling, $sText, $iImage = -1, $iSelImage = -1)
  235. Return __GUICtrlTreeView_AddItem($hWnd, $hSibling, $sText, $TVNA_ADDFIRST, $iImage, $iSelImage)
  236. EndFunc ;==>_GUICtrlTreeView_AddFirst
  237. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  238. ; Name...........: __GUICtrlTreeView_AddItem
  239. ; Description ...: Add a new item
  240. ; Syntax.........: __GUICtrlTreeView_AddItem ( $hWnd, $hRelative, $sText, $iMethod [, $iImage = -1 [, $iSelImage = -1]] )
  241. ; Parameters ....: $hWnd - Handle to the control
  242. ; $hRelative - Handle to an existing item that will be either parent or sibling to the new item
  243. ; $sText - The text for the new item
  244. ; $iMethod - The relationship between the new item and the $hRelative item
  245. ; |$TVNA_ADD - The item becomes the last sibling of the other item
  246. ; |$TVNA_ADDFIRST - The item becomes the first sibling of the other item
  247. ; |$TVNA_ADDCHILD - The item becomes the sibling before the other item
  248. ; |$TVNA_ADDCHILDFIRST - The item becomes the last child of the other item
  249. ; |$TVNA_INSERT - The item becomes the first child of the other item
  250. ; $iImage - Zero based index of the item's icon in the control's image list
  251. ; $iSelImage - Zero based index of the item's icon in the control's image list
  252. ; $iParam - Application Defined Data
  253. ; Return values .: Success - The handle to the new item
  254. ; Failure - 0
  255. ; Author ........: Paul Campbell (PaulIA)
  256. ; Modified.......: Gary Frost (gafrost)
  257. ; Remarks .......: This function is for interall use only and should not normally be called by the end user
  258. ; Related .......:
  259. ; Link ..........:
  260. ; Example .......:
  261. ; ===============================================================================================================================
  262. Func __GUICtrlTreeView_AddItem($hWnd, $hRelative, $sText, $iMethod, $iImage = -1, $iSelImage = -1, $iParam = 0)
  263. Local $iAddMode
  264. Switch $iMethod
  265. Case $TVNA_ADD, $TVNA_ADDCHILD
  266. $iAddMode = $TVTA_ADD
  267. Case $TVNA_ADDFIRST, $TVNA_ADDCHILDFIRST
  268. $iAddMode = $TVTA_ADDFIRST
  269. Case Else
  270. $iAddMode = $TVTA_INSERT
  271. EndSwitch
  272. Local $hItem, $hItemID = 0
  273. If $hRelative <> 0x00000000 Then
  274. Switch $iMethod
  275. Case $TVNA_ADD, $TVNA_ADDFIRST
  276. $hItem = _GUICtrlTreeView_GetParentHandle($hWnd, $hRelative)
  277. Case $TVNA_ADDCHILD, $TVNA_ADDCHILDFIRST
  278. $hItem = $hRelative
  279. Case Else
  280. $hItem = _GUICtrlTreeView_GetParentHandle($hWnd, $hRelative)
  281. $hItemID = _GUICtrlTreeView_GetPrevSibling($hWnd, $hRelative)
  282. If $hItemID = 0x00000000 Then $iAddMode = $TVTA_ADDFIRST
  283. EndSwitch
  284. EndIf
  285. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  286. Local $iBuffer = StringLen($sText) + 1
  287. Local $tBuffer
  288. Local $bUnicode = _GUICtrlTreeView_GetUnicodeFormat($hWnd)
  289. If $bUnicode Then
  290. $tBuffer = DllStructCreate("wchar Text[" & $iBuffer & "]")
  291. $iBuffer *= 2
  292. Else
  293. $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]")
  294. EndIf
  295. Local $tInsert = DllStructCreate($tagTVINSERTSTRUCT)
  296. Switch $iAddMode
  297. Case $TVTA_ADDFIRST
  298. DllStructSetData($tInsert, "InsertAfter", $TVI_FIRST)
  299. Case $TVTA_ADD
  300. DllStructSetData($tInsert, "InsertAfter", $TVI_LAST)
  301. Case $TVTA_INSERT
  302. DllStructSetData($tInsert, "InsertAfter", $hItemID)
  303. EndSwitch
  304. Local $iMask = BitOR($TVIF_TEXT, $TVIF_PARAM)
  305. If $iImage >= 0 Then $iMask = BitOR($iMask, $TVIF_IMAGE)
  306. If $iSelImage >= 0 Then $iMask = BitOR($iMask, $TVIF_SELECTEDIMAGE)
  307. DllStructSetData($tBuffer, "Text", $sText)
  308. DllStructSetData($tInsert, "Parent", $hItem)
  309. DllStructSetData($tInsert, "Mask", $iMask)
  310. DllStructSetData($tInsert, "TextMax", $iBuffer)
  311. DllStructSetData($tInsert, "Image", $iImage)
  312. DllStructSetData($tInsert, "SelectedImage", $iSelImage)
  313. DllStructSetData($tInsert, "Param", $iParam)
  314. Local $hResult
  315. If _WinAPI_InProcess($hWnd, $__g_hTVLastWnd) Then
  316. DllStructSetData($tInsert, "Text", DllStructGetPtr($tBuffer))
  317. $hResult = _SendMessage($hWnd, $TVM_INSERTITEMW, 0, $tInsert, 0, "wparam", "struct*", "handle")
  318. Else
  319. Local $iInsert = DllStructGetSize($tInsert)
  320. Local $tMemMap
  321. Local $pMemory = _MemInit($hWnd, $iInsert + $iBuffer, $tMemMap)
  322. Local $pText = $pMemory + $iInsert
  323. _MemWrite($tMemMap, $tInsert, $pMemory, $iInsert)
  324. _MemWrite($tMemMap, $tBuffer, $pText, $iBuffer)
  325. DllStructSetData($tInsert, "Text", $pText)
  326. If $bUnicode Then
  327. $hResult = _SendMessage($hWnd, $TVM_INSERTITEMW, 0, $pMemory, 0, "wparam", "ptr", "handle")
  328. Else
  329. $hResult = _SendMessage($hWnd, $TVM_INSERTITEMA, 0, $pMemory, 0, "wparam", "ptr", "handle")
  330. EndIf
  331. _MemFree($tMemMap)
  332. EndIf
  333. Return $hResult
  334. EndFunc ;==>__GUICtrlTreeView_AddItem
  335. ; #FUNCTION# ====================================================================================================================
  336. ; Author ........: Paul Campbell (PaulIA)
  337. ; Modified.......: Gary Frost (gafrost)
  338. ; ===============================================================================================================================
  339. Func _GUICtrlTreeView_BeginUpdate($hWnd)
  340. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  341. Return _SendMessage($hWnd, $__TREEVIEWCONSTANT_WM_SETREDRAW, False) = 0
  342. EndFunc ;==>_GUICtrlTreeView_BeginUpdate
  343. ; #FUNCTION# ====================================================================================================================
  344. ; Author ........: Paul Campbell (PaulIA)
  345. ; Modified.......: Gary Frost
  346. ; ===============================================================================================================================
  347. Func _GUICtrlTreeView_ClickItem($hWnd, $hItem, $sButton = "left", $bMove = False, $iClicks = 1, $iSpeed = 0)
  348. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  349. Local $tRECT = _GUICtrlTreeView_DisplayRectEx($hWnd, $hItem, True)
  350. If @error Then Return SetError(@error, @error, 0)
  351. ; Always click on the left-most portion of the control, not the center. A
  352. ; very wide control may be off-screen which means clicking on it's center
  353. ; will click outside the window.
  354. Local $tPoint = _WinAPI_PointFromRect($tRECT, False)
  355. _WinAPI_ClientToScreen($hWnd, $tPoint)
  356. Local $iX, $iY
  357. _WinAPI_GetXYFromPoint($tPoint, $iX, $iY)
  358. Local $iMode = Opt("MouseCoordMode", 1)
  359. If Not $bMove Then
  360. Local $aPos = MouseGetPos()
  361. _WinAPI_ShowCursor(False)
  362. MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
  363. MouseMove($aPos[0], $aPos[1], 0)
  364. _WinAPI_ShowCursor(True)
  365. Else
  366. MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
  367. EndIf
  368. Opt("MouseCoordMode", $iMode)
  369. Return 1
  370. EndFunc ;==>_GUICtrlTreeView_ClickItem
  371. ; #FUNCTION# ====================================================================================================================
  372. ; Author ........: Paul Campbell (PaulIA)
  373. ; Modified.......: Gary Frost
  374. ; ===============================================================================================================================
  375. Func _GUICtrlTreeView_Create($hWnd, $iX, $iY, $iWidth = 150, $iHeight = 150, $iStyle = 0x00000037, $iExStyle = 0x00000000)
  376. If Not IsHWnd($hWnd) Then
  377. ; Invalid Window handle for _GUICtrlTreeView_Create 1st parameter
  378. Return SetError(1, 0, 0)
  379. EndIf
  380. If $iWidth = -1 Then $iWidth = 150
  381. If $iHeight = -1 Then $iHeight = 150
  382. If $iStyle = -1 Then $iStyle = BitOR($TVS_SHOWSELALWAYS, $TVS_DISABLEDRAGDROP, $TVS_LINESATROOT, $TVS_HASLINES, $TVS_HASBUTTONS)
  383. If $iExStyle = -1 Then $iExStyle = 0x00000000
  384. $iStyle = BitOR($iStyle, $__UDFGUICONSTANT_WS_CHILD, $__UDFGUICONSTANT_WS_VISIBLE)
  385. Local $nCtrlID = __UDF_GetNextGlobalID($hWnd)
  386. If @error Then Return SetError(@error, @extended, 0)
  387. Local $hTree = _WinAPI_CreateWindowEx($iExStyle, $__TREEVIEWCONSTANT_ClassName, "", $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd, $nCtrlID)
  388. _WinAPI_SetFont($hTree, _WinAPI_GetStockObject($__TREEVIEWCONSTANT_DEFAULT_GUI_FONT))
  389. Return $hTree
  390. EndFunc ;==>_GUICtrlTreeView_Create
  391. ; #FUNCTION# ====================================================================================================================
  392. ; Author ........: Paul Campbell (PaulIA)
  393. ; Modified.......: Gary Frost (gafrost)
  394. ; ===============================================================================================================================
  395. Func _GUICtrlTreeView_CreateDragImage($hWnd, $hItem)
  396. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  397. Return _SendMessage($hWnd, $TVM_CREATEDRAGIMAGE, 0, $hItem, 0, "wparam", "handle", "handle")
  398. EndFunc ;==>_GUICtrlTreeView_CreateDragImage
  399. ; #FUNCTION# ====================================================================================================================
  400. ; Author ........: Gary Frost (gafrost)
  401. ; Modified.......:
  402. ; ===============================================================================================================================
  403. Func _GUICtrlTreeView_CreateSolidBitMap($hWnd, $iColor, $iWidth, $iHeight)
  404. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  405. Return _WinAPI_CreateSolidBitmap($hWnd, $iColor, $iWidth, $iHeight)
  406. EndFunc ;==>_GUICtrlTreeView_CreateSolidBitMap
  407. ; #FUNCTION# ====================================================================================================================
  408. ; Author ........: Gary Frost (gafrost)
  409. ; Modified.......: re-written by Holger Kotsch, re-written again by Gary Frost
  410. ; ===============================================================================================================================
  411. Func _GUICtrlTreeView_Delete($hWnd, $hItem = 0)
  412. If $hItem = 0 Then $hItem = 0x00000000
  413. If IsHWnd($hWnd) Then
  414. If $hItem = 0x00000000 Then
  415. $hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0, 0, "wparam", "handle", "handle")
  416. If $hItem <> 0x00000000 Then Return _SendMessage($hWnd, $TVM_DELETEITEM, 0, $hItem, 0, "wparam", "handle", "hwnd") <> 0
  417. Return False
  418. Else
  419. If GUICtrlDelete($hItem) Then Return True
  420. Return _SendMessage($hWnd, $TVM_DELETEITEM, 0, $hItem, 0, "wparam", "handle", "hwnd") <> 0
  421. EndIf
  422. Else
  423. If $hItem = 0x00000000 Then
  424. $hItem = GUICtrlSendMsg($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0)
  425. If $hItem <> 0x00000000 Then Return GUICtrlSendMsg($hWnd, $TVM_DELETEITEM, 0, $hItem) <> 0
  426. Return False
  427. Else
  428. If GUICtrlDelete($hItem) Then Return True
  429. Return GUICtrlSendMsg($hWnd, $TVM_DELETEITEM, 0, $hItem) <> 0
  430. EndIf
  431. EndIf
  432. EndFunc ;==>_GUICtrlTreeView_Delete
  433. ; #FUNCTION# ====================================================================================================================
  434. ; Author ........: Gary Frost (gafrost)
  435. ; Modified.......:
  436. ; ===============================================================================================================================
  437. Func _GUICtrlTreeView_DeleteAll($hWnd)
  438. Local $iCount = 0
  439. If IsHWnd($hWnd) Then
  440. _SendMessage($hWnd, $TVM_DELETEITEM, 0, $TVI_ROOT)
  441. $iCount = _GUICtrlTreeView_GetCount($hWnd) ; might be created with autoit create
  442. If $iCount Then Return GUICtrlSendMsg($hWnd, $TVM_DELETEITEM, 0, $TVI_ROOT) <> 0
  443. Return True
  444. Else
  445. GUICtrlSendMsg($hWnd, $TVM_DELETEITEM, 0, $TVI_ROOT)
  446. $iCount = _GUICtrlTreeView_GetCount($hWnd) ; might be created with udf
  447. If $iCount Then Return _SendMessage($hWnd, $TVM_DELETEITEM, 0, $TVI_ROOT) <> 0
  448. Return True
  449. EndIf
  450. Return False
  451. EndFunc ;==>_GUICtrlTreeView_DeleteAll
  452. ; #FUNCTION# ====================================================================================================================
  453. ; Author ........: Paul Campbell (PaulIA)
  454. ; Modified.......: Gary Frost (gafrost)
  455. ; ===============================================================================================================================
  456. Func _GUICtrlTreeView_DeleteChildren($hWnd, $hItem)
  457. Local $bResult
  458. If IsHWnd($hWnd) Then
  459. $bResult = _SendMessage($hWnd, $TVM_EXPAND, BitOR($TVE_COLLAPSE, $TVE_COLLAPSERESET), $hItem, 0, "wparam", "handle")
  460. Else
  461. $bResult = GUICtrlSendMsg($hWnd, $TVM_EXPAND, BitOR($TVE_COLLAPSE, $TVE_COLLAPSERESET), $hItem)
  462. EndIf
  463. Return $bResult
  464. EndFunc ;==>_GUICtrlTreeView_DeleteChildren
  465. ; #FUNCTION# ====================================================================================================================
  466. ; Author ........: Gary Frost (gafrost)
  467. ; Modified.......:
  468. ; ===============================================================================================================================
  469. Func _GUICtrlTreeView_Destroy(ByRef $hWnd)
  470. ;If Not _WinAPI_IsClassName($hWnd, $__TREEVIEWCONSTANT_ClassName) Then Return SetError(2, 2, False)
  471. Local $iDestroyed = 0
  472. If IsHWnd($hWnd) Then
  473. If _WinAPI_InProcess($hWnd, $__g_hTVLastWnd) Then
  474. Local $nCtrlID = _WinAPI_GetDlgCtrlID($hWnd)
  475. Local $hParent = _WinAPI_GetParent($hWnd)
  476. $iDestroyed = _WinAPI_DestroyWindow($hWnd)
  477. Local $iRet = __UDF_FreeGlobalID($hParent, $nCtrlID)
  478. If Not $iRet Then
  479. ; can check for errors here if needed, for debug
  480. EndIf
  481. Else
  482. ; Not Allowed to Destroy Other Applications Control(s)
  483. Return SetError(1, 1, False)
  484. EndIf
  485. Else
  486. $iDestroyed = GUICtrlDelete($hWnd)
  487. EndIf
  488. If $iDestroyed Then $hWnd = 0
  489. Return $iDestroyed <> 0
  490. EndFunc ;==>_GUICtrlTreeView_Destroy
  491. ; #FUNCTION# ====================================================================================================================
  492. ; Author ........: Paul Campbell (PaulIA)
  493. ; Modified.......:
  494. ; ===============================================================================================================================
  495. Func _GUICtrlTreeView_DisplayRect($hWnd, $hItem, $bTextOnly = False)
  496. Local $tRECT = _GUICtrlTreeView_DisplayRectEx($hWnd, $hItem, $bTextOnly)
  497. If @error Then Return SetError(@error, @error, 0)
  498. Local $aRect[4]
  499. $aRect[0] = DllStructGetData($tRECT, "Left")
  500. $aRect[1] = DllStructGetData($tRECT, "Top")
  501. $aRect[2] = DllStructGetData($tRECT, "Right")
  502. $aRect[3] = DllStructGetData($tRECT, "Bottom")
  503. Return $aRect
  504. EndFunc ;==>_GUICtrlTreeView_DisplayRect
  505. ; #FUNCTION# ====================================================================================================================
  506. ; Author ........: Paul Campbell (PaulIA)
  507. ; Modified.......: Gary Frost (gafrost)
  508. ; ===============================================================================================================================
  509. Func _GUICtrlTreeView_DisplayRectEx($hWnd, $hItem, $bTextOnly = False)
  510. Local $tRECT = DllStructCreate($tagRECT)
  511. Local $iRet
  512. If IsHWnd($hWnd) Then
  513. ; RECT is expected to point to the item in its first member.
  514. DllStructSetData($tRECT, "Left", $hItem)
  515. If _WinAPI_InProcess($hWnd, $__g_hTVLastWnd) Then
  516. $iRet = _SendMessage($hWnd, $TVM_GETITEMRECT, $bTextOnly, $tRECT, 0, "wparam", "struct*")
  517. Else
  518. Local $iRect = DllStructGetSize($tRECT)
  519. Local $tMemMap
  520. Local $pMemory = _MemInit($hWnd, $iRect, $tMemMap)
  521. _MemWrite($tMemMap, $tRECT)
  522. $iRet = _SendMessage($hWnd, $TVM_GETITEMRECT, $bTextOnly, $pMemory, 0, "wparam", "ptr")
  523. _MemRead($tMemMap, $pMemory, $tRECT, $iRect)
  524. _MemFree($tMemMap)
  525. EndIf
  526. Else
  527. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  528. ; RECT is expected to point to the item in its first member.
  529. DllStructSetData($tRECT, "Left", $hItem)
  530. $iRet = GUICtrlSendMsg($hWnd, $TVM_GETITEMRECT, $bTextOnly, DllStructGetPtr($tRECT))
  531. EndIf
  532. ; On failure ensure Left is set to 0 and not the item handle.
  533. If Not $iRet Then DllStructSetData($tRECT, "Left", 0)
  534. Return SetError($iRet = 0, $iRet, $tRECT)
  535. EndFunc ;==>_GUICtrlTreeView_DisplayRectEx
  536. ; #FUNCTION# ====================================================================================================================
  537. ; Author ........: Paul Campbell (PaulIA)
  538. ; Modified.......: Gary Frost (gafrost)
  539. ; ===============================================================================================================================
  540. Func _GUICtrlTreeView_EditText($hWnd, $hItem)
  541. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  542. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  543. _WinAPI_SetFocus($hWnd)
  544. Local $bUnicode = _GUICtrlTreeView_GetUnicodeFormat($hWnd)
  545. If $bUnicode Then
  546. Return _SendMessage($hWnd, $TVM_EDITLABELW, 0, $hItem, 0, "wparam", "handle", "handle")
  547. Else
  548. Return _SendMessage($hWnd, $TVM_EDITLABELA, 0, $hItem, 0, "wparam", "handle", "handle")
  549. EndIf
  550. EndFunc ;==>_GUICtrlTreeView_EditText
  551. ; #FUNCTION# ====================================================================================================================
  552. ; Author ........: Paul Campbell (PaulIA)
  553. ; Modified.......: Gary Frost (gafrost)
  554. ; ===============================================================================================================================
  555. Func _GUICtrlTreeView_EndEdit($hWnd, $bCancel = False)
  556. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  557. Return _SendMessage($hWnd, $TVM_ENDEDITLABELNOW, $bCancel) <> 0
  558. EndFunc ;==>_GUICtrlTreeView_EndEdit
  559. ; #FUNCTION# ====================================================================================================================
  560. ; Author ........: Paul Campbell (PaulIA)
  561. ; Modified.......: Gary Frost (gafrost)
  562. ; ===============================================================================================================================
  563. Func _GUICtrlTreeView_EndUpdate($hWnd)
  564. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  565. Return _SendMessage($hWnd, $__TREEVIEWCONSTANT_WM_SETREDRAW, True) = 0
  566. EndFunc ;==>_GUICtrlTreeView_EndUpdate
  567. ; #FUNCTION# ====================================================================================================================
  568. ; Author ........: Gary Frost (gafrost)
  569. ; Modified.......:
  570. ; ===============================================================================================================================
  571. Func _GUICtrlTreeView_EnsureVisible($hWnd, $hItem)
  572. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  573. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  574. Return _SendMessage($hWnd, $TVM_ENSUREVISIBLE, 0, $hItem, 0, "wparam", "handle") <> 0
  575. EndFunc ;==>_GUICtrlTreeView_EnsureVisible
  576. ; #FUNCTION# ====================================================================================================================
  577. ; Author ........: Holger Kotsch
  578. ; Modified.......: Gary Frost
  579. ; ===============================================================================================================================
  580. Func _GUICtrlTreeView_Expand($hWnd, $hItem = 0, $bExpand = True)
  581. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  582. If $hItem = 0 Then $hItem = 0x00000000
  583. If $hItem = 0x00000000 Then
  584. $hItem = $TVI_ROOT
  585. Else
  586. If Not IsHWnd($hItem) Then
  587. Local $hItem_tmp = GUICtrlGetHandle($hItem)
  588. If $hItem_tmp <> 0x00000000 Then $hItem = $hItem_tmp
  589. EndIf
  590. EndIf
  591. If $bExpand Then
  592. __GUICtrlTreeView_ExpandItem($hWnd, $TVE_EXPAND, $hItem)
  593. Else
  594. __GUICtrlTreeView_ExpandItem($hWnd, $TVE_COLLAPSE, $hItem)
  595. EndIf
  596. EndFunc ;==>_GUICtrlTreeView_Expand
  597. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  598. ; Name...........: __GUICtrlTreeView_ExpandItem($hWnd, $iExpand, $hItem)
  599. ; Description ...: Expands/Collapes the item and child(ren), if any
  600. ; Syntax.........: __GUICtrlTreeView_ExpandItem ( $hWnd, $iExpand, $hItem )
  601. ; Parameters ....: $hWnd - Handle to the control
  602. ; Return values .:
  603. ; Author ........: Holger Kotsch
  604. ; Modified.......: Gary Frost (gafrost)
  605. ; Remarks .......:
  606. ; Related .......:
  607. ; Link ..........:
  608. ; Example .......:
  609. ; ===============================================================================================================================
  610. Func __GUICtrlTreeView_ExpandItem($hWnd, $iExpand, $hItem)
  611. If Not IsHWnd($hWnd) Then
  612. If $hItem = 0x00000000 Then
  613. $hItem = $TVI_ROOT
  614. Else
  615. $hItem = GUICtrlGetHandle($hItem)
  616. If $hItem = 0 Then Return
  617. EndIf
  618. $hWnd = GUICtrlGetHandle($hWnd)
  619. EndIf
  620. _SendMessage($hWnd, $TVM_EXPAND, $iExpand, $hItem, 0, "wparam", "handle")
  621. If $iExpand = $TVE_EXPAND And $hItem > 0 Then _SendMessage($hWnd, $TVM_ENSUREVISIBLE, 0, $hItem, 0, "wparam", "handle")
  622. $hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CHILD, $hItem, 0, "wparam", "handle")
  623. While $hItem <> 0x00000000
  624. Local $hChild = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CHILD, $hItem, 0, "wparam", "handle")
  625. If $hChild <> 0x00000000 Then __GUICtrlTreeView_ExpandItem($hWnd, $iExpand, $hItem)
  626. $hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_NEXT, $hItem, 0, "wparam", "handle")
  627. WEnd
  628. EndFunc ;==>__GUICtrlTreeView_ExpandItem
  629. ; #FUNCTION# ====================================================================================================================
  630. ; Author ........: Paul Campbell (PaulIA)
  631. ; Modified.......:
  632. ; ===============================================================================================================================
  633. Func _GUICtrlTreeView_ExpandedOnce($hWnd, $hItem)
  634. Return BitAND(_GUICtrlTreeView_GetState($hWnd, $hItem), $TVIS_EXPANDEDONCE) <> 0
  635. EndFunc ;==>_GUICtrlTreeView_ExpandedOnce
  636. ; #FUNCTION# ====================================================================================================================
  637. ; Author ........: Paul Campbell (PaulIA)
  638. ; Modified.......:
  639. ; ===============================================================================================================================
  640. Func _GUICtrlTreeView_FindItem($hWnd, $sText, $bInStr = False, $hStart = 0)
  641. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  642. If $hStart = 0 Then $hStart = _GUICtrlTreeView_GetFirstItem($hWnd)
  643. While $hStart <> 0x00000000
  644. Local $sItem = _GUICtrlTreeView_GetText($hWnd, $hStart)
  645. Switch $bInStr
  646. Case False
  647. If $sItem = $sText Then Return $hStart
  648. Case True
  649. If StringInStr($sItem, $sText) Then Return $hStart
  650. EndSwitch
  651. $hStart = _GUICtrlTreeView_GetNext($hWnd, $hStart)
  652. WEnd
  653. EndFunc ;==>_GUICtrlTreeView_FindItem
  654. ; #FUNCTION# ====================================================================================================================
  655. ; Author ........: Miguel Pilar (luckyb), Paul Campbell (PaulIA)
  656. ; Modified.......:
  657. ; ===============================================================================================================================
  658. Func _GUICtrlTreeView_FindItemEx($hWnd, $sTreePath, $hStart = 0)
  659. Local $sDelimiter = Opt("GUIDataSeparatorChar")
  660. Local $iIndex = 1
  661. Local $aParts = StringSplit($sTreePath, $sDelimiter)
  662. If $hStart = 0 Then $hStart = _GUICtrlTreeView_GetFirstItem($hWnd)
  663. While ($iIndex <= $aParts[0]) And ($hStart <> 0x00000000)
  664. If StringStripWS(_GUICtrlTreeView_GetText($hWnd, $hStart), $STR_STRIPLEADING + $STR_STRIPTRAILING) = StringStripWS($aParts[$iIndex], $STR_STRIPLEADING + $STR_STRIPTRAILING) Then
  665. If $iIndex = $aParts[0] Then Return $hStart
  666. $iIndex += 1
  667. __GUICtrlTreeView_ExpandItem($hWnd, $TVE_EXPAND, $hStart)
  668. $hStart = _GUICtrlTreeView_GetFirstChild($hWnd, $hStart)
  669. Else
  670. $hStart = _GUICtrlTreeView_GetNextSibling($hWnd, $hStart)
  671. __GUICtrlTreeView_ExpandItem($hWnd, $TVE_COLLAPSE, $hStart)
  672. EndIf
  673. WEnd
  674. Return $hStart
  675. EndFunc ;==>_GUICtrlTreeView_FindItemEx
  676. ; #FUNCTION# ====================================================================================================================
  677. ; Author ........: Gary Frost (gafrost)
  678. ; Modified.......:
  679. ; ===============================================================================================================================
  680. Func _GUICtrlTreeView_GetBkColor($hWnd)
  681. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  682. Local $sHex = Hex(String(_SendMessage($hWnd, $TVM_GETBKCOLOR)), 6)
  683. Return '0x' & StringMid($sHex, 5, 2) & StringMid($sHex, 3, 2) & StringMid($sHex, 1, 2)
  684. EndFunc ;==>_GUICtrlTreeView_GetBkColor
  685. ; #FUNCTION# ====================================================================================================================
  686. ; Author ........: Paul Campbell (PaulIA)
  687. ; Modified.......:
  688. ; ===============================================================================================================================
  689. Func _GUICtrlTreeView_GetBold($hWnd, $hItem)
  690. Return BitAND(_GUICtrlTreeView_GetState($hWnd, $hItem), $TVIS_BOLD) <> 0
  691. EndFunc ;==>_GUICtrlTreeView_GetBold
  692. ; #FUNCTION# ====================================================================================================================
  693. ; Author ........: Gary Frost (gafrost)
  694. ; Modified.......:
  695. ; ===============================================================================================================================
  696. Func _GUICtrlTreeView_GetChecked($hWnd, $hItem)
  697. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  698. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  699. Local $tItem = DllStructCreate($tagTVITEMEX)
  700. DllStructSetData($tItem, "Mask", $TVIF_STATE)
  701. DllStructSetData($tItem, "hItem", $hItem)
  702. __GUICtrlTreeView_GetItem($hWnd, $tItem)
  703. Return BitAND(DllStructGetData($tItem, "State"), $TVIS_CHECKED) = $TVIS_CHECKED
  704. EndFunc ;==>_GUICtrlTreeView_GetChecked
  705. ; #FUNCTION# ====================================================================================================================
  706. ; Author ........: Gary Frost (gafrost)
  707. ; Modified.......:
  708. ; ===============================================================================================================================
  709. Func _GUICtrlTreeView_GetChildCount($hWnd, $hItem)
  710. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  711. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  712. Local $iRet = 0
  713. Local $hNext = _GUICtrlTreeView_GetFirstChild($hWnd, $hItem)
  714. If $hNext = 0x00000000 Then Return -1
  715. Do
  716. $iRet += 1
  717. $hNext = _GUICtrlTreeView_GetNextSibling($hWnd, $hNext)
  718. Until $hNext = 0x00000000
  719. Return $iRet
  720. EndFunc ;==>_GUICtrlTreeView_GetChildCount
  721. ; #FUNCTION# ====================================================================================================================
  722. ; Author ........: Paul Campbell (PaulIA)
  723. ; Modified.......: Gary Frost (gafrost)
  724. ; ===============================================================================================================================
  725. Func _GUICtrlTreeView_GetChildren($hWnd, $hItem)
  726. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  727. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  728. Local $tItem = DllStructCreate($tagTVITEMEX)
  729. DllStructSetData($tItem, "Mask", $TVIF_CHILDREN)
  730. DllStructSetData($tItem, "hItem", $hItem)
  731. __GUICtrlTreeView_GetItem($hWnd, $tItem)
  732. Return DllStructGetData($tItem, "Children") <> 0
  733. EndFunc ;==>_GUICtrlTreeView_GetChildren
  734. ; #FUNCTION# ====================================================================================================================
  735. ; Author ........: Gary Frost (gafrost)
  736. ; Modified.......:
  737. ; ===============================================================================================================================
  738. Func _GUICtrlTreeView_GetCount($hWnd)
  739. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  740. Return _SendMessage($hWnd, $TVM_GETCOUNT)
  741. EndFunc ;==>_GUICtrlTreeView_GetCount
  742. ; #FUNCTION# ====================================================================================================================
  743. ; Author ........: Paul Campbell (PaulIA)
  744. ; Modified.......:
  745. ; ===============================================================================================================================
  746. Func _GUICtrlTreeView_GetCut($hWnd, $hItem)
  747. Return BitAND(_GUICtrlTreeView_GetState($hWnd, $hItem), $TVIS_CUT) <> 0
  748. EndFunc ;==>_GUICtrlTreeView_GetCut
  749. ; #FUNCTION# ====================================================================================================================
  750. ; Author ........: Paul Campbell (PaulIA)
  751. ; Modified.......:
  752. ; ===============================================================================================================================
  753. Func _GUICtrlTreeView_GetDropTarget($hWnd, $hItem)
  754. Return BitAND(_GUICtrlTreeView_GetState($hWnd, $hItem), $TVIS_DROPHILITED) <> 0
  755. EndFunc ;==>_GUICtrlTreeView_GetDropTarget
  756. ; #FUNCTION# ====================================================================================================================
  757. ; Author ........: Paul Campbell (PaulIA)
  758. ; Modified.......: Gary Frost (gafrost)
  759. ; ===============================================================================================================================
  760. Func _GUICtrlTreeView_GetEditControl($hWnd)
  761. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  762. Return _SendMessage($hWnd, $TVM_GETEDITCONTROL, 0, 0, 0, "wparam", "lparam", "handle")
  763. EndFunc ;==>_GUICtrlTreeView_GetEditControl
  764. ; #FUNCTION# ====================================================================================================================
  765. ; Author ........: Paul Campbell (PaulIA)
  766. ; Modified.......:
  767. ; ===============================================================================================================================
  768. Func _GUICtrlTreeView_GetExpanded($hWnd, $hItem)
  769. Return BitAND(_GUICtrlTreeView_GetState($hWnd, $hItem), $TVIS_EXPANDED) <> 0
  770. EndFunc ;==>_GUICtrlTreeView_GetExpanded
  771. ; #FUNCTION# ====================================================================================================================
  772. ; Author ........: Paul Campbell (PaulIA)
  773. ; Modified.......: Gary Frost (gafrost)
  774. ; ===============================================================================================================================
  775. Func _GUICtrlTreeView_GetFirstChild($hWnd, $hItem)
  776. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  777. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  778. Return _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CHILD, $hItem, 0, "wparam", "handle", "handle")
  779. EndFunc ;==>_GUICtrlTreeView_GetFirstChild
  780. ; #FUNCTION# ====================================================================================================================
  781. ; Author ........: Paul Campbell (PaulIA)
  782. ; Modified.......: Gary Frost (gafrost)
  783. ; ===============================================================================================================================
  784. Func _GUICtrlTreeView_GetFirstItem($hWnd)
  785. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  786. Return _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_ROOT, 0, 0, "wparam", "lparam", "handle")
  787. EndFunc ;==>_GUICtrlTreeView_GetFirstItem
  788. ; #FUNCTION# ====================================================================================================================
  789. ; Author ........: Paul Campbell (PaulIA)
  790. ; Modified.......: Gary Frost (gafrost)
  791. ; ===============================================================================================================================
  792. Func _GUICtrlTreeView_GetFirstVisible($hWnd)
  793. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  794. Return _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_FIRSTVISIBLE, 0, 0, "wparam", "lparam", "handle")
  795. EndFunc ;==>_GUICtrlTreeView_GetFirstVisible
  796. ; #FUNCTION# ====================================================================================================================
  797. ; Author ........: Paul Campbell (PaulIA)
  798. ; Modified.......:
  799. ; ===============================================================================================================================
  800. Func _GUICtrlTreeView_GetFocused($hWnd, $hItem)
  801. Return BitAND(_GUICtrlTreeView_GetState($hWnd, $hItem), $TVIS_FOCUSED) <> 0
  802. EndFunc ;==>_GUICtrlTreeView_GetFocused
  803. ; #FUNCTION# ====================================================================================================================
  804. ; Author ........: Paul Campbell (PaulIA)
  805. ; Modified.......: Gary Frost (gafrost)
  806. ; ===============================================================================================================================
  807. Func _GUICtrlTreeView_GetHeight($hWnd)
  808. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  809. Return _SendMessage($hWnd, $TVM_GETITEMHEIGHT)
  810. EndFunc ;==>_GUICtrlTreeView_GetHeight
  811. ; #FUNCTION# ====================================================================================================================
  812. ; Author ........: Paul Campbell (PaulIA)
  813. ; Modified.......:
  814. ; ===============================================================================================================================
  815. Func _GUICtrlTreeView_GetImageIndex($hWnd, $hItem)
  816. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  817. Local $tItem = DllStructCreate($tagTVITEMEX)
  818. DllStructSetData($tItem, "Mask", $TVIF_IMAGE)
  819. DllStructSetData($tItem, "hItem", $hItem)
  820. __GUICtrlTreeView_GetItem($hWnd, $tItem)
  821. Return DllStructGetData($tItem, "Image")
  822. EndFunc ;==>_GUICtrlTreeView_GetImageIndex
  823. ; #FUNCTION# ====================================================================================================================
  824. ; Author ........: Gary Frost (gafrost)
  825. ; Modified.......:
  826. ; ===============================================================================================================================
  827. Func _GUICtrlTreeView_GetImageListIconHandle($hWnd, $iIndex)
  828. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  829. Local $hImageList = _SendMessage($hWnd, $TVM_GETIMAGELIST, 0, 0, 0, "wparam", "lparam", "handle")
  830. Local $hIcon = DllCall("comctl32.dll", "handle", "ImageList_GetIcon", "handle", $hImageList, "int", $iIndex, "uint", 0)
  831. If @error Then Return SetError(@error, @extended, 0)
  832. Return $hIcon[0]
  833. EndFunc ;==>_GUICtrlTreeView_GetImageListIconHandle
  834. ; #FUNCTION# ====================================================================================================================
  835. ; Author ........: Gary Frost (gafrost)
  836. ; Modified.......:
  837. ; ===============================================================================================================================
  838. Func _GUICtrlTreeView_GetIndent($hWnd)
  839. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  840. Return _SendMessage($hWnd, $TVM_GETINDENT)
  841. EndFunc ;==>_GUICtrlTreeView_GetIndent
  842. ; #FUNCTION# ====================================================================================================================
  843. ; Author ........: Paul Campbell (PaulIA)
  844. ; Modified.......: Gary Frost (gafrost)
  845. ; ===============================================================================================================================
  846. Func _GUICtrlTreeView_GetInsertMarkColor($hWnd)
  847. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  848. Return _SendMessage($hWnd, $TVM_GETINSERTMARKCOLOR)
  849. EndFunc ;==>_GUICtrlTreeView_GetInsertMarkColor
  850. ; #FUNCTION# ====================================================================================================================
  851. ; Author ........: Paul Campbell (PaulIA)
  852. ; Modified.......: Gary Frost (gafrost)
  853. ; ===============================================================================================================================
  854. Func _GUICtrlTreeView_GetISearchString($hWnd)
  855. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  856. Local $bUnicode = _GUICtrlTreeView_GetUnicodeFormat($hWnd)
  857. Local $iBuffer
  858. If $bUnicode Then
  859. $iBuffer = _SendMessage($hWnd, $TVM_GETISEARCHSTRINGW) + 1
  860. Else
  861. $iBuffer = _SendMessage($hWnd, $TVM_GETISEARCHSTRINGA) + 1
  862. EndIf
  863. If $iBuffer = 1 Then Return ""
  864. Local $tBuffer
  865. If $bUnicode Then
  866. $tBuffer = DllStructCreate("wchar Text[" & $iBuffer & "]")
  867. $iBuffer *= 2
  868. Else
  869. $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]")
  870. EndIf
  871. If _WinAPI_InProcess($hWnd, $__g_hTVLastWnd) Then
  872. _SendMessage($hWnd, $TVM_GETISEARCHSTRINGW, 0, $tBuffer, 0, "wparam", "struct*")
  873. Else
  874. Local $tMemMap
  875. Local $pMemory = _MemInit($hWnd, $iBuffer, $tMemMap)
  876. If $bUnicode Then
  877. _SendMessage($hWnd, $TVM_GETISEARCHSTRINGW, 0, $pMemory, 0, "wparam", "ptr")
  878. Else
  879. _SendMessage($hWnd, $TVM_GETISEARCHSTRINGA, 0, $pMemory, 0, "wparam", "ptr")
  880. EndIf
  881. _MemRead($tMemMap, $pMemory, $tBuffer, $iBuffer)
  882. _MemFree($tMemMap)
  883. EndIf
  884. Return DllStructGetData($tBuffer, "Text")
  885. EndFunc ;==>_GUICtrlTreeView_GetISearchString
  886. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  887. ; Name...........: __GUICtrlTreeView_GetItem
  888. ; Description ...: Retrieves some or all of a item's attributes
  889. ; Syntax.........: __GUICtrlTreeView_GetItem ( $hWnd, ByRef $tItem )
  890. ; Parameters ....: $hWnd - Handle to the control
  891. ; $tItem - $tagTVITEMEX structure used to request/receive item information
  892. ; +the item
  893. ; Return values .: Success - True
  894. ; Failure - False
  895. ; Author ........: Paul Campbell (PaulIA)
  896. ; Modified.......: Gary Frost (gafrost)
  897. ; Remarks .......: This function is used internally and should not normally be called by the end user
  898. ; Related .......: __GUICtrlTreeView_SetItem
  899. ; Link ..........:
  900. ; Example .......:
  901. ; ===============================================================================================================================
  902. Func __GUICtrlTreeView_GetItem($hWnd, ByRef $tItem)
  903. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  904. Local $bUnicode = _GUICtrlTreeView_GetUnicodeFormat($hWnd)
  905. Local $iRet
  906. If IsHWnd($hWnd) Then
  907. If _WinAPI_InProcess($hWnd, $__g_hTVLastWnd) Then
  908. $iRet = _SendMessage($hWnd, $TVM_GETITEMW, 0, $tItem, 0, "wparam", "struct*")
  909. Else
  910. Local $iItem = DllStructGetSize($tItem)
  911. Local $tMemMap
  912. Local $pMemory = _MemInit($hWnd, $iItem, $tMemMap)
  913. _MemWrite($tMemMap, $tItem)
  914. If $bUnicode Then
  915. $iRet = _SendMessage($hWnd, $TVM_GETITEMW, 0, $pMemory, 0, "wparam", "ptr")
  916. Else
  917. $iRet = _SendMessage($hWnd, $TVM_GETITEMA, 0, $pMemory, 0, "wparam", "ptr")
  918. EndIf
  919. _MemRead($tMemMap, $pMemory, $tItem, $iItem)
  920. _MemFree($tMemMap)
  921. EndIf
  922. Else
  923. Local $pItem = DllStructGetPtr($tItem)
  924. If $bUnicode Then
  925. $iRet = GUICtrlSendMsg($hWnd, $TVM_GETITEMW, 0, $pItem)
  926. Else
  927. $iRet = GUICtrlSendMsg($hWnd, $TVM_GETITEMA, 0, $pItem)
  928. EndIf
  929. EndIf
  930. Return $iRet <> 0
  931. EndFunc ;==>__GUICtrlTreeView_GetItem
  932. ; #FUNCTION# ====================================================================================================================
  933. ; Author ........: Paul Campbell (PaulIA)
  934. ; Modified.......:
  935. ; ===============================================================================================================================
  936. Func _GUICtrlTreeView_GetItemByIndex($hWnd, $hItem, $iIndex)
  937. Local $hResult = _GUICtrlTreeView_GetFirstChild($hWnd, $hItem)
  938. While ($hResult <> 0x00000000) And ($iIndex > 0)
  939. $hResult = _GUICtrlTreeView_GetNextSibling($hWnd, $hResult)
  940. $iIndex -= 1
  941. WEnd
  942. Return $hResult
  943. EndFunc ;==>_GUICtrlTreeView_GetItemByIndex
  944. ; #FUNCTION# ====================================================================================================================
  945. ; Author ........: Holger Kotsch
  946. ; Modified.......: Gary Frost (gafrost)
  947. ; ===============================================================================================================================
  948. Func _GUICtrlTreeView_GetItemHandle($hWnd, $hItem = 0)
  949. If $hItem = 0 Then $hItem = 0x00000000
  950. If IsHWnd($hWnd) Then
  951. If $hItem = 0x00000000 Then $hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_ROOT, 0, 0, "wparam", "lparam", "handle")
  952. Else
  953. If $hItem = 0x00000000 Then
  954. $hItem = Ptr(GUICtrlSendMsg($hWnd, $TVM_GETNEXTITEM, $TVGN_ROOT, 0))
  955. Else
  956. Local $hTempItem = GUICtrlGetHandle($hItem)
  957. If $hTempItem <> 0x00000000 Then $hItem = $hTempItem
  958. EndIf
  959. EndIf
  960. Return $hItem
  961. EndFunc ;==>_GUICtrlTreeView_GetItemHandle
  962. ; #FUNCTION# ====================================================================================================================
  963. ; Author ........: Gary Frost (gafrost)
  964. ; Modified.......:
  965. ; ===============================================================================================================================
  966. Func _GUICtrlTreeView_GetItemParam($hWnd, $hItem = 0)
  967. Local $tItem = DllStructCreate($tagTVITEMEX)
  968. DllStructSetData($tItem, "Mask", $TVIF_PARAM)
  969. DllStructSetData($tItem, "Param", 0)
  970. Local $bUnicode = _GUICtrlTreeView_GetUnicodeFormat($hWnd)
  971. If IsHWnd($hWnd) Then
  972. ; get the handle to item selected
  973. If $hItem = 0x00000000 Then $hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0, 0, "wparam", "lparam", "handle")
  974. If $hItem = 0x00000000 Then Return 0
  975. DllStructSetData($tItem, "hItem", $hItem)
  976. ; get the item properties
  977. If $bUnicode Then
  978. If _SendMessage($hWnd, $TVM_GETITEMW, 0, $tItem, 0, "wparam", "struct*") = 0 Then Return 0
  979. Else
  980. If _SendMessage($hWnd, $TVM_GETITEMA, 0, $tItem, 0, "wparam", "struct*") = 0 Then Return 0
  981. EndIf
  982. Else
  983. ; get the handle to item selected
  984. If $hItem = 0x00000000 Then
  985. $hItem = Ptr(GUICtrlSendMsg($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0))
  986. If $hItem = 0x00000000 Then Return 0
  987. Else
  988. Local $hTempItem = GUICtrlGetHandle($hItem)
  989. If $hTempItem <> 0x00000000 Then
  990. $hItem = $hTempItem
  991. Else
  992. Return 0
  993. EndIf
  994. EndIf
  995. DllStructSetData($tItem, "hItem", $hItem)
  996. ; get the item properties
  997. If $bUnicode Then
  998. If GUICtrlSendMsg($hWnd, $TVM_GETITEMW, 0, DllStructGetPtr($tItem)) = 0 Then Return 0
  999. Else
  1000. If GUICtrlSendMsg($hWnd, $TVM_GETITEMA, 0, DllStructGetPtr($tItem)) = 0 Then Return 0
  1001. EndIf
  1002. EndIf
  1003. Return DllStructGetData($tItem, "Param")
  1004. EndFunc ;==>_GUICtrlTreeView_GetItemParam
  1005. ; #FUNCTION# ====================================================================================================================
  1006. ; Author ........: Paul Campbell (PaulIA)
  1007. ; Modified.......:
  1008. ; ===============================================================================================================================
  1009. Func _GUICtrlTreeView_GetLastChild($hWnd, $hItem)
  1010. Local $hResult = _GUICtrlTreeView_GetFirstChild($hWnd, $hItem)
  1011. If $hResult <> 0x00000000 Then
  1012. Local $hNext = $hResult
  1013. Do
  1014. $hResult = $hNext
  1015. $hNext = _GUICtrlTreeView_GetNextSibling($hWnd, $hNext)
  1016. Until $hNext = 0x00000000
  1017. EndIf
  1018. Return $hResult
  1019. EndFunc ;==>_GUICtrlTreeView_GetLastChild
  1020. ; #FUNCTION# ====================================================================================================================
  1021. ; Author ........: Gary Frost (gafrost)
  1022. ; Modified.......:
  1023. ; ===============================================================================================================================
  1024. Func _GUICtrlTreeView_GetLineColor($hWnd)
  1025. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1026. Local $sHex = Hex(String(_SendMessage($hWnd, $TVM_GETLINECOLOR)), 6)
  1027. Return '0x' & StringMid($sHex, 5, 2) & StringMid($sHex, 3, 2) & StringMid($sHex, 1, 2)
  1028. EndFunc ;==>_GUICtrlTreeView_GetLineColor
  1029. ; #FUNCTION# ====================================================================================================================
  1030. ; Author ........: Paul Campbell (PaulIA)
  1031. ; Modified.......: Gary Frost
  1032. ; ===============================================================================================================================
  1033. Func _GUICtrlTreeView_GetNext($hWnd, $hItem)
  1034. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1035. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1036. Local $hResult = 0
  1037. If $hItem <> 0x00000000 And $hItem <> 0 Then
  1038. Local $hNext = _GUICtrlTreeView_GetFirstChild($hWnd, $hItem)
  1039. If $hNext = 0x00000000 Then
  1040. $hNext = _GUICtrlTreeView_GetNextSibling($hWnd, $hItem)
  1041. EndIf
  1042. Local $hParent = $hItem
  1043. While ($hNext = 0x00000000) And ($hParent <> 0x00000000)
  1044. $hParent = _GUICtrlTreeView_GetParentHandle($hWnd, $hParent)
  1045. If $hParent = 0x00000000 Then
  1046. $hNext = 0x00000000
  1047. ExitLoop
  1048. EndIf
  1049. $hNext = _GUICtrlTreeView_GetNextSibling($hWnd, $hParent)
  1050. WEnd
  1051. If $hNext = 0x00000000 Then $hNext = 0
  1052. $hResult = $hNext
  1053. EndIf
  1054. Return $hResult
  1055. EndFunc ;==>_GUICtrlTreeView_GetNext
  1056. ; #FUNCTION# ====================================================================================================================
  1057. ; Author ........: Gary Frost (gafrost)
  1058. ; Modified.......:
  1059. ; ===============================================================================================================================
  1060. Func _GUICtrlTreeView_GetNextChild($hWnd, $hItem)
  1061. Return _GUICtrlTreeView_GetNextSibling($hWnd, $hItem)
  1062. EndFunc ;==>_GUICtrlTreeView_GetNextChild
  1063. ; #FUNCTION# ====================================================================================================================
  1064. ; Author ........: Paul Campbell (PaulIA)
  1065. ; Modified.......: Gary Frost (gafrost)
  1066. ; ===============================================================================================================================
  1067. Func _GUICtrlTreeView_GetNextSibling($hWnd, $hItem)
  1068. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1069. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1070. Return _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_NEXT, $hItem, 0, "wparam", "handle", "handle")
  1071. EndFunc ;==>_GUICtrlTreeView_GetNextSibling
  1072. ; #FUNCTION# ====================================================================================================================
  1073. ; Author ........: Paul Campbell (PaulIA)
  1074. ; Modified.......: Gary Frost (gafrost)
  1075. ; ===============================================================================================================================
  1076. Func _GUICtrlTreeView_GetNextVisible($hWnd, $hItem)
  1077. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1078. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1079. Return _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_NEXTVISIBLE, $hItem, 0, "wparam", "handle", "handle")
  1080. EndFunc ;==>_GUICtrlTreeView_GetNextVisible
  1081. ; #FUNCTION# ====================================================================================================================
  1082. ; Author ........: Paul Campbell (PaulIA)
  1083. ; Modified.......: Gary Frost (gafrost)
  1084. ; ===============================================================================================================================
  1085. Func _GUICtrlTreeView_GetNormalImageList($hWnd)
  1086. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1087. Return _SendMessage($hWnd, $TVM_GETIMAGELIST, $TVSIL_NORMAL, 0, 0, "wparam", "lparam", "handle")
  1088. EndFunc ;==>_GUICtrlTreeView_GetNormalImageList
  1089. ; #NO_DOC_FUNCTION# =============================================================================================================
  1090. ; Name...........: _GUICtrlTreeView_GetOverlayImageIndex
  1091. ; Description ...: Returns the index of the image from the image list that is used as an overlay mask
  1092. ; Syntax.........: _GUICtrlTreeView_GetOverlayImageIndex ( $hWnd, $hItem )
  1093. ; Parameters ....: $hWnd - Handle to the control
  1094. ; $hItem - Handle to the item
  1095. ; Return values .: Success - Overlay list index
  1096. ; Failure - 0
  1097. ; Author ........: Paul Campbell (PaulIA)
  1098. ; Modified.......:
  1099. ; Remarks .......:
  1100. ; Related .......: _GUICtrlTreeView_SetOverlayImageIndex
  1101. ; Link ..........:
  1102. ; Example .......:
  1103. ; ===============================================================================================================================
  1104. Func _GUICtrlTreeView_GetOverlayImageIndex($hWnd, $hItem)
  1105. Local $tItem = DllStructCreate($tagTVITEMEX)
  1106. DllStructSetData($tItem, "Mask", $TVIF_STATE)
  1107. DllStructSetData($tItem, "hItem", $hItem)
  1108. DllStructSetData($tItem, "StateMask", $TVIS_OVERLAYMASK)
  1109. __GUICtrlTreeView_GetItem($hWnd, $tItem)
  1110. Return DllStructGetData($tItem, "Image")
  1111. EndFunc ;==>_GUICtrlTreeView_GetOverlayImageIndex
  1112. ; #FUNCTION# ====================================================================================================================
  1113. ; Author ........: Gary Frost (gafrost), Holger Kotsch
  1114. ; Modified.......: Gary Frost (gafrost)
  1115. ; ===============================================================================================================================
  1116. Func _GUICtrlTreeView_GetParentHandle($hWnd, $hItem = 0)
  1117. ;If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1118. If $hItem = 0 Then $hItem = 0x00000000
  1119. ; get the handle to item selected
  1120. If $hItem = 0x00000000 Then
  1121. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1122. $hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0, 0, "wparam", "handle", "handle")
  1123. If $hItem = 0x00000000 Then Return 0
  1124. Else
  1125. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1126. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1127. EndIf
  1128. ; get the handle of the parent item
  1129. Local $hParent = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_PARENT, $hItem, 0, "wparam", "handle", "handle")
  1130. Return $hParent
  1131. EndFunc ;==>_GUICtrlTreeView_GetParentHandle
  1132. ; #FUNCTION# ====================================================================================================================
  1133. ; Author ........: Gary Frost (gafrost)
  1134. ; Modified.......:
  1135. ; ===============================================================================================================================
  1136. Func _GUICtrlTreeView_GetParentParam($hWnd, $hItem = 0)
  1137. If $hItem = 0 Then $hItem = 0x00000000
  1138. Local $tTVITEM = DllStructCreate($tagTVITEMEX)
  1139. DllStructSetData($tTVITEM, "Mask", $TVIF_PARAM)
  1140. DllStructSetData($tTVITEM, "Param", 0)
  1141. Local $hParent
  1142. If IsHWnd($hWnd) Then
  1143. ; get the handle to item selected
  1144. If $hItem = 0x00000000 Then $hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0, 0, "wparam", "handle", "handle")
  1145. If $hItem = 0x00000000 Then Return 0
  1146. ; get the handle of the parent item
  1147. $hParent = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_PARENT, $hItem, 0, "wparam", "handle", "handle")
  1148. DllStructSetData($tTVITEM, "hItem", $hParent)
  1149. ; get the item properties
  1150. If _SendMessage($hWnd, $TVM_GETITEMA, 0, $tTVITEM, 0, "wparam", "struct*") = 0 Then Return False
  1151. Else
  1152. ; get the handle to item selected
  1153. If $hItem = 0x00000000 Then
  1154. $hItem = GUICtrlSendMsg($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0)
  1155. If $hItem = 0x00000000 Then Return 0
  1156. Else
  1157. Local $hTempItem = GUICtrlGetHandle($hItem)
  1158. If $hTempItem <> 0x00000000 Then
  1159. $hItem = $hTempItem
  1160. Else
  1161. Return 0
  1162. EndIf
  1163. EndIf
  1164. ; get the handle of the parent item
  1165. $hParent = GUICtrlSendMsg($hWnd, $TVM_GETNEXTITEM, $TVGN_PARENT, $hItem)
  1166. DllStructSetData($tTVITEM, "hItem", $hParent)
  1167. ; get the item properties
  1168. If GUICtrlSendMsg($hWnd, $TVM_GETITEMA, 0, DllStructGetPtr($tTVITEM)) = 0 Then Return 0
  1169. EndIf
  1170. Return DllStructGetData($tTVITEM, "Param")
  1171. EndFunc ;==>_GUICtrlTreeView_GetParentParam
  1172. ; #FUNCTION# ====================================================================================================================
  1173. ; Author ........: Paul Campbell (PaulIA)
  1174. ; Modified.......:
  1175. ; ===============================================================================================================================
  1176. Func _GUICtrlTreeView_GetPrev($hWnd, $hItem)
  1177. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1178. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1179. Local $hResult = _GUICtrlTreeView_GetPrevChild($hWnd, $hItem)
  1180. If $hResult <> 0x00000000 Then
  1181. Local $hPrev = $hResult
  1182. Do
  1183. $hResult = $hPrev
  1184. $hPrev = _GUICtrlTreeView_GetLastChild($hWnd, $hPrev)
  1185. Until $hPrev = 0x00000000
  1186. Else
  1187. $hResult = _GUICtrlTreeView_GetParentHandle($hWnd, $hItem)
  1188. EndIf
  1189. Return $hResult
  1190. EndFunc ;==>_GUICtrlTreeView_GetPrev
  1191. ; #FUNCTION# ====================================================================================================================
  1192. ; Author ........: Paul Campbell (PaulIA)
  1193. ; Modified.......:
  1194. ; ===============================================================================================================================
  1195. Func _GUICtrlTreeView_GetPrevChild($hWnd, $hItem)
  1196. Return _GUICtrlTreeView_GetPrevSibling($hWnd, $hItem)
  1197. EndFunc ;==>_GUICtrlTreeView_GetPrevChild
  1198. ; #FUNCTION# ====================================================================================================================
  1199. ; Author ........: Paul Campbell (PaulIA)
  1200. ; Modified.......: Gary Frost (gafrost)
  1201. ; ===============================================================================================================================
  1202. Func _GUICtrlTreeView_GetPrevSibling($hWnd, $hItem)
  1203. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1204. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1205. Return _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_PREVIOUS, $hItem, 0, "wparam", "handle", "handle")
  1206. EndFunc ;==>_GUICtrlTreeView_GetPrevSibling
  1207. ; #FUNCTION# ====================================================================================================================
  1208. ; Author ........: Paul Campbell (PaulIA)
  1209. ; Modified.......: Gary Frost (gafrost)
  1210. ; ===============================================================================================================================
  1211. Func _GUICtrlTreeView_GetPrevVisible($hWnd, $hItem)
  1212. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1213. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1214. Return _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_PREVIOUSVISIBLE, $hItem, 0, "wparam", "handle", "handle")
  1215. EndFunc ;==>_GUICtrlTreeView_GetPrevVisible
  1216. ; #FUNCTION# ====================================================================================================================
  1217. ; Author ........: Paul Campbell (PaulIA)
  1218. ; Modified.......: Gary Frost (gafrost)
  1219. ; ===============================================================================================================================
  1220. Func _GUICtrlTreeView_GetScrollTime($hWnd)
  1221. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1222. Return _SendMessage($hWnd, $TVM_GETSCROLLTIME)
  1223. EndFunc ;==>_GUICtrlTreeView_GetScrollTime
  1224. ; #FUNCTION# ====================================================================================================================
  1225. ; Author ........: Paul Campbell (PaulIA)
  1226. ; Modified.......:
  1227. ; ===============================================================================================================================
  1228. Func _GUICtrlTreeView_GetSelected($hWnd, $hItem)
  1229. Return BitAND(_GUICtrlTreeView_GetState($hWnd, $hItem), $TVIS_SELECTED) <> 0
  1230. EndFunc ;==>_GUICtrlTreeView_GetSelected
  1231. ; #FUNCTION# ====================================================================================================================
  1232. ; Author ........: Paul Campbell (PaulIA)
  1233. ; Modified.......: Gary Frost (gafrost)
  1234. ; ===============================================================================================================================
  1235. Func _GUICtrlTreeView_GetSelectedImageIndex($hWnd, $hItem)
  1236. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1237. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1238. Local $tItem = DllStructCreate($tagTVITEMEX)
  1239. DllStructSetData($tItem, "Mask", $TVIF_SELECTEDIMAGE)
  1240. DllStructSetData($tItem, "hItem", $hItem)
  1241. __GUICtrlTreeView_GetItem($hWnd, $tItem)
  1242. Return DllStructGetData($tItem, "SelectedImage")
  1243. EndFunc ;==>_GUICtrlTreeView_GetSelectedImageIndex
  1244. ; #FUNCTION# ====================================================================================================================
  1245. ; Author ........: Paul Campbell (PaulIA)
  1246. ; Modified.......: Gary Frost (gafrost)
  1247. ; ===============================================================================================================================
  1248. Func _GUICtrlTreeView_GetSelection($hWnd)
  1249. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1250. Return _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0, 0, "wparam", "handle", "handle")
  1251. EndFunc ;==>_GUICtrlTreeView_GetSelection
  1252. ; #FUNCTION# ====================================================================================================================
  1253. ; Author ........: Gary Frost (gafrost)
  1254. ; Modified.......:
  1255. ; ===============================================================================================================================
  1256. Func _GUICtrlTreeView_GetSiblingCount($hWnd, $hItem)
  1257. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1258. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1259. Local $hNext, $iRet = 0
  1260. Local $hParent = _GUICtrlTreeView_GetParentHandle($hWnd, $hItem)
  1261. If $hParent <> 0x00000000 Then
  1262. $hNext = _GUICtrlTreeView_GetFirstChild($hWnd, $hParent)
  1263. If $hNext = 0x00000000 Then Return -1
  1264. Do
  1265. $iRet += 1
  1266. $hNext = _GUICtrlTreeView_GetNextSibling($hWnd, $hNext)
  1267. Until $hNext = 0x00000000
  1268. Else
  1269. $hNext = _GUICtrlTreeView_GetFirstItem($hWnd)
  1270. If $hNext = 0x00000000 Then Return -1
  1271. Do
  1272. $iRet += 1
  1273. $hNext = _GUICtrlTreeView_GetNextSibling($hWnd, $hNext)
  1274. Until $hNext = 0x00000000
  1275. EndIf
  1276. Return $iRet
  1277. EndFunc ;==>_GUICtrlTreeView_GetSiblingCount
  1278. ; #FUNCTION# ====================================================================================================================
  1279. ; Author ........: Holger Kotsch
  1280. ; Modified.......: Gary Frost (gafrost)
  1281. ; ===============================================================================================================================
  1282. Func _GUICtrlTreeView_GetState($hWnd, $hItem = 0)
  1283. If $hItem = 0 Then $hItem = 0x00000000
  1284. $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1285. If $hItem = 0x00000000 Then Return SetError(1, 1, 0)
  1286. Local $tTVITEM = DllStructCreate($tagTVITEMEX)
  1287. DllStructSetData($tTVITEM, "Mask", $TVIF_STATE)
  1288. DllStructSetData($tTVITEM, "hItem", $hItem)
  1289. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1290. If _WinAPI_InProcess($hWnd, $__g_hTVLastWnd) Then
  1291. _SendMessage($hWnd, $TVM_GETITEMA, 0, $tTVITEM, 0, "wparam", "struct*")
  1292. Else
  1293. Local $iSize = DllStructGetSize($tTVITEM)
  1294. Local $tMemMap
  1295. Local $pMemory = _MemInit($hWnd, $iSize, $tMemMap)
  1296. _MemWrite($tMemMap, $tTVITEM)
  1297. _SendMessage($hWnd, $TVM_GETITEMA, 0, $pMemory)
  1298. _MemRead($tMemMap, $pMemory, $tTVITEM, $iSize)
  1299. _MemFree($tMemMap)
  1300. EndIf
  1301. Return DllStructGetData($tTVITEM, "State")
  1302. EndFunc ;==>_GUICtrlTreeView_GetState
  1303. ; #FUNCTION# ====================================================================================================================
  1304. ; Author ........: Paul Campbell (PaulIA)
  1305. ; Modified.......: Gary Frost (gafrost)
  1306. ; ===============================================================================================================================
  1307. Func _GUICtrlTreeView_GetStateImageIndex($hWnd, $hItem)
  1308. $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1309. Local $tItem = DllStructCreate($tagTVITEMEX)
  1310. DllStructSetData($tItem, "Mask", $TVIF_STATE)
  1311. DllStructSetData($tItem, "hItem", $hItem)
  1312. __GUICtrlTreeView_GetItem($hWnd, $tItem)
  1313. Return BitShift(BitAND(DllStructGetData($tItem, "State"), $TVIS_STATEIMAGEMASK), 12)
  1314. EndFunc ;==>_GUICtrlTreeView_GetStateImageIndex
  1315. ; #FUNCTION# ====================================================================================================================
  1316. ; Author ........: Paul Campbell (PaulIA)
  1317. ; Modified.......: Gary Frost (gafrost)
  1318. ; ===============================================================================================================================
  1319. Func _GUICtrlTreeView_GetStateImageList($hWnd)
  1320. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1321. Return _SendMessage($hWnd, $TVM_GETIMAGELIST, $TVSIL_STATE, 0, 0, "wparam", "handle", "handle")
  1322. EndFunc ;==>_GUICtrlTreeView_GetStateImageList
  1323. ; #FUNCTION# ====================================================================================================================
  1324. ; Author ........: Paul Campbell (PaulIA)
  1325. ; Modified.......: Gary Frost (gafrost)
  1326. ; ===============================================================================================================================
  1327. Func _GUICtrlTreeView_GetText($hWnd, $hItem = 0)
  1328. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1329. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1330. If $hItem = 0x00000000 Then Return SetError(1, 1, "")
  1331. Local $tTVITEM = DllStructCreate($tagTVITEMEX)
  1332. Local $tText
  1333. Local $bUnicode = _GUICtrlTreeView_GetUnicodeFormat($hWnd)
  1334. If $bUnicode Then
  1335. $tText = DllStructCreate("wchar Buffer[4096]") ; create a text 'area' for receiving the text
  1336. Else
  1337. $tText = DllStructCreate("char Buffer[4096]") ; create a text 'area' for receiving the text
  1338. EndIf
  1339. DllStructSetData($tTVITEM, "Mask", $TVIF_TEXT)
  1340. DllStructSetData($tTVITEM, "hItem", $hItem)
  1341. DllStructSetData($tTVITEM, "TextMax", 4096)
  1342. If _WinAPI_InProcess($hWnd, $__g_hTVLastWnd) Then
  1343. DllStructSetData($tTVITEM, "Text", DllStructGetPtr($tText))
  1344. _SendMessage($hWnd, $TVM_GETITEMW, 0, $tTVITEM, 0, "wparam", "struct*")
  1345. Else
  1346. Local $iItem = DllStructGetSize($tTVITEM)
  1347. Local $tMemMap
  1348. Local $pMemory = _MemInit($hWnd, $iItem + 4096, $tMemMap)
  1349. Local $pText = $pMemory + $iItem
  1350. DllStructSetData($tTVITEM, "Text", $pText)
  1351. _MemWrite($tMemMap, $tTVITEM, $pMemory, $iItem)
  1352. If $bUnicode Then
  1353. _SendMessage($hWnd, $TVM_GETITEMW, 0, $pMemory, 0, "wparam", "ptr")
  1354. Else
  1355. _SendMessage($hWnd, $TVM_GETITEMA, 0, $pMemory, 0, "wparam", "ptr")
  1356. EndIf
  1357. _MemRead($tMemMap, $pText, $tText, 4096)
  1358. _MemFree($tMemMap)
  1359. EndIf
  1360. Return DllStructGetData($tText, "Buffer")
  1361. EndFunc ;==>_GUICtrlTreeView_GetText
  1362. ; #FUNCTION# ====================================================================================================================
  1363. ; Author ........: Gary Frost (gafrost)
  1364. ; Modified.......:
  1365. ; ===============================================================================================================================
  1366. Func _GUICtrlTreeView_GetTextColor($hWnd)
  1367. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1368. Local $sHex = Hex(String(_SendMessage($hWnd, $TVM_GETTEXTCOLOR)), 6)
  1369. Return '0x' & StringMid($sHex, 5, 2) & StringMid($sHex, 3, 2) & StringMid($sHex, 1, 2)
  1370. EndFunc ;==>_GUICtrlTreeView_GetTextColor
  1371. ; #FUNCTION# ====================================================================================================================
  1372. ; Author ........: Paul Campbell (PaulIA)
  1373. ; Modified.......: Gary Frost (gafrost)
  1374. ; ===============================================================================================================================
  1375. Func _GUICtrlTreeView_GetToolTips($hWnd)
  1376. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1377. Return _SendMessage($hWnd, $TVM_GETTOOLTIPS, 0, 0, 0, "wparam", "lparam", "hwnd")
  1378. EndFunc ;==>_GUICtrlTreeView_GetToolTips
  1379. ; #FUNCTION# ====================================================================================================================
  1380. ; Author ........: Gary Frost (gafrost), Holger Kotsch
  1381. ; Modified.......: Gary Frost (gafrost)
  1382. ; ===============================================================================================================================
  1383. Func _GUICtrlTreeView_GetTree($hWnd, $hItem = 0)
  1384. If $hItem = 0 Then
  1385. $hItem = 0x00000000
  1386. Else
  1387. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1388. EndIf
  1389. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1390. Local $sPath = ""
  1391. If $hItem = 0x00000000 Then $hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0, 0, "wparam", "handle", "handle")
  1392. If $hItem <> 0x00000000 Then
  1393. $sPath = _GUICtrlTreeView_GetText($hWnd, $hItem)
  1394. Local $hParent, $sSeparator = Opt("GUIDataSeparatorChar")
  1395. Do ; Get now the parent item handle if there is one
  1396. $hParent = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_PARENT, $hItem, 0, "wparam", "handle", "handle")
  1397. If $hParent <> 0x00000000 Then $sPath = _GUICtrlTreeView_GetText($hWnd, $hParent) & $sSeparator & $sPath
  1398. $hItem = $hParent
  1399. Until $hItem = 0x00000000
  1400. EndIf
  1401. Return $sPath
  1402. EndFunc ;==>_GUICtrlTreeView_GetTree
  1403. ; #FUNCTION# ====================================================================================================================
  1404. ; Author ........: Paul Campbell (PaulIA)
  1405. ; Modified.......: Gary Frost (gafrost)
  1406. ; ===============================================================================================================================
  1407. Func _GUICtrlTreeView_GetUnicodeFormat($hWnd)
  1408. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1409. Return _SendMessage($hWnd, $TVM_GETUNICODEFORMAT) <> 0
  1410. EndFunc ;==>_GUICtrlTreeView_GetUnicodeFormat
  1411. ; #FUNCTION# ====================================================================================================================
  1412. ; Author ........: Paul Campbell (PaulIA)
  1413. ; Modified.......: Gary Frost (gafrost)
  1414. ; ===============================================================================================================================
  1415. Func _GUICtrlTreeView_GetVisible($hWnd, $hItem)
  1416. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1417. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1418. Local $tRECT = DllStructCreate($tagRECT)
  1419. DllStructSetData($tRECT, "Left", $hItem)
  1420. Local $iRet
  1421. If _WinAPI_InProcess($hWnd, $__g_hTVLastWnd) Then
  1422. $iRet = _SendMessage($hWnd, $TVM_GETITEMRECT, True, $tRECT, 0, "wparam", "struct*")
  1423. Else
  1424. Local $iRect = DllStructGetSize($tRECT)
  1425. Local $tMemMap
  1426. Local $pMemory = _MemInit($hWnd, $iRect, $tMemMap)
  1427. _MemWrite($tMemMap, $tRECT)
  1428. $iRet = _SendMessage($hWnd, $TVM_GETITEMRECT, True, $pMemory, 0, "wparam", "ptr")
  1429. _MemRead($tMemMap, $pMemory, $tRECT, $iRect)
  1430. _MemFree($tMemMap)
  1431. EndIf
  1432. If $iRet = 0 Then Return False ; item is child item, collapsed and not visible
  1433. ; item may not be collapsed or may be at the root level the above will give a rect even it isn't in the view
  1434. ; check to see if it is visible to the eye
  1435. Local $iControlHeight = _WinAPI_GetWindowHeight($hWnd)
  1436. If DllStructGetData($tRECT, "Top") >= $iControlHeight Or _
  1437. DllStructGetData($tRECT, "Bottom") <= 0 Then
  1438. Return False
  1439. Else
  1440. Return True
  1441. EndIf
  1442. EndFunc ;==>_GUICtrlTreeView_GetVisible
  1443. ; #FUNCTION# ====================================================================================================================
  1444. ; Author ........: Paul Campbell (PaulIA)
  1445. ; Modified.......: Gary Frost (gafrost)
  1446. ; ===============================================================================================================================
  1447. Func _GUICtrlTreeView_GetVisibleCount($hWnd)
  1448. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1449. Return _SendMessage($hWnd, $TVM_GETVISIBLECOUNT)
  1450. EndFunc ;==>_GUICtrlTreeView_GetVisibleCount
  1451. ; #FUNCTION# ====================================================================================================================
  1452. ; Author ........: Paul Campbell (PaulIA)
  1453. ; Modified.......:
  1454. ; ===============================================================================================================================
  1455. Func _GUICtrlTreeView_HitTest($hWnd, $iX, $iY)
  1456. Local $tHitTest = _GUICtrlTreeView_HitTestEx($hWnd, $iX, $iY)
  1457. Local $iFlags = DllStructGetData($tHitTest, "Flags")
  1458. Local $iRet = 0
  1459. If BitAND($iFlags, $TVHT_NOWHERE) <> 0 Then $iRet = BitOR($iRet, 1)
  1460. If BitAND($iFlags, $TVHT_ONITEMICON) <> 0 Then $iRet = BitOR($iRet, 2)
  1461. If BitAND($iFlags, $TVHT_ONITEMLABEL) <> 0 Then $iRet = BitOR($iRet, 4)
  1462. If BitAND($iFlags, $TVHT_ONITEMINDENT) <> 0 Then $iRet = BitOR($iRet, 8)
  1463. If BitAND($iFlags, $TVHT_ONITEMBUTTON) <> 0 Then $iRet = BitOR($iRet, 16)
  1464. If BitAND($iFlags, $TVHT_ONITEMRIGHT) <> 0 Then $iRet = BitOR($iRet, 32)
  1465. If BitAND($iFlags, $TVHT_ONITEMSTATEICON) <> 0 Then $iRet = BitOR($iRet, 64)
  1466. If BitAND($iFlags, $TVHT_ABOVE) <> 0 Then $iRet = BitOR($iRet, 128)
  1467. If BitAND($iFlags, $TVHT_BELOW) <> 0 Then $iRet = BitOR($iRet, 256)
  1468. If BitAND($iFlags, $TVHT_TORIGHT) <> 0 Then $iRet = BitOR($iRet, 512)
  1469. If BitAND($iFlags, $TVHT_TOLEFT) <> 0 Then $iRet = BitOR($iRet, 1024)
  1470. Return $iRet
  1471. EndFunc ;==>_GUICtrlTreeView_HitTest
  1472. ; #FUNCTION# ====================================================================================================================
  1473. ; Author ........: Paul Campbell (PaulIA)
  1474. ; Modified.......: Gary Frost (gafrost)
  1475. ; ===============================================================================================================================
  1476. Func _GUICtrlTreeView_HitTestEx($hWnd, $iX, $iY)
  1477. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1478. Local $tHitTest = DllStructCreate($tagTVHITTESTINFO)
  1479. DllStructSetData($tHitTest, "X", $iX)
  1480. DllStructSetData($tHitTest, "Y", $iY)
  1481. If _WinAPI_InProcess($hWnd, $__g_hTVLastWnd) Then
  1482. _SendMessage($hWnd, $TVM_HITTEST, 0, $tHitTest, 0, "wparam", "struct*")
  1483. Else
  1484. Local $iHitTest = DllStructGetSize($tHitTest)
  1485. Local $tMemMap
  1486. Local $pMemory = _MemInit($hWnd, $iHitTest, $tMemMap)
  1487. _MemWrite($tMemMap, $tHitTest)
  1488. _SendMessage($hWnd, $TVM_HITTEST, 0, $pMemory, 0, "wparam", "ptr")
  1489. _MemRead($tMemMap, $pMemory, $tHitTest, $iHitTest)
  1490. _MemFree($tMemMap)
  1491. EndIf
  1492. Return $tHitTest
  1493. EndFunc ;==>_GUICtrlTreeView_HitTestEx
  1494. ; #FUNCTION# ====================================================================================================================
  1495. ; Author ........: Paul Campbell (PaulIA)
  1496. ; Modified.......:
  1497. ; ===============================================================================================================================
  1498. Func _GUICtrlTreeView_HitTestItem($hWnd, $iX, $iY)
  1499. Local $tHitTest = _GUICtrlTreeView_HitTestEx($hWnd, $iX, $iY)
  1500. Return DllStructGetData($tHitTest, "Item")
  1501. EndFunc ;==>_GUICtrlTreeView_HitTestItem
  1502. ; #FUNCTION# ====================================================================================================================
  1503. ; Author ........: Paul Campbell (PaulIA)
  1504. ; Modified.......: Gary Frost (gafrost)
  1505. ; ===============================================================================================================================
  1506. Func _GUICtrlTreeView_Index($hWnd, $hItem)
  1507. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1508. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1509. Local $iRet = -1
  1510. Local $hParent = _GUICtrlTreeView_GetParentHandle($hWnd, $hItem)
  1511. Local $hNext
  1512. If $hParent <> 0x00000000 Then
  1513. $hNext = _GUICtrlTreeView_GetFirstChild($hWnd, $hParent)
  1514. While $hNext <> 0x00000000
  1515. $iRet += 1
  1516. If $hNext = $hItem Then ExitLoop
  1517. $hNext = _GUICtrlTreeView_GetNextSibling($hWnd, $hNext)
  1518. WEnd
  1519. Else
  1520. $hNext = _GUICtrlTreeView_GetFirstItem($hWnd)
  1521. While $hNext <> 0x00000000
  1522. $iRet += 1
  1523. If $hNext = $hItem Then ExitLoop
  1524. $hNext = _GUICtrlTreeView_GetNextSibling($hWnd, $hNext)
  1525. WEnd
  1526. EndIf
  1527. If $hNext = 0x00000000 Then $iRet = -1
  1528. Return $iRet
  1529. EndFunc ;==>_GUICtrlTreeView_Index
  1530. ; #FUNCTION# ====================================================================================================================
  1531. ; Author ........: Holger Kotsch
  1532. ; Modified.......: Gary Frost (gafrost)
  1533. ; ===============================================================================================================================
  1534. Func _GUICtrlTreeView_InsertItem($hWnd, $sItem_Text, $hItem_Parent = 0, $hItem_After = 0, $iImage = -1, $iSelImage = -1)
  1535. Local $tTVI = DllStructCreate($tagTVINSERTSTRUCT)
  1536. Local $iBuffer, $pBuffer
  1537. If $sItem_Text <> -1 Then
  1538. $iBuffer = StringLen($sItem_Text) + 1
  1539. Local $tText
  1540. Local $bUnicode = _GUICtrlTreeView_GetUnicodeFormat($hWnd)
  1541. If $bUnicode Then
  1542. $tText = DllStructCreate("wchar Buffer[" & $iBuffer & "]")
  1543. $iBuffer *= 2
  1544. Else
  1545. $tText = DllStructCreate("char Buffer[" & $iBuffer & "]")
  1546. EndIf
  1547. DllStructSetData($tText, "Buffer", $sItem_Text)
  1548. $pBuffer = DllStructGetPtr($tText)
  1549. Else
  1550. $iBuffer = 0
  1551. $pBuffer = -1 ; LPSTR_TEXTCALLBACK
  1552. EndIf
  1553. Local $hItem_tmp
  1554. If $hItem_Parent = 0 Then ; setting to root level
  1555. $hItem_Parent = $TVI_ROOT
  1556. ElseIf Not IsHWnd($hItem_Parent) Then ; control created by autoit create
  1557. $hItem_tmp = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem_Parent)
  1558. If $hItem_tmp Then $hItem_Parent = $hItem_tmp
  1559. EndIf
  1560. If $hItem_After = 0 Then ; using default
  1561. $hItem_After = $TVI_LAST
  1562. ElseIf ($hItem_After <> $TVI_ROOT And _
  1563. $hItem_After <> $TVI_FIRST And _
  1564. $hItem_After <> $TVI_LAST And _
  1565. $hItem_After <> $TVI_SORT) Then ; not using flag
  1566. If Not IsHWnd($hItem_After) Then
  1567. $hItem_tmp = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem_After)
  1568. If Not $hItem_tmp Then ; item not found or invalid flag used
  1569. $hItem_After = $TVI_LAST
  1570. Else ; setting handle
  1571. $hItem_After = $hItem_tmp
  1572. EndIf
  1573. EndIf
  1574. EndIf
  1575. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1576. Local $hIcon
  1577. Local $iMask = $TVIF_TEXT
  1578. If $iImage >= 0 Then
  1579. $iMask = BitOR($iMask, $TVIF_IMAGE)
  1580. $iMask = BitOR($iMask, $TVIF_IMAGE)
  1581. DllStructSetData($tTVI, "Image", $iImage)
  1582. Else
  1583. $hIcon = _GUICtrlTreeView_GetImageListIconHandle($hWnd, 0)
  1584. If $hIcon <> 0x00000000 Then
  1585. $iMask = BitOR($iMask, $TVIF_IMAGE)
  1586. DllStructSetData($tTVI, "Image", 0)
  1587. DllCall("user32.dll", "int", "DestroyIcon", "handle", $hIcon)
  1588. ; No @error test because results are unimportant.
  1589. EndIf
  1590. EndIf
  1591. If $iSelImage >= 0 Then
  1592. $iMask = BitOR($iMask, $TVIF_SELECTEDIMAGE)
  1593. $iMask = BitOR($iMask, $TVIF_SELECTEDIMAGE)
  1594. DllStructSetData($tTVI, "SelectedImage", $iSelImage)
  1595. Else
  1596. $hIcon = _GUICtrlTreeView_GetImageListIconHandle($hWnd, 1)
  1597. If $hIcon <> 0x00000000 Then
  1598. $iMask = BitOR($iMask, $TVIF_SELECTEDIMAGE)
  1599. DllStructSetData($tTVI, "SelectedImage", 0)
  1600. DllCall("user32.dll", "int", "DestroyIcon", "handle", $hIcon)
  1601. ; No @error test because results are unimportant.
  1602. EndIf
  1603. EndIf
  1604. DllStructSetData($tTVI, "Parent", $hItem_Parent)
  1605. DllStructSetData($tTVI, "InsertAfter", $hItem_After)
  1606. DllStructSetData($tTVI, "Mask", $iMask)
  1607. DllStructSetData($tTVI, "TextMax", $iBuffer)
  1608. $iMask = BitOR($iMask, $TVIF_PARAM)
  1609. DllStructSetData($tTVI, "Param", 0)
  1610. Local $hItem
  1611. If _WinAPI_InProcess($hWnd, $__g_hTVLastWnd) Then
  1612. DllStructSetData($tTVI, "Text", $pBuffer)
  1613. $hItem = _SendMessage($hWnd, $TVM_INSERTITEMW, 0, $tTVI, 0, "wparam", "struct*", "handle")
  1614. Else
  1615. Local $iInsert = DllStructGetSize($tTVI)
  1616. Local $tMemMap
  1617. Local $pMemory = _MemInit($hWnd, $iInsert + $iBuffer, $tMemMap)
  1618. If $sItem_Text <> -1 Then
  1619. Local $pText = $pMemory + $iInsert
  1620. DllStructSetData($tTVI, "Text", $pText)
  1621. _MemWrite($tMemMap, $tText, $pText, $iBuffer)
  1622. Else
  1623. DllStructSetData($tTVI, "Text", -1) ; LPSTR_TEXTCALLBACK
  1624. EndIf
  1625. _MemWrite($tMemMap, $tTVI, $pMemory, $iInsert)
  1626. If $bUnicode Then
  1627. $hItem = _SendMessage($hWnd, $TVM_INSERTITEMW, 0, $pMemory, 0, "wparam", "ptr", "handle")
  1628. Else
  1629. $hItem = _SendMessage($hWnd, $TVM_INSERTITEMA, 0, $pMemory, 0, "wparam", "ptr", "handle")
  1630. EndIf
  1631. _MemFree($tMemMap)
  1632. EndIf
  1633. Return $hItem
  1634. EndFunc ;==>_GUICtrlTreeView_InsertItem
  1635. ; #FUNCTION# ====================================================================================================================
  1636. ; Author ........: Paul Campbell (PaulIA)
  1637. ; Modified.......: Gary Frost (gafrost)
  1638. ; ===============================================================================================================================
  1639. Func _GUICtrlTreeView_IsFirstItem($hWnd, $hItem)
  1640. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1641. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1642. Return _GUICtrlTreeView_GetFirstItem($hWnd) = $hItem
  1643. EndFunc ;==>_GUICtrlTreeView_IsFirstItem
  1644. ; #FUNCTION# ====================================================================================================================
  1645. ; Author ........: Gary Frost (gafrost)
  1646. ; Modified.......:
  1647. ; ===============================================================================================================================
  1648. Func _GUICtrlTreeView_IsParent($hWnd, $hParent, $hItem)
  1649. If Not IsHWnd($hParent) Then $hParent = _GUICtrlTreeView_GetItemHandle($hWnd, $hParent)
  1650. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1651. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1652. Return _GUICtrlTreeView_GetParentHandle($hWnd, $hItem) = $hParent
  1653. EndFunc ;==>_GUICtrlTreeView_IsParent
  1654. ; #FUNCTION# ====================================================================================================================
  1655. ; Author ........: Paul Campbell (PaulIA)
  1656. ; Modified.......:
  1657. ; ===============================================================================================================================
  1658. Func _GUICtrlTreeView_Level($hWnd, $hItem)
  1659. Local $iRet = 0
  1660. Local $hNext = _GUICtrlTreeView_GetParentHandle($hWnd, $hItem)
  1661. While $hNext <> 0x00000000
  1662. $iRet += 1
  1663. $hNext = _GUICtrlTreeView_GetParentHandle($hWnd, $hNext)
  1664. WEnd
  1665. Return $iRet
  1666. EndFunc ;==>_GUICtrlTreeView_Level
  1667. ; #NO_DOC_FUNCTION# =============================================================================================================
  1668. ; Name...........: _GUICtrlTreeView_MapAccIDToItem
  1669. ; Description ...: Maps an accessibility ID to an HTREEITEM
  1670. ; Syntax.........: _GUICtrlTreeView_MapAccIDToItem ( $hWnd, $iID )
  1671. ; Parameters ....: $hWnd - Handle to the control
  1672. ; $iID - Accessibility ID
  1673. ; Return values .: Success - The HTREEITEM that the specified accessibility ID is mapped to
  1674. ; Author ........: Paul Campbell (PaulIA)
  1675. ; Modified.......: Gary Frost (gafrost)
  1676. ; Remarks .......: Minimum OS Windows XP.
  1677. ; +
  1678. ; When you add an item to a control an HTREEITEM returns, which uniquely identifies the item.
  1679. ; Related .......: _GUICtrlTreeView_MapItemToAccID
  1680. ; Link ..........:
  1681. ; Example .......:
  1682. ; ===============================================================================================================================
  1683. Func _GUICtrlTreeView_MapAccIDToItem($hWnd, $iID)
  1684. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1685. Return _SendMessage($hWnd, $TVM_MAPACCIDTOHTREEITEM, $iID, 0, 0, "wparam", "lparam", "handle")
  1686. EndFunc ;==>_GUICtrlTreeView_MapAccIDToItem
  1687. ; #NO_DOC_FUNCTION# =============================================================================================================
  1688. ; Name...........: _GUICtrlTreeView_MapItemToAccID
  1689. ; Description ...: Maps an HTREEITEM to an accessibility ID
  1690. ; Syntax.........: _GUICtrlTreeView_MapItemToAccID ( $hWnd, $hTreeItem )
  1691. ; Parameters ....: $hWnd - Handle to the control
  1692. ; $hTreeItem - HTREEITEM that is mapped to an accessibility ID
  1693. ; Return values .: Success - Returns an accessibility ID
  1694. ; Author ........: Paul Campbell (PaulIA)
  1695. ; Modified.......: Gary Frost (gafrost)
  1696. ; Remarks .......: Minimum OS Windows XP.
  1697. ; +
  1698. ; When you add an item to a control an HTREEITEM returns, which uniquely identifies the item.
  1699. ; Related .......:
  1700. ; Link ..........:
  1701. ; Example .......:
  1702. ; ===============================================================================================================================
  1703. Func _GUICtrlTreeView_MapItemToAccID($hWnd, $hTreeItem)
  1704. If Not IsHWnd($hTreeItem) Then $hTreeItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hTreeItem)
  1705. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1706. Return _SendMessage($hWnd, $TVM_MAPHTREEITEMTOACCID, $hTreeItem, 0, 0, "handle")
  1707. EndFunc ;==>_GUICtrlTreeView_MapItemToAccID
  1708. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  1709. ; Name...........: __GUICtrlTreeView_ReverseColorOrder
  1710. ; Description ...: Convert Hex RGB or BGR Color to Hex RGB or BGR Color
  1711. ; Syntax.........: __GUICtrlTreeView_ReverseColorOrder ( $vColor )
  1712. ; Parameters ....: $vColor - Hex Color
  1713. ; Return values .: Success - Hex RGB or BGR Color
  1714. ; Author ........: Gary Frost (gafrost)
  1715. ; Modified.......:
  1716. ; Remarks .......:
  1717. ; Related .......:
  1718. ; Link ..........:
  1719. ; Example .......:
  1720. ; ===============================================================================================================================
  1721. Func __GUICtrlTreeView_ReverseColorOrder($vColor)
  1722. Local $sHex = Hex(String($vColor), 6)
  1723. Return '0x' & StringMid($sHex, 5, 2) & StringMid($sHex, 3, 2) & StringMid($sHex, 1, 2)
  1724. EndFunc ;==>__GUICtrlTreeView_ReverseColorOrder
  1725. ; #FUNCTION# ====================================================================================================================
  1726. ; Author ........: Paul Campbell (PaulIA)
  1727. ; Modified.......: Gary Frost (gafrost)
  1728. ; ===============================================================================================================================
  1729. Func _GUICtrlTreeView_SelectItem($hWnd, $hItem, $iFlag = 0)
  1730. If Not IsHWnd($hItem) And $hItem <> 0 Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1731. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1732. If $iFlag = 0 Then $iFlag = $TVGN_CARET
  1733. Return _SendMessage($hWnd, $TVM_SELECTITEM, $iFlag, $hItem, 0, "wparam", "handle") <> 0
  1734. EndFunc ;==>_GUICtrlTreeView_SelectItem
  1735. ; #FUNCTION# ====================================================================================================================
  1736. ; Author ........: Paul Campbell (PaulIA)
  1737. ; Modified.......:
  1738. ; ===============================================================================================================================
  1739. Func _GUICtrlTreeView_SelectItemByIndex($hWnd, $hItem, $iIndex)
  1740. Return _GUICtrlTreeView_SelectItem($hWnd, _GUICtrlTreeView_GetItemByIndex($hWnd, $hItem, $iIndex))
  1741. EndFunc ;==>_GUICtrlTreeView_SelectItemByIndex
  1742. ; #FUNCTION# ====================================================================================================================
  1743. ; Author ........: Gary Frost (gafrost)
  1744. ; Modified.......:
  1745. ; ===============================================================================================================================
  1746. Func _GUICtrlTreeView_SetBkColor($hWnd, $vRGBColor)
  1747. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1748. Return __GUICtrlTreeView_ReverseColorOrder(_SendMessage($hWnd, $TVM_SETBKCOLOR, 0, Int(__GUICtrlTreeView_ReverseColorOrder($vRGBColor))))
  1749. EndFunc ;==>_GUICtrlTreeView_SetBkColor
  1750. ; #FUNCTION# ====================================================================================================================
  1751. ; Author ........: Paul Campbell (PaulIA)
  1752. ; Modified.......:
  1753. ; ===============================================================================================================================
  1754. Func _GUICtrlTreeView_SetBold($hWnd, $hItem, $bFlag = True)
  1755. Return _GUICtrlTreeView_SetState($hWnd, $hItem, $TVIS_BOLD, $bFlag)
  1756. EndFunc ;==>_GUICtrlTreeView_SetBold
  1757. ; #FUNCTION# ====================================================================================================================
  1758. ; Author ........: Gary Frost (gafrost
  1759. ; Modified.......:
  1760. ; ===============================================================================================================================
  1761. Func _GUICtrlTreeView_SetChecked($hWnd, $hItem, $bCheck = True)
  1762. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1763. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1764. Local $tItem = DllStructCreate($tagTVITEMEX)
  1765. DllStructSetData($tItem, "Mask", $TVIF_STATE)
  1766. DllStructSetData($tItem, "hItem", $hItem)
  1767. If $bCheck Then
  1768. DllStructSetData($tItem, "State", 0x2000)
  1769. Else
  1770. DllStructSetData($tItem, "State", 0x1000)
  1771. EndIf
  1772. DllStructSetData($tItem, "StateMask", 0xf000)
  1773. Return __GUICtrlTreeView_SetItem($hWnd, $tItem)
  1774. EndFunc ;==>_GUICtrlTreeView_SetChecked
  1775. ; #FUNCTION# ====================================================================================================================
  1776. ; Author ........: Paul Campbell (PaulIA)
  1777. ; Modified.......: Gary Frost (gafrost)
  1778. ; ===============================================================================================================================
  1779. Func _GUICtrlTreeView_SetCheckedByIndex($hWnd, $hItem, $iIndex, $bCheck = True)
  1780. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1781. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1782. Local $hChild = _GUICtrlTreeView_GetItemByIndex($hWnd, $hItem, $iIndex)
  1783. Return _GUICtrlTreeView_SetChecked($hWnd, $hChild, $bCheck)
  1784. EndFunc ;==>_GUICtrlTreeView_SetCheckedByIndex
  1785. ; #FUNCTION# ====================================================================================================================
  1786. ; Author ........: Paul Campbell (PaulIA)
  1787. ; Modified.......: Gary Frost (gafrost)
  1788. ; ===============================================================================================================================
  1789. Func _GUICtrlTreeView_SetChildren($hWnd, $hItem, $bFlag = True)
  1790. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1791. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1792. Local $tItem = DllStructCreate($tagTVITEMEX)
  1793. DllStructSetData($tItem, "Mask", BitOR($TVIF_HANDLE, $TVIF_CHILDREN))
  1794. DllStructSetData($tItem, "hItem", $hItem)
  1795. DllStructSetData($tItem, "Children", $bFlag)
  1796. Return __GUICtrlTreeView_SetItem($hWnd, $tItem)
  1797. EndFunc ;==>_GUICtrlTreeView_SetChildren
  1798. ; #FUNCTION# ====================================================================================================================
  1799. ; Author ........: Paul Campbell (PaulIA)
  1800. ; Modified.......: Gary Frost (gafrost)
  1801. ; ===============================================================================================================================
  1802. Func _GUICtrlTreeView_SetCut($hWnd, $hItem, $bFlag = True)
  1803. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1804. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1805. Return _GUICtrlTreeView_SetState($hWnd, $hItem, $TVIS_CUT, $bFlag)
  1806. EndFunc ;==>_GUICtrlTreeView_SetCut
  1807. ; #FUNCTION# ====================================================================================================================
  1808. ; Author ........: Paul Campbell (PaulIA)
  1809. ; Modified.......:
  1810. ; ===============================================================================================================================
  1811. Func _GUICtrlTreeView_SetDropTarget($hWnd, $hItem, $bFlag = True)
  1812. If $bFlag Then
  1813. Return _GUICtrlTreeView_SelectItem($hWnd, $hItem, $TVGN_DROPHILITE)
  1814. ElseIf _GUICtrlTreeView_GetDropTarget($hWnd, $hItem) Then
  1815. Return _GUICtrlTreeView_SelectItem($hWnd, 0)
  1816. EndIf
  1817. Return False
  1818. EndFunc ;==>_GUICtrlTreeView_SetDropTarget
  1819. ; #FUNCTION# ====================================================================================================================
  1820. ; Author ........: Paul Campbell (PaulIA)
  1821. ; Modified.......:
  1822. ; ===============================================================================================================================
  1823. Func _GUICtrlTreeView_SetFocused($hWnd, $hItem, $bFlag = True)
  1824. Return _GUICtrlTreeView_SetState($hWnd, $hItem, $TVIS_FOCUSED, $bFlag)
  1825. EndFunc ;==>_GUICtrlTreeView_SetFocused
  1826. ; #FUNCTION# ====================================================================================================================
  1827. ; Author ........: Paul Campbell (PaulIA)
  1828. ; Modified.......: Gary Frost (gafrost)
  1829. ; ===============================================================================================================================
  1830. Func _GUICtrlTreeView_SetHeight($hWnd, $iHeight)
  1831. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1832. Return _SendMessage($hWnd, $TVM_SETITEMHEIGHT, $iHeight)
  1833. EndFunc ;==>_GUICtrlTreeView_SetHeight
  1834. ; #FUNCTION# ====================================================================================================================
  1835. ; Author ........: Holger Kotsch
  1836. ; Modified.......: Gary Frost (gafrost)
  1837. ; ===============================================================================================================================
  1838. Func _GUICtrlTreeView_SetIcon($hWnd, $hItem = 0, $sIconFile = "", $iIconID = 0, $iImageMode = 6)
  1839. If $hItem = 0 Then $hItem = 0x00000000
  1840. If $hItem <> 0x00000000 And Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1841. If $hItem = 0x00000000 Or $sIconFile = "" Then Return SetError(1, 1, False)
  1842. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1843. Local $tTVITEM = DllStructCreate($tagTVITEMEX)
  1844. Local $tIcon = DllStructCreate("handle")
  1845. Local $aCount = DllCall("shell32.dll", "uint", "ExtractIconExW", "wstr", $sIconFile, "int", $iIconID, _
  1846. "handle", 0, "struct*", $tIcon, "uint", 1)
  1847. If @error Then Return SetError(@error, @extended, 0)
  1848. If $aCount[0] = 0 Then Return 0
  1849. Local $hImageList = _SendMessage($hWnd, $TVM_GETIMAGELIST, 0, 0, 0, "wparam", "lparam", "handle")
  1850. If $hImageList = 0x00000000 Then
  1851. $hImageList = DllCall("comctl32.dll", "handle", "ImageList_Create", "int", 16, "int", 16, "uint", 0x0021, "int", 0, "int", 1)
  1852. If @error Then Return SetError(@error, @extended, 0)
  1853. $hImageList = $hImageList[0]
  1854. If $hImageList = 0 Then Return SetError(1, 1, False)
  1855. _SendMessage($hWnd, $TVM_SETIMAGELIST, 0, $hImageList, 0, "wparam", "handle")
  1856. EndIf
  1857. Local $hIcon = DllStructGetData($tIcon, 1)
  1858. Local $vIcon = DllCall("comctl32.dll", "int", "ImageList_AddIcon", "handle", $hImageList, "handle", $hIcon)
  1859. $vIcon = $vIcon[0]
  1860. If @error Then
  1861. Local $iError = @error, $iExtended = @extended
  1862. DllCall("user32.dll", "int", "DestroyIcon", "handle", $hIcon)
  1863. ; No @error test because results are unimportant.
  1864. Return SetError($iError, $iExtended, 0)
  1865. EndIf
  1866. DllCall("user32.dll", "int", "DestroyIcon", "handle", $hIcon)
  1867. ; No @error test because results are unimportant.
  1868. Local $iMask = BitOR($TVIF_IMAGE, $TVIF_SELECTEDIMAGE)
  1869. If BitAND($iImageMode, 2) Then
  1870. DllStructSetData($tTVITEM, "Image", $vIcon)
  1871. If Not BitAND($iImageMode, 4) Then $iMask = $TVIF_IMAGE
  1872. EndIf
  1873. If BitAND($iImageMode, 4) Then
  1874. DllStructSetData($tTVITEM, "SelectedImage", $vIcon)
  1875. If Not BitAND($iImageMode, 2) Then
  1876. $iMask = $TVIF_SELECTEDIMAGE
  1877. Else
  1878. $iMask = BitOR($TVIF_IMAGE, $TVIF_SELECTEDIMAGE)
  1879. EndIf
  1880. EndIf
  1881. DllStructSetData($tTVITEM, "Mask", $iMask)
  1882. DllStructSetData($tTVITEM, "hItem", $hItem)
  1883. Return __GUICtrlTreeView_SetItem($hWnd, $tTVITEM)
  1884. EndFunc ;==>_GUICtrlTreeView_SetIcon
  1885. ; #FUNCTION# ====================================================================================================================
  1886. ; Author ........: Paul Campbell (PaulIA)
  1887. ; Modified.......: Gary Frost (gafrost)
  1888. ; ===============================================================================================================================
  1889. Func _GUICtrlTreeView_SetImageIndex($hWnd, $hItem, $iIndex)
  1890. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1891. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1892. Local $tItem = DllStructCreate($tagTVITEMEX)
  1893. DllStructSetData($tItem, "Mask", BitOR($TVIF_HANDLE, $TVIF_IMAGE))
  1894. DllStructSetData($tItem, "hItem", $hItem)
  1895. DllStructSetData($tItem, "Image", $iIndex)
  1896. Return __GUICtrlTreeView_SetItem($hWnd, $tItem)
  1897. EndFunc ;==>_GUICtrlTreeView_SetImageIndex
  1898. ; #FUNCTION# ====================================================================================================================
  1899. ; Author ........: Gary Frost (gafrost)
  1900. ; Modified.......:
  1901. ; ===============================================================================================================================
  1902. Func _GUICtrlTreeView_SetIndent($hWnd, $iIndent)
  1903. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1904. _SendMessage($hWnd, $TVM_SETINDENT, $iIndent)
  1905. EndFunc ;==>_GUICtrlTreeView_SetIndent
  1906. ; #FUNCTION# ====================================================================================================================
  1907. ; Author ........: Paul Campbell (PaulIA)
  1908. ; Modified.......: Gary Frost (gafrost)
  1909. ; ===============================================================================================================================
  1910. Func _GUICtrlTreeView_SetInsertMark($hWnd, $hItem, $bAfter = True)
  1911. If Not IsHWnd($hItem) And $hItem <> 0 Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1912. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1913. Return _SendMessage($hWnd, $TVM_SETINSERTMARK, $bAfter, $hItem, 0, "wparam", "handle") <> 0
  1914. EndFunc ;==>_GUICtrlTreeView_SetInsertMark
  1915. ; #FUNCTION# ====================================================================================================================
  1916. ; Author ........: Paul Campbell (PaulIA)
  1917. ; Modified.......: Gary Frost (gafrost)
  1918. ; ===============================================================================================================================
  1919. Func _GUICtrlTreeView_SetInsertMarkColor($hWnd, $iColor)
  1920. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1921. Return _SendMessage($hWnd, $TVM_SETINSERTMARKCOLOR, 0, $iColor)
  1922. EndFunc ;==>_GUICtrlTreeView_SetInsertMarkColor
  1923. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  1924. ; Name...........: __GUICtrlTreeView_SetItem
  1925. ; Description ...: Sets some or all of a items attributes
  1926. ; Syntax.........: __GUICtrlTreeView_SetItem ( $hWnd, ByRef $tItem )
  1927. ; Parameters ....: $hWnd - Handle to the control
  1928. ; $tItem - $tagTVITEMEX structure that contains the new item attributes
  1929. ; Return values .: Success - True
  1930. ; Failure - False
  1931. ; Author ........: Paul Campbell (PaulIA)
  1932. ; Modified.......: Gary Frost (gafrost)
  1933. ; Remarks .......: This function is used internally and should not normally be called by the end user
  1934. ; Related .......: __GUICtrlTreeView_GetItem
  1935. ; Link ..........:
  1936. ; Example .......:
  1937. ; ===============================================================================================================================
  1938. Func __GUICtrlTreeView_SetItem($hWnd, ByRef $tItem)
  1939. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1940. Local $bUnicode = _GUICtrlTreeView_GetUnicodeFormat($hWnd)
  1941. Local $iRet
  1942. If _WinAPI_InProcess($hWnd, $__g_hTVLastWnd) Then
  1943. $iRet = _SendMessage($hWnd, $TVM_SETITEMW, 0, $tItem, 0, "wparam", "struct*")
  1944. Else
  1945. Local $iItem = DllStructGetSize($tItem)
  1946. Local $tMemMap
  1947. Local $pMemory = _MemInit($hWnd, $iItem, $tMemMap)
  1948. _MemWrite($tMemMap, $tItem)
  1949. If $bUnicode Then
  1950. $iRet = _SendMessage($hWnd, $TVM_SETITEMW, 0, $pMemory, 0, "wparam", "ptr")
  1951. Else
  1952. $iRet = _SendMessage($hWnd, $TVM_SETITEMA, 0, $pMemory, 0, "wparam", "ptr")
  1953. EndIf
  1954. _MemFree($tMemMap)
  1955. EndIf
  1956. Return $iRet <> 0
  1957. EndFunc ;==>__GUICtrlTreeView_SetItem
  1958. ; #FUNCTION# ====================================================================================================================
  1959. ; Author ........: Paul Campbell (PaulIA)
  1960. ; Modified.......:
  1961. ; ===============================================================================================================================
  1962. Func _GUICtrlTreeView_SetItemHeight($hWnd, $hItem, $iIntegral)
  1963. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1964. _GUICtrlTreeView_BeginUpdate($hWnd)
  1965. Local $tItem = DllStructCreate($tagTVITEMEX)
  1966. DllStructSetData($tItem, "Mask", BitOR($TVIF_HANDLE, $TVIF_INTEGRAL))
  1967. DllStructSetData($tItem, "hItem", $hItem)
  1968. DllStructSetData($tItem, "Integral", $iIntegral)
  1969. Local $bResult = __GUICtrlTreeView_SetItem($hWnd, $tItem)
  1970. _GUICtrlTreeView_EndUpdate($hWnd)
  1971. Return $bResult
  1972. EndFunc ;==>_GUICtrlTreeView_SetItemHeight
  1973. ; #FUNCTION# ====================================================================================================================
  1974. ; Author ........: Gary Frost (gafrost)
  1975. ; Modified.......:
  1976. ; ===============================================================================================================================
  1977. Func _GUICtrlTreeView_SetItemParam($hWnd, $hItem, $iParam)
  1978. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  1979. Local $tItem = DllStructCreate($tagTVITEMEX)
  1980. DllStructSetData($tItem, "Mask", BitOR($TVIF_HANDLE, $TVIF_PARAM))
  1981. DllStructSetData($tItem, "hItem", $hItem)
  1982. DllStructSetData($tItem, "Param", $iParam)
  1983. Local $bResult = __GUICtrlTreeView_SetItem($hWnd, $tItem)
  1984. Return $bResult
  1985. EndFunc ;==>_GUICtrlTreeView_SetItemParam
  1986. ; #FUNCTION# ====================================================================================================================
  1987. ; Author ........: Gary Frost (gafrost)
  1988. ; Modified.......:
  1989. ; ===============================================================================================================================
  1990. Func _GUICtrlTreeView_SetLineColor($hWnd, $vRGBColor)
  1991. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  1992. Return __GUICtrlTreeView_ReverseColorOrder(_SendMessage($hWnd, $TVM_SETLINECOLOR, 0, Int(__GUICtrlTreeView_ReverseColorOrder($vRGBColor))))
  1993. EndFunc ;==>_GUICtrlTreeView_SetLineColor
  1994. ; #FUNCTION# ====================================================================================================================
  1995. ; Author ........: Paul Campbell (PaulIA)
  1996. ; Modified.......: Gary Frost (gafrost)
  1997. ; ===============================================================================================================================
  1998. Func _GUICtrlTreeView_SetNormalImageList($hWnd, $hImageList)
  1999. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  2000. Return _SendMessage($hWnd, $TVM_SETIMAGELIST, $TVSIL_NORMAL, $hImageList, 0, "wparam", "handle", "handle")
  2001. EndFunc ;==>_GUICtrlTreeView_SetNormalImageList
  2002. ; #NO_DOC_FUNCTION# =============================================================================================================
  2003. ; Name...........: _GUICtrlTreeView_SetOverlayImageIndex
  2004. ; Description ...: Sets the index into image list for the state image
  2005. ; Syntax.........: _GUICtrlTreeView_SetOverlayImageIndex ( $hWnd, $hItem, $iIndex )
  2006. ; Parameters ....: $hWnd - Handle to the control
  2007. ; $hItem - Handle to the item
  2008. ; $iIndex - Image list index
  2009. ; Return values .: Success - True
  2010. ; Failure - False
  2011. ; Author ........: Paul Campbell (PaulIA)
  2012. ; Modified.......: Gary Frost (gafrost)
  2013. ; Remarks .......:
  2014. ; Related .......: _GUICtrlTreeView_GetOverlayImageIndex
  2015. ; Link ..........:
  2016. ; Example .......:
  2017. ; ===============================================================================================================================
  2018. Func _GUICtrlTreeView_SetOverlayImageIndex($hWnd, $hItem, $iIndex)
  2019. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  2020. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  2021. Local $tItem = DllStructCreate($tagTVITEMEX)
  2022. DllStructSetData($tItem, "Mask", BitOR($TVIF_HANDLE, $TVIF_STATE))
  2023. DllStructSetData($tItem, "hItem", $hItem)
  2024. DllStructSetData($tItem, "State", BitShift($iIndex, -8))
  2025. DllStructSetData($tItem, "StateMask", $TVIS_OVERLAYMASK)
  2026. Return __GUICtrlTreeView_SetItem($hWnd, $tItem)
  2027. EndFunc ;==>_GUICtrlTreeView_SetOverlayImageIndex
  2028. ; #FUNCTION# ====================================================================================================================
  2029. ; Author ........: Paul Campbell (PaulIA)
  2030. ; Modified.......: Gary Frost (gafrost)
  2031. ; ===============================================================================================================================
  2032. Func _GUICtrlTreeView_SetScrollTime($hWnd, $iTime)
  2033. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  2034. Return _SendMessage($hWnd, $TVM_SETSCROLLTIME, $iTime)
  2035. EndFunc ;==>_GUICtrlTreeView_SetScrollTime
  2036. ; #FUNCTION# ====================================================================================================================
  2037. ; Author ........: Paul Campbell (PaulIA)
  2038. ; Modified.......:
  2039. ; ===============================================================================================================================
  2040. Func _GUICtrlTreeView_SetSelected($hWnd, $hItem, $bFlag = True)
  2041. Return _GUICtrlTreeView_SetState($hWnd, $hItem, $TVIS_SELECTED, $bFlag)
  2042. EndFunc ;==>_GUICtrlTreeView_SetSelected
  2043. ; #FUNCTION# ====================================================================================================================
  2044. ; Author ........: Paul Campbell (PaulIA)
  2045. ; Modified.......: Gary Frost (gafrost)
  2046. ; ===============================================================================================================================
  2047. Func _GUICtrlTreeView_SetSelectedImageIndex($hWnd, $hItem, $iIndex)
  2048. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  2049. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  2050. Local $tItem = DllStructCreate($tagTVITEMEX)
  2051. DllStructSetData($tItem, "Mask", BitOR($TVIF_HANDLE, $TVIF_SELECTEDIMAGE))
  2052. DllStructSetData($tItem, "hItem", $hItem)
  2053. DllStructSetData($tItem, "SelectedImage", $iIndex)
  2054. Return __GUICtrlTreeView_SetItem($hWnd, $tItem)
  2055. EndFunc ;==>_GUICtrlTreeView_SetSelectedImageIndex
  2056. ; #FUNCTION# ====================================================================================================================
  2057. ; Author ........: Holger Kotsch
  2058. ; Modified.......: Gary Frost (gafrost)
  2059. ; ===============================================================================================================================
  2060. Func _GUICtrlTreeView_SetState($hWnd, $hItem, $iState = 0, $bSetState = True)
  2061. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  2062. If $hItem = 0x00000000 Or ($iState = 0 And $bSetState = False) Then Return False
  2063. Local $tTVITEM = DllStructCreate($tagTVITEMEX)
  2064. If @error Then Return SetError(1, 1, 0)
  2065. DllStructSetData($tTVITEM, "Mask", $TVIF_STATE)
  2066. DllStructSetData($tTVITEM, "hItem", $hItem)
  2067. If $bSetState Then
  2068. DllStructSetData($tTVITEM, "State", $iState)
  2069. Else
  2070. DllStructSetData($tTVITEM, "State", BitAND($bSetState, $iState))
  2071. EndIf
  2072. DllStructSetData($tTVITEM, "StateMask", $iState)
  2073. If $bSetState Then DllStructSetData($tTVITEM, "StateMask", BitOR($bSetState, $iState))
  2074. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  2075. Return __GUICtrlTreeView_SetItem($hWnd, $tTVITEM)
  2076. EndFunc ;==>_GUICtrlTreeView_SetState
  2077. ; #FUNCTION# ====================================================================================================================
  2078. ; Author ........: Paul Campbell (PaulIA)
  2079. ; Modified.......: Gary Frost (gafrost)
  2080. ; ===============================================================================================================================
  2081. Func _GUICtrlTreeView_SetStateImageIndex($hWnd, $hItem, $iIndex)
  2082. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  2083. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  2084. If $iIndex < 0 Then
  2085. ; Invalid index for State Image" & @LF & "State Image List is One-based list
  2086. Return SetError(1, 0, False)
  2087. EndIf
  2088. Local $tItem = DllStructCreate($tagTVITEMEX)
  2089. DllStructSetData($tItem, "Mask", $TVIF_STATE)
  2090. DllStructSetData($tItem, "hItem", $hItem)
  2091. DllStructSetData($tItem, "State", BitShift($iIndex, -12))
  2092. DllStructSetData($tItem, "StateMask", $TVIS_STATEIMAGEMASK)
  2093. Return __GUICtrlTreeView_SetItem($hWnd, $tItem)
  2094. EndFunc ;==>_GUICtrlTreeView_SetStateImageIndex
  2095. ; #FUNCTION# ====================================================================================================================
  2096. ; Author ........: Gary Frost (gafrost)
  2097. ; Modified.......:
  2098. ; ===============================================================================================================================
  2099. Func _GUICtrlTreeView_SetStateImageList($hWnd, $hImageList)
  2100. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  2101. ; haven't figured out why but the state image list appears to use a 1 based index
  2102. ; add and icon
  2103. _GUIImageList_AddIcon($hImageList, "shell32.dll", 0)
  2104. Local $iCount = _GUIImageList_GetImageCount($hImageList)
  2105. ; shift it to the zero index, won't be used
  2106. For $x = $iCount - 1 To 1 Step -1
  2107. _GUIImageList_Swap($hImageList, $x, $x - 1)
  2108. Next
  2109. Return _SendMessage($hWnd, $TVM_SETIMAGELIST, $TVSIL_STATE, $hImageList, 0, "wparam", "handle", "handle")
  2110. EndFunc ;==>_GUICtrlTreeView_SetStateImageList
  2111. ; #FUNCTION# ====================================================================================================================
  2112. ; Author ........: Holger Kotsch
  2113. ; Modified.......: Gary Frost (gafrost)
  2114. ; ===============================================================================================================================
  2115. Func _GUICtrlTreeView_SetText($hWnd, $hItem = 0, $sText = "")
  2116. If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
  2117. If $hItem = 0x00000000 Or $sText = "" Then Return SetError(1, 1, 0)
  2118. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  2119. Local $tTVITEM = DllStructCreate($tagTVITEMEX)
  2120. Local $iBuffer = StringLen($sText) + 1
  2121. Local $tBuffer
  2122. Local $bUnicode = _GUICtrlTreeView_GetUnicodeFormat($hWnd)
  2123. If $bUnicode Then
  2124. $tBuffer = DllStructCreate("wchar Buffer[" & $iBuffer & "]")
  2125. $iBuffer *= 2
  2126. Else
  2127. $tBuffer = DllStructCreate("char Buffer[" & $iBuffer & "]")
  2128. EndIf
  2129. DllStructSetData($tBuffer, "Buffer", $sText)
  2130. DllStructSetData($tTVITEM, "Mask", BitOR($TVIF_HANDLE, $TVIF_TEXT))
  2131. DllStructSetData($tTVITEM, "hItem", $hItem)
  2132. DllStructSetData($tTVITEM, "TextMax", $iBuffer)
  2133. Local $bResult
  2134. If _WinAPI_InProcess($hWnd, $__g_hTVLastWnd) Then
  2135. DllStructSetData($tTVITEM, "Text", DllStructGetPtr($tBuffer))
  2136. $bResult = _SendMessage($hWnd, $TVM_SETITEMW, 0, $tTVITEM, 0, "wparam", "struct*")
  2137. Else
  2138. Local $iItem = DllStructGetSize($tTVITEM)
  2139. Local $tMemMap
  2140. Local $pMemory = _MemInit($hWnd, $iItem + $iBuffer, $tMemMap)
  2141. Local $pText = $pMemory + $iItem
  2142. DllStructSetData($tTVITEM, "Text", $pText)
  2143. _MemWrite($tMemMap, $tTVITEM, $pMemory, $iItem)
  2144. _MemWrite($tMemMap, $tBuffer, $pText, $iBuffer)
  2145. If $bUnicode Then
  2146. $bResult = _SendMessage($hWnd, $TVM_SETITEMW, 0, $pMemory, 0, "wparam", "ptr")
  2147. Else
  2148. $bResult = _SendMessage($hWnd, $TVM_SETITEMA, 0, $pMemory, 0, "wparam", "ptr")
  2149. EndIf
  2150. _MemFree($tMemMap)
  2151. EndIf
  2152. Return $bResult <> 0
  2153. EndFunc ;==>_GUICtrlTreeView_SetText
  2154. ; #FUNCTION# ====================================================================================================================
  2155. ; Author ........: Gary Frost (gafrost)
  2156. ; Modified.......:
  2157. ; ===============================================================================================================================
  2158. Func _GUICtrlTreeView_SetTextColor($hWnd, $vRGBColor)
  2159. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  2160. Return __GUICtrlTreeView_ReverseColorOrder(_SendMessage($hWnd, $TVM_SETTEXTCOLOR, 0, Int(__GUICtrlTreeView_ReverseColorOrder($vRGBColor))))
  2161. EndFunc ;==>_GUICtrlTreeView_SetTextColor
  2162. ; #FUNCTION# ====================================================================================================================
  2163. ; Author ........: Paul Campbell (PaulIA)
  2164. ; Modified.......: Gary Frost (gafrost)
  2165. ; ===============================================================================================================================
  2166. Func _GUICtrlTreeView_SetToolTips($hWnd, $hToolTip)
  2167. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  2168. Return _SendMessage($hWnd, $TVM_SETTOOLTIPS, $hToolTip, 0, 0, "wparam", "int", "hwnd")
  2169. EndFunc ;==>_GUICtrlTreeView_SetToolTips
  2170. ; #FUNCTION# ====================================================================================================================
  2171. ; Author ........: Paul Campbell (PaulIA)
  2172. ; Modified.......: Gary Frost (gafrost)
  2173. ; ===============================================================================================================================
  2174. Func _GUICtrlTreeView_SetUnicodeFormat($hWnd, $bFormat = True)
  2175. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  2176. Return _SendMessage($hWnd, $TVM_SETUNICODEFORMAT, $bFormat)
  2177. EndFunc ;==>_GUICtrlTreeView_SetUnicodeFormat
  2178. ; #FUNCTION# ====================================================================================================================
  2179. ; Author ........: Gary Frost (gafrost)
  2180. ; Modified.......: mlipok, guinness, gillesg
  2181. ; ===============================================================================================================================
  2182. Func _GUICtrlTreeView_Sort($hWnd)
  2183. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  2184. Local $iItemCount = _GUICtrlTreeView_GetCount($hWnd)
  2185. If $iItemCount Then
  2186. Local $aTreeView[$iItemCount], $i = 0
  2187. ; get only A child at each level
  2188. Local $hHandle = _GUICtrlTreeView_GetFirstItem($hWnd)
  2189. $aTreeView[1] = $hHandle
  2190. $aTreeView[0] = 2
  2191. __GUICtrlTreeView_SortGetFirstChild($hWnd, $hHandle, $aTreeView)
  2192. ReDim $aTreeView[$aTreeView[0]]
  2193. $aTreeView[0] = 0
  2194. For $i = 0 To UBound($aTreeView) - 1
  2195. _SendMessage($hWnd, $TVM_SORTCHILDREN, 0, $aTreeView[$i], 0, "wparam", "handle") ; Sort the items in root
  2196. Next
  2197. EndIf
  2198. EndFunc ;==>_GUICtrlTreeView_Sort
  2199. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  2200. ; Name...........: __GUICtrlTreeView_SortGetFirstChild
  2201. ; Description ...: Sets some or all of a items attributes
  2202. ; Syntax.........: __GUICtrlTreeView_SortGetFirstChild ( $hWnd, $hItem, ByRef $aTreeView )
  2203. ; Parameters ....: $hWnd - Handle to the control
  2204. ; $hItem - Handle to the item
  2205. ; $aTreeView - Byref array to store first chidren handles
  2206. ; Return values .: None
  2207. ; Author ........: gillesg
  2208. ; Modified.......:
  2209. ; Remarks .......: This function is used internally and should not normally be called by the end user
  2210. ; Related .......:
  2211. ; Link ..........: https://www.autoitscript.com/trac/autoit/ticket/3585
  2212. ; Example .......:
  2213. ; ===============================================================================================================================
  2214. Func __GUICtrlTreeView_SortGetFirstChild($hWnd, $hItem, ByRef $aTreeView)
  2215. Local $hChild = _GUICtrlTreeView_GetFirstChild($hWnd, $hItem)
  2216. If $hChild <> 0 Then
  2217. $aTreeView[$aTreeView[0]] = $hChild
  2218. $aTreeView[0] += 1
  2219. __GUICtrlTreeView_SortGetFirstChild($hWnd, $hChild, $aTreeView)
  2220. EndIf
  2221. Local $hNext = _GUICtrlTreeView_GetNextSibling($hWnd, $hItem)
  2222. If $hNext <> 0 Then __GUICtrlTreeView_SortGetFirstChild($hWnd, $hNext, $aTreeView)
  2223. EndFunc ;==>__GUICtrlTreeView_SortGetFirstChild