I've found this code somewhere on the forum (and I slightly modified it e.g. to get the row under the mouse cursor):
Code: Select all
DisableExplicit
#MyWindow = 0
#MyGadget = 1
Import ""
PB_Object_GetThreadMemory(*mem)
PB_Gadget_Globals.i
EndImport
Procedure.s SetToolTipText(gadgetID, text.s)
Protected.i win_info
Protected ti.TOOLINFO
win_info = PB_Object_GetThreadMemory(PB_Gadget_Globals)
ti\cbSize = SizeOf(TOOLINFO)
ti\hWnd = GetParent_(GadgetID(gadgetID))
ti\uId = GadgetID(gadgetID)
ti\lpszText = @text
SendMessage_(PeekI(win_info + 24), #TTM_UPDATETIPTEXT, 0, @ti)
ProcedureReturn text
EndProcedure
If OpenWindow(#MyWindow, 100, 100, 500, 400, "ListIcon Example", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ListIconGadget(#MyGadget, 10, 10, 480, 360, "Name", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(#MyGadget, 1, "Address", 250)
AddGadgetItem(#MyGadget, -1, "Harry Rannit" + #LF$ + "12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(#MyGadget, -1, "Ginger Brokeit" + #LF$ + "130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(#MyGadget, -1, "Docter Sewdit" + #LF$ + "101 PureBasic Road, SameTown, CodeCity")
AddGadgetItem(#MyGadget, -1, "Harry Fainted" + #LF$ + "86 PureBasic Road, FuzzyTown, CodeCity")
GadgetToolTip(#MyGadget, "This is my tip")
Define pLVH.LVHITTESTINFO
Define pt.POINT
Define rc.RECT
lastRow = -1
Repeat
eventID = WindowEvent()
GetCursorPos_(pt)
GetWindowRect_(GadgetID(#MyGadget), rc)
If PtInRect_(rc, pt\x + (pt\y) << 32)
; Convert x and y from coordinate space to window-relative space
MapWindowPoints_(0, GadgetID(#MyGadget), pt, 1)
; Get row index of current cursor position
pLVH\pt\y = pt\y
SendMessage_(GadgetID(#MyGadget), #LVM_SUBITEMHITTEST, 0, pLVH)
cursorRow = pLVH\iItem
;Debug "Row under cursor: " + Str(cursorRow)
If lastRow <> cursorRow
If cursorRow <> -1 ; The last (empty) line has -1
s$ = GetGadgetItemText(#MyGadget, cursorRow, 1)
Else
s$ = ""
EndIf
SetToolTipText(#MyGadget, s$)
lastRow = cursorRow
EndIf
EndIf
Until eventID = #PB_Event_CloseWindow
EndIf
Import ""
...
EndImport
and rewrite the SetToolTipText() to not depend on using win_info and the PeekI() command(s)?
I know there are a few other implementation of showing a tooltip for each row in a list view on the forum
but I like this one because it does what I need with a minimum of code (compared to the other solutions)...