Balloontips with icons & titles

Share your advanced PureBasic knowledge/code with the community.
Balatro
User
User
Posts: 15
Joined: Sun Oct 05, 2003 2:27 pm

Balloontips with icons & titles

Post by Balatro »

Hi, my first post here! I haven't seen the code for doing neat balloon-style tooltips with icons & titles here before so I thought I'd post this. Can't remember who posted the original code for doing regular balloontips, but many thanks to him anyway.

Code: Select all

Procedure AddToolTip(Handle, Text$, Icon, Title$)

    ToolTipControl = CreateWindowEx_(0, "tooltips_class32", "", $D0000000 | #TTS_BALLOON, 0, 0, 0, 0, WindowID(), 0, GetModuleHandle_(0), 0)

    SendMessage_(ToolTipControl, 1048, 0, 200)                                      ; *** Size control

    SendMessage_(ToolTipControl, $413, GetSysColor_(#COLOR_INFOBK), 0)              ; *** Color control
    SendMessage_(ToolTipControl, $414, GetSysColor_(#COLOR_INFOTEXT), 0)            ; *** Color control
    ; *** You could also use something like #COLOR_WINDOW and #COLOR_WINDOWTEXT, or omit these two above lines for default tooltip colors

    LoadFont(1, "Tahoma", 8) : UseFont(1)
    SendMessage_(ToolTipControl, #WM_SETFONT, FontID(), #TRUE)                      ; *** Font control
    ; *** You can omit these lines for the default tooltip font

    Temporary.ToolInfo\cbSize   = 44
    Temporary\uFlags            = #TTF_SUBCLASS | #TTF_IDISHWND
    Temporary\hWnd              = Handle
    Temporary\uId               = Handle
    Temporary\lpszText          = @Text$

    ; TTI_NONE    = 0 (no icon)
    ; TTI_INFO    = 1 (information icon)
    ; TTI_WARNING = 2 (warning icon)
    ; TTI_ERROR   = 3 (error icon)

    SendMessage_(ToolTipControl, #TTM_SETTITLE, Icon, Title$) ; *** Adds icon and title in bold

    SendMessage_(ToolTipControl, #TTM_ADDTOOL, 0, Temporary)

EndProcedure
Have fun.

~ B
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

The PureBasic Visual Designer and Purevision generate this code also.
It's posted a couple of times already i think.

Code: Select all

; PureBasic Visual Designer v3.80 build 1284


;- Window Constants
;
Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Button_0
EndEnumeration


; BalloonTip Constants
#TOOLTIP_NO_ICON      = 0
#TOOLTIP_INFO_ICON    = 1
#TOOLTIP_WARNING_ICON = 2
#TOOLTIP_ERROR_ICON   = 3

Procedure BalloonTip(WindowID, Gadget, Text$ , Title$, Icon)
  
  ToolTip=CreateWindowEx_(0,"ToolTips_Class32","",#WS_POPUP | #TTS_NOPREFIX | #TTS_BALLOON,0,0,0,0,WindowID(WindowID),0,GetModuleHandle_(0),0)
  SendMessage_(ToolTip,#TTM_SETTIPTEXTCOLOR,GetSysColor_(#COLOR_INFOTEXT),0)
  SendMessage_(ToolTip,#TTM_SETTIPBKCOLOR,GetSysColor_(#COLOR_INFOBK),0)
  SendMessage_(ToolTip,#TTM_SETMAXTIPWIDTH,0,180)
  Balloon.TOOLINFO\cbSize=SizeOf(TOOLINFO)
  Balloon\uFlags=#TTF_IDISHWND | #TTF_SUBCLASS
  Balloon\hWnd=GadgetID(Gadget)
  Balloon\uId=GadgetID(Gadget)
  Balloon\lpszText=@Text$
  SendMessage_(ToolTip, #TTM_ADDTOOL, 0, Balloon)
  If Title$ > ""
    SendMessage_(ToolTip, #TTM_SETTITLE, Icon, @Title$)
  EndIf
  
EndProcedure

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 216, 0, 600, 300,  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "New window ( 0 )")
    If CreateGadgetList(WindowID())
      ButtonGadget(#Button_0, 48, 64, 136, 40, "Ok")
      BalloonTip(WindowID(), #Button_0, "Tooltip", "Balloon title", #TOOLTIP_ERROR_ICON)
      
    EndIf
  EndIf
EndProcedure
Open_Window_0()

Repeat
  
  Event = WaitWindowEvent()
  
  If Event = #PB_EventGadget
    
    ;Debug "WindowID: " + Str(EventWindowID())
    
    GadgetID = EventGadgetID()
    
    If GadgetID = #Button_0
      Debug "GadgetID: #Button_0"
      
    EndIf
    
  EndIf
  
Until Event = #PB_EventCloseWindow

End
;
Balatro
User
User
Posts: 15
Joined: Sun Oct 05, 2003 2:27 pm

Post by Balatro »

Berikco wrote:The PureBasic Visual Designer and Purevision generate this code also.
It's posted a couple of times already i think.
Well, I don't use either of those so I didn't know that :) I guess learning the hard way isn't such a bad thing.

~ B
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

Balatro wrote:
Berikco wrote:The PureBasic Visual Designer and Purevision generate this code also.
It's posted a couple of times already i think.
Well, I don't use either of those so I didn't know that :) I guess learning the hard way isn't such a bad thing.

~ B
Very true, i learned also the heard way, it's more fun :)

btw, welcome to the forum Balatro :)
Post Reply