Colored Balloon Tooltips with icons
Posted: Sat Jan 21, 2006 3:11 pm
Code updated for 5.20+
This is a procedure to add 'cartoon style' colored balloon (or ordinary) tooltips to gadgets. You can also specify an icon for it, and a title if you like.
Hope it can be of use to someone else too.
I have a question though. When XP skin support is selected in compiler options, the tooltips doesn't
reappear if you allow them to timeout. Does anyone know how to prevent this ?
This is a procedure to add 'cartoon style' colored balloon (or ordinary) tooltips to gadgets. You can also specify an icon for it, and a title if you like.
Hope it can be of use to someone else too.

reappear if you allow them to timeout. Does anyone know how to prevent this ?
Code: Select all
;-Gadget Id's
;
Enumeration
#Win
#Btn1
#Btn2
#Btn3
#Btn4
EndEnumeration
;-Declares
;
Declare ToolTip(Win, Id, Style, Center, Icon, FgColor, BgColor, Title.s, Tip.s)
Declare OpenMainWindow()
;-StartRun
;
OpenMainWindow()
;-Events
;
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
;-EndRun
;
End
;-Procedures
;
Procedure ToolTip(Win, Id, Style, Center, Icon , FgColor, BgColor, Title.s, Tip.s)
;Adds a tooltip to Id. Style: 0 = ordinary, 1 = balloon. Center: 1 = center the stem
;Icon: 0 = No icon, 1 = Info, 2 = Warn, 3 = Error, (See #TOOLTIP_ constants)
TT = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_BALLOON * Style, 0, 0, 0, 0, 0, 0, 0, 0)
;Color. RGB() or GetSysColor_(See #COLOR_ constants)
If FgColor
;Set the tip text color, also the tip outline color for balloon tooltips
SendMessage_(TT, #TTM_SETTIPTEXTCOLOR, FgColor, 0)
EndIf
If BgColor
;Set the tip background color
SendMessage_(TT, #TTM_SETTIPBKCOLOR, BgColor, 0)
EndIf
TI.TOOLINFO\cbSize = SizeOf(TOOLINFO)
TI\uFlags = #TTF_IDISHWND | #TTF_SUBCLASS | (#TTF_CENTERTIP * Center)
TI\hWnd = WindowID(Win)
TI\uId = GadgetID(Id)
TI\lpszText = @Tip
;Register tooltip with the control
SendMessage_(TT, #TTM_ADDTOOL, 0, TI)
;Set as a multiline tooltip with wordwrap
SendMessage_(TT, #TTM_SETMAXTIPWIDTH, 0, 150)
;Set the icon style and tip title
SendMessage_(TT, #TTM_SETTITLE, Icon, Title)
EndProcedure
Procedure OpenMainWindow()
If OpenWindow(0, 0, 0, 300, 300, "Tooltip Styles", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ButtonGadget(#Btn1, 110, 40, 80, 20, "Button1")
ToolTip(#Win, #Btn1, 0, 0, 1, 0, 0, "", "This is a boring old Tooltip")
ButtonGadget(#Btn2, 110,100, 80, 20, "Button2")
ToolTip(#Win, #Btn2, 0, 1, 1, 0, RGB(226, 255, 255), "Title", "Not that boring old Tooltip")
ButtonGadget(#Btn3, 110, 160, 80, 20, "Button3")
ToolTip(#Win, #Btn3, 1, 0, 0, 0, RGB(226, 255, 255), "", "This is a multi line Tooltip This is a multi line Tooltip")
ButtonGadget(#Btn4, 110, 220, 80, 20, "Button4")
ToolTip(#Win, #Btn4, 1, 1, 1, RGB(57, 120, 63), RGB(226, 255, 255), "This is:", "A centered Tooltip")
Else
End
EndIf
EndProcedure