eltorro Posted June 11, 2006 Share Posted June 11, 2006 (edited) Without further ado. Here is an example of using Tv item bounding rectangles to display custom tooltips. This script does not suppress the tooltip generated by the treeview control itself (such as with long treeview text).expandcollapse popup;Tooltip on treeview items ;example of use for _GUICtrlTreeViewGetItemRect ;Other uses include context menus, and editing items. ;eltorro <steve@ocotillo.sytes.net> #include <GUIConstants.au3> ;#include "_GUICtrlTreeViewGetItemRect.au3" ;http://www.autoitscript.com/forum/index.php?showtopic=27463 Local $TvItems[7][2] ; $TvItems[x][0]= ctrl id, $TvItems[x][1]= tooltip. Local $tip_old = "" Local $Timer Const $TIM_DIFF = 3000 ;3 seconds tooltip display time GUICreate("Treeview Item Tooltips", 350, 240, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_CLIPSIBLINGS)) $treeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) $TvItems[0][0] = GUICtrlCreateTreeViewItem("General", $treeview) $TvItems[0][1] = "This is the 'General' item" $TvItems[1][0] = GUICtrlCreateTreeViewItem("Display", $treeview) $TvItems[1][1] = "This is the 'Display' item" $TvItems[2][0] = GUICtrlCreateTreeViewItem("About", $TvItems[0][0]) $TvItems[2][1] = "This is the 'About' item" $TvItems[3][0] = GUICtrlCreateTreeViewItem("Computer", $TvItems[0][0]) $TvItems[3][1] = "This is the 'Computer' item" $TvItems[4][0] = GUICtrlCreateTreeViewItem("User", $TvItems[0][0]) $TvItems[4][1] = "This is the 'User' item" $TvItems[5][0] = GUICtrlCreateTreeViewItem("This is a very long text line", $TvItems[1][0]) $TvItems[5][1] = "This is the 'This is a very long text line' item" $TvItems[6][0] = GUICtrlCreateTreeViewItem("Other", $TvItems[1][0]) $TvItems[6][1] = "This is the 'Other' item" $startlabel = GUICtrlCreateLabel("TreeView Demo", 190, 90, 100, 20) $rectInfo = GUICtrlCreateLabel("", 0, 215, 350, 25, $SS_SUNKEN) $aboutbutton = GUICtrlCreateButton("About", 100, 185, 70, 20) $exitbutton = GUICtrlCreateButton("Exit", 180, 185, 70, 20) GUISetState() While 1 $msg = GUIGetMsg() _GuiTreeViewItemToolTip($treeview, $TvItems) If TimerDiff($Timer) > $TIM_DIFF Then ToolTip("") Select Case $msg = $exitbutton Or $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $aboutbutton MsgBox(4096, "About", "Tooltip on treeview items" & @LF _ & "Usage example for _GUICtrlTreeViewGetItemRect" & @LF _ & "Other uses include context menus, and editing items.") Case Else ; EndSelect WEnd GUIDelete() Exit ;=============================================================================== ; ; Description: _GUICtrlTreeViewItemToolTip ; Parameter(s): $i_treeview - controlID ; $ah_item - array of item ID/handles to get the bounding rect of ; ; Requirement: Beta, _GUICtrlTreeViewGetItemRect ; Return Value(s): ; User CallTip: ; Author(s): eltorro <steve@ocotillo.sytes.net> ; Note(s): custom tooltip for a treeview item ; ;=============================================================================== Func _GuiTreeViewItemToolTip($id_tree, $aTv_Items) If Not IsArray($aTv_Items) Then SetError(1) Return 0 EndIf Local $guiInfo, $rect, $x, $tip_new $guiInfo = GUIGetCursorInfo() If $guiInfo[4] = $id_tree Then For $x = 0 To UBound($aTv_Items, 1) - 1 $rect = _GuiCtrlTreeViewGetItemRect($id_tree, $aTv_Items[$x][0], 1) ;if rect is 0 then item not visible, or non existent so... skip it If $rect <> 0 Then If $guiInfo[0] > $rect[0]And $guiInfo[0] < $rect[2]Then If $guiInfo[1] > $rect[1]And $guiInfo[1] < $rect[3]Then GUICtrlSetData($rectInfo, "Treeview Item " & $x) If $tip_old <> $aTv_Items[$x][1]Then $tip_new = $aTv_Items[$x][1] ToolTip("") ToolTip($tip_new) $tip_old = $tip_new $Timer = TimerInit() EndIf EndIf EndIf EndIf Next If TimerDiff($Timer) > $TIM_DIFF Then ToolTip("") Else ToolTip("") EndIf EndFunc ;==>_GuiTreeViewItemToolTipThis script requires beta and _GuiCtrlTreeViewGetItemRect _GUICtrlTreeViewGetItemRect can be used to display context menus, edit boxes, list/combo boxes on treeview items too.eltorroEdit1: spelling Edited June 11, 2006 by eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
gamepin126 Posted June 11, 2006 Share Posted June 11, 2006 Awesome, I have so many things that could use this. Btw, adieu* Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now