Date: 02-16-2022
Return to Index
created by gbSnippets
'A Toolbar control used with style TBStyle_Tooltips provides a popup
'tooltip when the mouse hovers over a Toolbar button, and sends a WM_Notify
'message asking the user to supply the Tooltip text.
'Primary Code:
'Credit: Kev Peel
'There are two steps
'1. Add %TBStyle_Tooltips to the toolbar control style
Control Add Toolbar, hDlg, 500,"", 0,0,0,0, %TBStyle_Tooltips
'2. Add code to detect appropriate notification message
Case %WM_NOTIFY
If CB.Nmcode = %TTN_GetDispInfo Then
Local P as TOOLTIPTEXT Ptr
P = CB.lParam
Select Case CB.NmID 'or this: @P.hdr.idFrom
Case %ID_ToolbarButton1
@P.@lpszText = "x"
Case %ID_ToolbarButton2
@P.@lpszText = "y"
Case %ID_ToolbarButton3
@P.@lpszText = "z"
End Select
End If
'Compilable Example: (Jose Includes)
'The following compilable code demonstrates a Toolbar control that provides Tooltips
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "CommCtrl.inc"
#Resource "gbsnippets.pbr" 'misc icons
Global hDlg As Dword 'main dialog handle
Global hLst As Dword 'imagelist handke
Function PBMain()
'create dialog
Dialog New Pixels, 0, "Toolbar Test",,, 500,250, %WS_SysMenu, To hDlg
Dialog Set Color hDlg, %White, %White
Dialog Set Icon hDlg, "x"
'add toolbar
Control Add Toolbar, hDlg, 500,"", 0,0,0,0, %TBStyle_Tooltips
'create imagelist
ImageList New Icon 16,16,32,3 To hLst
ImageList Add Icon hLst, "x" '1
ImageList Add Icon hLst, "y" '2
ImageList Add Icon hLst, "z" '3
'attach imagelist
Toolbar Set ImageList hDlg, 500, hLst, 0
'create buttons
Toolbar Add Button hDlg, 500, 1, 200, %TbStyle_Button, "x"
Toolbar Add Button hDlg, 500, 2, 201, %TbStyle_Button, "y
Toolbar Add Button hDlg, 500, 3, 202, %TbStyle_Button, "z"
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Command
If CB.Ctl = 200 Then MsgBox "Pushed X!"
If CB.Ctl = 201 Then MsgBox "Pushed Y!"
If CB.Ctl = 202 Then MsgBox "Pushed Z!"
Case %WM_NOTIFY
If CB.Nmcode = %TTN_GetDispInfo Then
Local P as TOOLTIPTEXT Ptr
P = CB.lParam
Select Case CB.NmID 'or this: @P.hdr.idFrom
Case 200 : @P.@lpszText = "x"
Case 201 : @P.@lpszText = "y"
Case 202 : @P.@lpszText = "z"
End Select
End If
End Select
End Function
'gbs_00291
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm