Code : Tout sélectionner
#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
global $bouton,$msg
$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work
_Main()
Func _Main()
Local $hItem[6], $hRandomItem, $hTreeView
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
GUICreate("TreeView Get Focused", 500, 400)
$bouton=GUICtrlCreateButton(" test ",1,1)
$hTreeView = GUICtrlCreateTreeView(2, 40, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState()
_GUICtrlTreeView_BeginUpdate($hTreeView)
For $x = 0 To UBound($hItem) - 1
$hItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x + 1), $hTreeView)
Next
_GUICtrlTreeView_EndUpdate($hTreeView)
_GUICtrlTreeView_SetSelected($hTreeView, $hItem[4])
$hRandomItem = 4
MsgBox(4160, "Information", StringFormat("Item %d Focused? %s", $hRandomItem, _GUICtrlTreeView_GetFocused($hTreeView, $hItem[$hRandomItem])))
_GUICtrlTreeView_SetFocused($hTreeView, $hItem[$hRandomItem],True)
MsgBox(4160, "Information", StringFormat("Item %d Focused? %s", $hRandomItem, _GUICtrlTreeView_GetFocused($hTreeView, $hItem[$hRandomItem])))
; Loop until user exits
Do
$msg = GUIGetMsg()
;~ Sleep(500)
if $msg=$bouton Then
$hRandomItem = 3
MsgBox(4160, "Information", StringFormat("Item %d Focused? %s", $hRandomItem, _GUICtrlTreeView_GetFocused($hTreeView, $hItem[$hRandomItem])))
_GUICtrlTreeView_SetFocused($hTreeView, $hItem[$hRandomItem],True)
MsgBox(4160, "Information", StringFormat("Item %d Focused? %s", $hRandomItem, _GUICtrlTreeView_GetFocused($hTreeView, $hItem[$hRandomItem])))
EndIf
Until $msg = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main