Create a TreeView control
#include <GuiTreeView.au3>
_GUICtrlTreeView_Create ( $hWnd, $iX, $iY [, $iWidth = 150 [, $iHeight = 150 [, $iStyle = 0x00000037 [, $iExStyle = 0x00000000]]]] )
$hWnd | Handle to parent or owner window |
$iX | Horizontal position of the control |
$iY | Vertical position of the control |
$iWidth | [optional] Control width |
$iHeight | [optional] Control height |
$iStyle | [optional] Control style: $TVS_CHECKBOXES - Enables check boxes for items. A check box will be displayed only if an image is associated with the item. When set to this style, the control effectively uses DrawFrameControl to create and set a state image list containing two images. State image 1 is the unchecked box and state image 2 is the checked box. Setting the state image to zero removes the check box. Version 5.80 displays a check box even if no image is associated with the item. $TVS_DISABLEDRAGDROP - Prevents the control from sending $TVN_BEGINDRAG notification messages $TVS_EDITLABELS - Allows the user to edit the item labels $TVS_FULLROWSELECT - Enables full row selection. The entire row of the selected item is highlighted, and clicking anywhere on an item's row causes it to be selected. This style cannot be used in conjunction with the $TVS_HASLINES style. $TVS_HASBUTTONS - Displays plus and minus buttons next to parent items. The user clicks the buttons to expand or collapse a parent item's list of child items. To include buttons with items at the root, you must also specify $TVS_LINESATROOT. $TVS_HASLINES - Uses lines to show the hierarchy of items $TVS_INFOTIP - Obtains ToolTip information by sending the $TVN_GETINFOTIP notification $TVS_LINESATROOT - Uses lines to link items at the root of the control. This value is ignored if $TVS_HASLINES is not also specified. $TVS_NOHSCROLL - Disables horizontal scrolling in the control. The control will not display any horizontal scroll bars. $TVS_NONEVENHEIGHT - Sets the height of the items to an odd height with the $TVM_SETITEMHEIGHT message. By default the height of items must be an even value. $TVS_NOSCROLL - Disables both horizontal and vertical scrolling in the control. The control will not display any scroll bars. $TVS_NOTOOLTIPS - Disables ToolTips $TVS_RTLREADING - Causes text to be displayed from right to left $TVS_SHOWSELALWAYS - Causes a selected item to remain selected when the control loses focus $TVS_SINGLEEXPAND - Causes the item being selected to expand and the item being unselected to collapse upon selection. If the mouse is used to single-click the selected item and that item is closed, it will be expanded. If the user holds down the CTRL key while selecting an item, the item being unselected will not be collapsed. Version 5.80 causes the item being selected to expand and the item being unselected to collapse upon selection. If the user holds down the CTRL key while selecting an item, the item being unselected will not be collapsed. $TVS_TRACKSELECT - Enables hot tracking Default: $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS Forced: $WS_CHILD, $WS_VISIBLE |
$iExStyle | [optional] Control extended style |
Success: | the handle to the control. |
Failure: | 0. |
This function is for Advanced users and for learning how the control works.
#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
Global $g_hTreeView
Example()
Func Example()
Local $hGUI, $hItem
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
$hGUI = GUICreate("(UDF Created) TreeView Create", 400, 300)
$g_hTreeView = _GUICtrlTreeView_Create($hGUI, 2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlTreeView_BeginUpdate($g_hTreeView)
For $x = 1 To Random(2, 10, 1)
$hItem = _GUICtrlTreeView_Add($g_hTreeView, 0, StringFormat("[%02d] New Item", $x))
For $y = 1 To Random(2, 10, 1)
_GUICtrlTreeView_AddChild($g_hTreeView, $hItem, StringFormat("[%02d] New Child", $y))
Next
Next
_GUICtrlTreeView_EndUpdate($g_hTreeView)
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
$hWndTreeview = $g_hTreeView
If Not IsHWnd($g_hTreeView) Then $hWndTreeview = GUICtrlGetHandle($g_hTreeView)
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeview
Switch $iCode
Case $NM_CLICK ; The user has clicked the left mouse button within the control
_DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; Return 1 ; nonzero to not allow the default processing
Return 0 ; zero to allow the default processing
Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
_DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; Return 1 ; nonzero to not allow the default processing
Return 0 ; zero to allow the default processing
Case $NM_RCLICK ; The user has clicked the right mouse button within the control
_DebugPrint("$NM_RCLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; Return 1 ; nonzero to not allow the default processing
Return 0 ; zero to allow the default processing
Case $NM_RDBLCLK ; The user has double-clicked the right mouse button within the control
_DebugPrint("$NM_RDBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; Return 1 ; nonzero to not allow the default processing
Return 0 ; zero to allow the default processing
Case $NM_KILLFOCUS ; control has lost the input focus
_DebugPrint("$NM_KILLFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; No return value
Case $NM_RETURN ; control has the input focus and that the user has pressed the key
_DebugPrint("$NM_RETURN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; Return 1 ; nonzero to not allow the default processing
Return 0 ; zero to allow the default processing
; Case $NM_SETCURSOR ; control is setting the cursor in response to a WM_SETCURSOR message
; Local $tInfo = DllStructCreate($tagNMMOUSE, $lParam)
; $hWndFrom = HWnd(DllStructGetData($tInfo, "hWndFrom"))
; $iIDFrom = DllStructGetData($tInfo, "IDFrom")
; $iCode = DllStructGetData($tInfo, "Code")
; _DebugPrint("$NM_SETCURSOR" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
; "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
; "-->Code:" & @TAB & $iCode & @CRLF & _
; "-->ItemSpec:" & @TAB & DllStructGetData($tInfo, "ItemSpec") & @CRLF & _
; "-->ItemData:" & @TAB & DllStructGetData($tInfo, "ItemData") & @CRLF & _
; "-->X:" & @TAB & DllStructGetData($tInfo, "X") & @CRLF & _
; "-->Y:" & @TAB & DllStructGetData($tInfo, "Y") & @CRLF & _
; "-->HitInfo:" & @TAB & DllStructGetData($tInfo, "HitInfo"))
; Return 0 ; to enable the control to set the cursor
; Return 1 ; nonzero to prevent the control from setting the cursor
Case $NM_SETFOCUS ; control has received the input focus
_DebugPrint("$NM_SETFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; No return value
Case $TVN_BEGINDRAGA, $TVN_BEGINDRAGW
_DebugPrint("$TVN_BEGINDRAG")
Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
_DebugPrint("$TVN_BEGINLABELEDIT")
Case $TVN_BEGINRDRAGA, $TVN_BEGINRDRAGW
_DebugPrint("$TVN_BEGINRDRAG")
Case $TVN_DELETEITEMA, $TVN_DELETEITEMW
_DebugPrint("$TVN_DELETEITEM")
Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
_DebugPrint("$TVN_ENDLABELEDIT")
Case $TVN_GETDISPINFOA, $TVN_GETDISPINFOW
_DebugPrint("$TVN_GETDISPINFO")
Case $TVN_GETINFOTIPA, $TVN_GETINFOTIPW
_DebugPrint("$TVN_GETINFOTIP")
Case $TVN_ITEMEXPANDEDA, $TVN_ITEMEXPANDEDW
_DebugPrint("$TVN_ITEMEXPANDED")
Case $TVN_ITEMEXPANDINGA, $TVN_ITEMEXPANDINGW
_DebugPrint("$TVN_ITEMEXPANDING")
Case $TVN_KEYDOWN
_DebugPrint("$TVN_KEYDOWN")
Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
_DebugPrint("$TVN_SELCHANGED")
Case $TVN_SELCHANGINGA, $TVN_SELCHANGINGW
_DebugPrint("$TVN_SELCHANGING")
Case $TVN_SETDISPINFOA, $TVN_SETDISPINFOW
_DebugPrint("$TVN_SETDISPINFO")
Case $TVN_SINGLEEXPAND
_DebugPrint("$TVN_SINGLEEXPAND")
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @CRLF & _
"+======================================================" & @CRLF & _
"-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint