Retrieve the item handle
#include <GuiTreeView.au3>
_GUICtrlTreeView_GetItemHandle ( $hWnd [, $hItem = 0] )
$hWnd | Control ID/Handle to the control |
$hItem | [optional] Item ID |
Success: | the item handle. |
Failure: | 0. |
#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
Example()
Func Example()
Local $hGui, $ahItem[10], $ahItemChild[30], $iYIndex = 0, $iRand, $hTreeView
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
$hGui = GUICreate("TreeView Get Item Handle", 400, 300)
$hTreeView = _GUICtrlTreeView_Create($hGui, 2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState(@SW_SHOW)
_GUICtrlTreeView_BeginUpdate($hTreeView)
For $x = 0 To 9
$ahItem[$x] = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x))
For $y = $iYIndex To $iYIndex + 2
$ahItemChild[$y] = _GUICtrlTreeView_AddChild($hTreeView, $ahItem[$x], StringFormat("[%02d] New Child Item", $y))
Next
$iYIndex += 3
Next
_GUICtrlTreeView_EndUpdate($hTreeView)
$iRand = Random(0, 9, 1)
MsgBox($MB_SYSTEMMODAL, "Information", StringFormat("Item handle for index %d: %s\r\nIsPtr = %d IsHWnd = %d", $iRand, _GUICtrlTreeView_GetItemHandle($hTreeView, $ahItem[$iRand]), _
IsPtr(_GUICtrlTreeView_GetItemHandle($hTreeView, $ahItem[$iRand])), IsHWnd(_GUICtrlTreeView_GetItemHandle($hTreeView, $ahItem[$iRand]))))
$iRand = Random(0, 29, 1)
MsgBox($MB_SYSTEMMODAL, "Information", StringFormat("Item handle for child index %d: %s", $iRand, _GUICtrlTreeView_GetItemHandle($hTreeView, $ahItemChild[$iRand])))
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example