Date: 02-16-2022
Return to Index
created by gbSnippets
'A tooltip control can be used instead of the built-in InfoTip feature of a ListView.delete
'Primary Code:
'Create the tooltip control and assign it to the ListView control
hToolTip = CreateWindowEx(ByVal 0, "tooltips_class32", "", %TTS_ALWAYSTIP, _
0, 0, 0, 0, ByVal hDlg, ByVal 0, GetModuleHandle(ByVal %NULL), ByVal 0)
SetToolTip(hListView, "My ListView")
'Respond to the TTN_GetDispInfo notification
Case %WM_Notify
Select Case Cb.NmCode
Case %TTN_GetDispInfo
Dialog Set Text hdlg, "GDI " + Time$
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "commctrl.inc"
#Resource "gbsnippets.pbr"
%IDC_ListView = 500
Global hDlg,hListView,hList,hTooltip As Dword, D() As AsciiZ * %Max_Path
Function PBMain() As Long
Dialog New Pixels, 0, "ListView Test",300,300,200,125,%WS_SysMenu, 0 To hDlg
CreateListView
hToolTip = CreateWindowEx(ByVal 0, "tooltips_class32", "", %TTS_ALWAYSTIP, _
0, 0, 0, 0, ByVal hDlg, ByVal 0, GetModuleHandle(ByVal %NULL), ByVal 0)
SetToolTip(hListView, "My ListView")
Dim D(-1 to 1) : D(-1) = "<none>" : D(0) = "zero" : D(1) = "one"
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local LVHT As LVHitTestInfo, temp$, DI As NMTTDISPINFO Ptr
Select Case Cb.Msg
Case %WM_Notify
Select Case Cb.NmCode
Case %TTN_GetDispInfo
'get item under cursor
GetCursorPos LVHT.pt
ScreenToClient hListView, LVHT.pt
Control Send hDlg, %IDC_ListView, %LVM_SubItemHitTest, 0, VarPtr(LVHT) 'item is LVHT.iItem
Dialog Set Text hdlg, Str$(LVHT.iItem) + " : " + D(LVHT.iItem)
'set tooltip
DI = Cb.LParam
@DI.@lpszText = D(LVHT.iItem)
End Select
End Select
End Function
Sub CreateListview
Control Add ListView, hDlg, %IDC_ListView, "", 10,10,180,100, %WS_Visible Or %LVS_Icon
Control Handle hDlg, %IDC_ListView To hListView
ImageList New Icon 32,32,24,3 To hList
ImageList Add Icon hList, "x" 'image 1
ImageList Add Icon hList, "y" 'image 2
ListView Set ImageList hDlg, %IDC_ListView, hList, %lvsil_normal 'normal (large) imagelist for LVS_Icon mode
ListView Insert Column hDlg, %IDC_ListView, 1, "test1", 75, 0
ListView Insert Item hDlg, %IDC_ListView, 1, 1, "" 'row,image,text
ListView Insert Item hDlg, %IDC_ListView, 2, 2, "" 'row,image,text
End Sub
Sub SetToolTip(hControl As Dword, TipText As Asciiz*256)
Local TI As TOOLINFO
TI.cbSize = SizeOf(TI)
TI.uFlags = %TTF_SUBCLASS Or %TTF_IDISHWND
TI.hWnd = GetParent(hToolTip)
TI.uId = hControl
TI.lpszText = %LPSTR_TextCallBack 'VarPtr(TipText)
SendMessage hToolTip, %TTM_ADDTOOL, 0, VarPTR(ti)
End Sub
'gbs_00992
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm