#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
$hForm=guicreate("treeview",200,200)
$hTree=guictrlcreatetreeview(0,0,150,200)
$hChina=guictrlcreatetreeviewitem("中国",$hTree)
guictrlcreatetreeviewitem("北京",$hChina)
guictrlcreatetreeviewitem("广东",$hChina)
guictrlcreatetreeviewitem("四川",$hChina)
$hUSA=guictrlcreatetreeviewitem("美国",$hTree)
guictrlcreatetreeviewitem("纽约",$hUSA)
guictrlcreatetreeviewitem("华盛顿",$hUSA)
guictrlcreatetreeviewitem("洛杉矶",$hUSA)
$hBut=guictrlcreatebutton("获取",155,70,40,20)
guisetstate()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
while 1
Sleep(60000)
wend
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Dim $iIDFrom = BitAND($iwParam, 0xFFFF)
Dim $iCode = BitShift($iwParam, 16)
Switch $iwParam
Case $hBut
Switch $iCode
Case 0
_ShowMsg($hTree)
EndSwitch
EndSwitch
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case GUICtrlGetHandle($hTree)
Switch $iCode
Case $NM_CLICK
;单击消息
EndSwitch
EndSwitch
EndFunc
Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
$nID = BitAND($wParam, 0x0000FFFF)
Switch $nID
Case 61536
If $hWnd == $hForm Then
Exit
EndIf
EndSwitch
EndFunc ;==>WM_SYSCOMMAND
Func _ShowMsg($hWnd)
Dim $hItem, $hParent
$hItem = _GUICtrlTreeView_GetSelection($hWnd)
$hParent = _GUICtrlTreeView_GetParentHandle($hWnd, $hItem)
If $hParent == GUICtrlGetHandle($hChina) Then
ToolTip("中国")
ElseIf $hParent == GUICtrlGetHandle($hUSA) Then
ToolTip("美国")
Else
ToolTip("")
EndIf
EndFunc