#Include <GUIConstantsEx.au3>
#Include <GUITreeView.au3>
#Include <Memory.au3>
#Include <WindowsConstants.au3>
#Include <WinAPI.au3>
Global Const $tagTIP = 'wchar Title[100];dword Icon;dword Options;dword Duration;'
Global $__Temp[9] = [0, 0]
$hGUI = GUICreate('MyGUI', 300, 200)
$TreeView = GUICtrlCreateTreeView(10, 10, 280, 180, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_INFOTIP))
$Item1 = GUICtrlCreateTreeViewItem('Item1', $TreeView)
$Item2 = GUICtrlCreateTreeViewItem('Item2', $TreeView)
$Item3 = GUICtrlCreateTreeViewItem('Item3', $TreeView)
_GUICtrlTreeView_SetItemToolTip($TreeView, $Item1, 'Text1', '', 0, 0, 2000)
_GUICtrlTreeView_SetItemToolTip($TreeView, $Item2, 'Text2', 'Title', 1, 1)
_GUICtrlTreeView_SetItemToolTip($TreeView, $Item3, 'Text3', 'Title', 3, 0, 2000)
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_GUICtrlTreeView_SetItemToolTip($TreeView, $Item1, '')
_GUICtrlTreeView_SetItemToolTip($TreeView, $Item2, '')
_GUICtrlTreeView_SetItemToolTip($TreeView, $Item3, '')
Func _GUICtrlTreeView_SetItemToolTip($hWnd, $hItem, $sText, $sTitle = '', $iIcon = 0, $iOptions = 0, $iDuration = 0)
Local $hMem, $pMem, $tTip, $iLenght
If Not IsHWnd($hWnd) Then
$hWnd = GUICtrlGetHandle($hWnd)
If Not $hWnd Then
Return SetError(1, 0, 0)
EndIf
EndIf
If Not IsHWnd($hItem) Then
$hItem = GUICtrlGetHandle($hItem)
If Not $hItem Then
Return SetError(1, 0, 0)
EndIf
EndIf
If Not StringStripWS($sText, 3) Then
$hMem = _GUICtrlTreeView_GetItemParam($hWnd, $hItem)
If $hMem Then
If Not _GUICtrlTreeView_SetItemParam($hWnd, $hItem, 0) then
Return SetError(1, 0, 0)
EndIf
_MemGlobalFree($hMem)
EndIf
Return 1
EndIf
$iLenght = StringLen($sText)
$tTip = DllStructCreate($tagTIP)
$hMem = _MemGlobalAlloc(DllStructGetSize($tTip) + 2 * ($iLenght + 1))
$pMem = _MemGlobalLock($hMem)
$tTip = DllStructCreate($tagTIP & 'wchar Text[' & ($iLenght + 1) & ']', $pMem)
DllStructSetData($tTip, 'Title', StringLeft($sTitle, 99))
DllStructSetData($tTip, 'Icon', $iIcon)
DllStructSetData($tTip, 'Options', $iOptions)
DllStructSetData($tTip, 'Duration', $iDuration)
DllStructSetData($tTip, 'Text', $sText)
_MemGlobalUnlock($hMem)
If Not _GUICtrlTreeView_SetItemParam($hWnd, $hItem, $hMem) Then
_MemGlobalFree($hMem)
Return SetError(1, 0, 0)
EndIf
Return 1
EndFunc
Func _TipHelper()
Local $tRect, $tPoint
If ($__Temp[8]) And (TimerDiff($__Temp[8]) > $__Temp[5]) Then
_TipRelease()
Return
EndIf
$tRect = _GUICtrlTreeView_DisplayRectEx($__Temp[0], $__Temp[1], 1)
$tPoint = _WinAPI_GetMousePos(1, $__Temp[0])
If _WinAPI_PtInRect($tRect, $tPoint) Then
If ($__Temp[7]) And (TimerDiff($__Temp[7]) > 800) Then
ToolTip($__Temp[6], MouseGetPos(0), MouseGetPos(1), $__Temp[2], $__Temp[3], $__Temp[4])
$__Temp[7] = 0
EndIf
Else
_TipRelease()
Return
EndIf
EndFunc
Func _TipRelease()
AdlibUnRegister('_TipHelper')
ToolTip('')
$__Temp[1] = 0
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local $tNMTVGETINFOTIP = DllStructCreate($tagNMTVGETINFOTIP, $lParam)
Local $hWndFrom = DllStructGetData($tNMTVGETINFOTIP, 'hWndFrom')
Local $hItem = DllStructGetData($tNMTVGETINFOTIP, 'hItem')
Local $iCode = DllStructGetData($tNMTVGETINFOTIP, 'Code')
Local $hTreeView = GUICtrlGetHandle($TreeView)
Local $hMem, $pMem, $tTip, $sTip
Switch $hWndFrom
Case $hTreeView
Switch $iCode
Case $TVN_GETINFOTIPW
If Not $__Temp[1] Then
$hMem = _GUICtrlTreeView_GetItemParam($hTreeView, $hItem)
If $hMem Then
$pMem = _MemGlobalLock($hMem)
If $pMem Then
_TipRelease()
$tTip = DllStructCreate($tagTIP)
$tTip = DllStructCreate($tagTIP & 'wchar[' & ((_MemGlobalSize($hMem) - DllStructGetSize($tTip)) / 2) & ']', $pMem)
$__Temp[0] = $hTreeView
$__Temp[1] = $hItem
For $i = 2 To 6
$__Temp[$i] = DllStructGetData($tTip, $i - 1)
Next
_MemGlobalUnlock($hMem)
$__Temp[7] = TimerInit()
If $__Temp[5] Then
$__Temp[8] = TimerInit()
Else
$__Temp[8] = 0
EndIf
AdLibRegister('_TipHelper', 5)
EndIf
EndIf
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc