函数参考


_GUICtrlTreeView_GetItemParam

检索项目的特定应用值

#include <GuiTreeView.au3>
_GUICtrlTreeView_GetItemParam($hWnd [, $hItem = 0])

参数

$hWnd 控件ID/句柄
$hItem [可选参数] 项目 ID

返回值

成功: 返回项目参数
失败: 返回 0

注意/说明

None.

相关

_GUICtrlTreeView_SetItemParam

示例/演示


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

$Debug_TV = False ; 检查传递给函数的类名, 设置为真并使用另一控件的句柄可以看出它是否有效

; 警告不要把 SetItemParam 用在使用 GUICtrlCreateTreeViewItem 创建的项目上
; Param 为用内置函数创建的项目的控件 ID

Example_Internal()
Example_External()

Func Example_Internal()

    Local $hItem[10], $hItemChild[30], $iYIndex = 0, $iRand, $hTreeView
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

    GUICreate("TreeView Get Item Param", 400, 300)

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

    _GUICtrlTreeView_BeginUpdate($hTreeView)
    For $x = 0 To 9
        $hItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x), $hTreeView)
        For $y = $iYIndex To $iYIndex + 2
            $hItemChild[$y] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Child Item", $y), $hItem[$x])
        Next
        $iYIndex += 3
    Next
    _GUICtrlTreeView_EndUpdate($hTreeView)

    $iRand = Random(0, 9, 1)
    MsgBox(4160, "信息", StringFormat("Item Param/ID for index %d: %s\r\nIsPtr = %d IsHWnd = %d", $iRand, _GUICtrlTreeView_GetItemParam($hTreeView, $hItem[$iRand]), _
            IsPtr(_GUICtrlTreeView_GetItemHandle($hTreeView, $hItem[$iRand])), IsHWnd(_GUICtrlTreeView_GetItemHandle($hTreeView, $hItem[$iRand]))))
    $iRand = Random(0, 29, 1)
    MsgBox(4160, "信息", StringFormat("Item Param/ID for child index %d: %s", $iRand, _GUICtrlTreeView_GetItemParam($hTreeView, $hItemChild[$iRand])))

    ; 循环直到用户退出
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example_Internal

Func Example_External()

    Local $GUI, $hItem[10], $hItemChild[30], $iYIndex = 0, $iRand, $iParam = 1, $hTreeView
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

    $GUI = GUICreate("(UDF Created) TreeView Get Item Param", 400, 300)

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

    _GUICtrlTreeView_BeginUpdate($hTreeView)
    For $x = 0 To 9
        $hItem[$x] = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x))
        _GUICtrlTreeView_SetItemParam($hTreeView, $hItem[$x], $iParam)
        $iParam += 1
        For $y = $iYIndex To $iYIndex + 2
            $hItemChild[$y] = _GUICtrlTreeView_AddChild($hTreeView, $hItem[$x], StringFormat("[%02d] New Item", $y))
            _GUICtrlTreeView_SetItemParam($hTreeView, $hItemChild[$y], $iParam)
            $iParam += 1
        Next
        $iYIndex += 3
    Next
    _GUICtrlTreeView_EndUpdate($hTreeView)

    $iRand = Random(0, 9, 1)
    MsgBox(4160, "信息", StringFormat("Item Param/ID for index %d: %s\r\nIsPtr = %d IsHWnd = %d", $iRand, _GUICtrlTreeView_GetItemParam($hTreeView, $hItem[$iRand]), _
            IsPtr(_GUICtrlTreeView_GetItemHandle($hTreeView, $hItem[$iRand])), IsHWnd(_GUICtrlTreeView_GetItemHandle($hTreeView, $hItem[$iRand]))))
    $iRand = Random(0, 29, 1)
    MsgBox(4160, "信息", StringFormat("Item Param for child index %d: %s", $iRand, _GUICtrlTreeView_GetItemParam($hTreeView, $hItemChild[$iRand])))

    ; 循环直到用户退出
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example_External