Balloon tooltip ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Balloon tooltip ?

Post by charvista »

Hello all,
Is there a way to make a balloon tooltip instead of a simple line?
And maybe even change colours, fonts, etc.
Thanks for any help!

Code: Select all

Win = OpenWindow(#PB_Any, 0, 0, 570, 200, "GadgetTooltip", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Btn = ButtonGadget(#PB_Any, 50, 30, 250, 30, "Button with Tooltip")
GadgetToolTip(Btn, "Tooltip for Button")
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Balloon tooltip ?

Post by netmaestro »

I guess you could do something like this:

Code: Select all

Procedure TT_CBTHookProc(nCode, wParam, lParam) 
  Shared _Hook, TT_HWND
  Select nCode 
    Case #HCBT_CREATEWND 
      *pcbt.CBT_CREATEWND = lParam 
      *pcs.CREATESTRUCT = *pcbt\lpcs 
      Select PeekS(*pcs\lpszClass)
        Case "tooltips_class32"
          TT_HWND = wParam
      EndSelect
  EndSelect
  ProcedureReturn CallNextHookEx_(_Hook, nCode, wParam, lParam) 
EndProcedure

Procedure GadgetToolTipEx(gadget_number, tooltip_text$)
  ; netmaestro 2009
  Shared _Hook, TT_HWND
  _Hook = SetWindowsHookEx_(#WH_CBT, @TT_CBTHookProc(), #Null, GetCurrentThreadId_()) 
  GadgetToolTip(gadget_number, tooltip_text$)
  UnhookWindowsHookEx_(_Hook)
  ProcedureReturn TT_HWND
EndProcedure

; Test

OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
StringGadget(1,20,40,200,20,"stuff")
ttid = GadgetToolTipEx(1, "This is a tooltip")
SetWindowLong_(ttid,#GWL_STYLE,GetWindowLong_(ttid,#GWL_STYLE) | #TTS_BALLOON &~ #WS_BORDER ) ; Will be a balloontip if we succeeded
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

BERESHEIT
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Balloon tooltip ?

Post by charvista »

@netmaestro
That's good! Thank you, it is working very well.
But... I hoped to get a more visible balloon (thus somewhat larger), and in yellow or red, depending of the circumstances (now it is gray, not very visible on a gray background).
And I would like to be using a specific font.
Is this possible?
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Balloon tooltip ?

Post by netmaestro »

Once you have the handle, you can go right to town on it. Just do some research on MSDN for the tooltip class. There are also several threads on these boards showing how to accomplish various effects with tooltips.
BERESHEIT
User avatar
Alireza
Enthusiast
Enthusiast
Posts: 143
Joined: Sat Aug 16, 2008 2:02 pm
Location: Iran

Re: Balloon tooltip ?

Post by Alireza »

I'm interesting too!
can u add a option as it's show after specific time? eg after 5sec
PB v 5.6 :D
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Balloon tooltip ?

Post by IdeasVacuum »

viewtopic.php?f=13&t=43709&sid=ed50b71a ... 89c7ea9e16

The code below may be helpful, it was crafted by the PB experts (i.e. not by me)

Balloon Tip at Gadget:

Code: Select all

Procedure BalloonTip(iWindowID.i, iGadget.i, sTip.s , sTitle.s, iIcon.i)
;-----------------------------------------------------------------------

    iToolTip = CreateWindowEx_(0,"ToolTips_Class32","",#WS_POPUP | #TTS_NOPREFIX | #TTS_BALLOON,0,0,0,0,iWindowID,0,GetModuleHandle_(0),0)

    SendMessage_(iToolTip,#TTM_SETDELAYTIME, #TTDT_AUTOPOP, 30000)
    SendMessage_(iToolTip,#TTM_SETTIPTEXTCOLOR,GetSysColor_(#COLOR_INFOTEXT),0)
    SendMessage_(iToolTip,#TTM_SETTIPBKCOLOR,GetSysColor_(#COLOR_INFOBK),0)
    SendMessage_(iToolTip,#TTM_SETMAXTIPWIDTH,0,280)

    Balloon.TOOLINFO\cbSize=SizeOf(TOOLINFO)
    Balloon\uFlags = #TTF_IDISHWND | #TTF_SUBCLASS
    Balloon\hwnd = GadgetID(iGadget)
    Balloon\uId = GadgetID(iGadget)
    Balloon\lpszText = @sTip

    SendMessage_(iToolTip, #TTM_ADDTOOL, 0, @Balloon)

    If (sTitle > "")

        SendMessage_(iToolTip, #TTM_SETTITLE, iIcon, @sTitle)

    EndIf

EndProcedure

BalloonTip(0, iGadget.i, sTip.s , sTitle.s, iIcon.i)
Balloon Tip at region:

Code: Select all

Global  TT

Procedure.l callback(hwnd, uMsg, wParam, lParam)
  Static text$
  Result = #PB_ProcessPureBasicEvents
  If uMsg = #WM_MOUSEMOVE
    msg.MSG
    msg\hwnd = hwnd
    msg\message = uMsg
    msg\wParam = wParam
    msg\lParam = lParam
    SendMessage_(TT, #TTM_RELAYEVENT, 0,msg)
  EndIf
  ProcedureReturn Result
EndProcedure

If OpenWindow(0, 0, 0, 300, 300, "Tooltips by area",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  TT = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP|#TTS_BALLOON, 0, 0, 0, 0, 0, 0, 0, 0)
  SendMessage_(TT, #TTM_SETTITLE, 1, "HiYa")
  SendMessage_(TT, #TTM_SETMAXTIPWIDTH, 0, 250)
  ;Add two 'tools' by area; one in the top left of the window and one in the bottom right.
    ti.TOOLINFO\cbSize = SizeOf(TOOLINFO)
    ti\uFlags = #TTF_CENTERTIP
    ti\hwnd = WindowID(0)
    ;Top left.
      ti\lpszText = @"Tool 0"
      SetRect_(@ti\rect, 0,0,20,20)
      ;Register tooltip with the control
        SendMessage_(TT, #TTM_ADDTOOL, 0, ti)
    ;Bottom right.
      ti\lpszText = @"Tool 1"
      ti\uId = 1
      SetRect_(@ti\rect, 280,280,300,300)
      ;Register tooltip with the control
        SendMessage_(TT, #TTM_ADDTOOL, 0, ti)
    ;A callback is needed
      SetWindowCallback(@callback())
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow

Endif
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Balloon tooltip ?

Post by charvista »

Many thanks, IdeaVacuum. This helps me a lot. Looks like it's written by srod. It is the type of balloon I was expecting (good looking). Now I have to make some research as netmaestro said, to find how to change the background colour... MSDN is not always easy to understand, and their examples are (pityfully) not in PB. Anyway I hope to find it. :wink:
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Balloon tooltip ?

Post by RASHAD »

Hi

Code: Select all

#TTS_BUBBLE = $40

Structure PB_Globals
  CurrentWindow.i
  FirstOptionGadget.i
  DefaultFont.i
  *PanelStack
  PanelStackIndex.l
  PanelStackSize.l
  ToolTipWindow.i
EndStructure

Import ""
  PB_Object_GetThreadMemory(*Mem)
  PB_Gadget_Globals
EndImport

Procedure ToolTipHandle() 
  Protected *PB_G.PB_Globals 
  *PB_G = PB_Object_GetThreadMemory(PB_Gadget_Globals) 
  ProcedureReturn *PB_G\ToolTipWindow 
EndProcedure

If OpenWindow(0, 0, 0, 270, 100, "GadgetTooltip", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(0, 10, 30, 250, 30, "Button with Tooltip")
  
  GadgetToolTip(0, "Tooltip for Button and Now with More Lines")
  ttip = ToolTipHandle()
 
  SetWindowLongPtr_(ttip, #GWL_STYLE, GetWindowLongPtr_(ttip, #GWL_STYLE) | #TTS_ALWAYSTIP| #TTS_NOPREFIX| #WS_POPUP| #TTS_BUBBLE)
  SetWindowTheme_(ttip, @null.w, @null.w)

  SendMessage_(ttip,#TTM_SETDELAYTIME,#TTDT_INITIAL,0)
  SendMessage_(ttip,#TTM_SETTIPTEXTCOLOR,$0002FF,0)                  ;TextColor Tooltip 
  SendMessage_(ttip,#TTM_SETTIPBKCOLOR,$D1FFFF,0)                    ;BackColor Tooltip
  SendMessage_(ttip,#TTM_SETMAXTIPWIDTH,0,100)                       ;Max tip width  
  ;SetRect_(r.RECT,5,5,5,5)                                          ;Tip Margins
  ;SendMessage_(ttip,#TTM_SETMARGIN,0,r)
  LoadFont(0, "Tahoma",14,#PB_Font_HighQuality) 
  SendMessage_(ttip,#WM_SETFONT,FontID(0),0)   
  ;SendMessage_(ttip,#TTM_ACTIVATE,#False,0)                          ;DeActivate  
  ;SendMessage_(ttip,#TTM_ACTIVATE,#True,0)                           ;Activate
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Egypt my love
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Balloon tooltip ?

Post by charvista »

:P
RASHAD, you are my Hero!!! Many Thanks!!! :P
:P
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Balloon tooltip ?

Post by IdeasVacuum »

Using 'the srod code' (not sure if it was srod, Rashad or a.n. other)

Code: Select all

#Window    = 0
#StringGgt = 1


Procedure BalloonTip(iWindowID.i, iGadget.i, sTip.s , sTitle.s, iIcon.i)
;-----------------------------------------------------------------------
    PaleGreen = RGB(195,255,195)
    DarkGreen = RGB(0,45,0)
     iToolTip = CreateWindowEx_(0,"ToolTips_Class32","",#WS_POPUP | #TTS_NOPREFIX | #TTS_BALLOON,0,0,0,0,iWindowID,0,GetModuleHandle_(0),0)

    SendMessage_(iToolTip,#TTM_SETDELAYTIME, #TTDT_AUTOPOP, 30000)
    ;SendMessage_(iToolTip,#TTM_SETTIPTEXTCOLOR,GetSysColor_(#COLOR_INFOTEXT),0)
    ;SendMessage_(iToolTip,#TTM_SETTIPBKCOLOR,GetSysColor_(#COLOR_INFOBK),0)
    SendMessage_(iToolTip,#TTM_SETMAXTIPWIDTH,0,280)
    SendMessage_(iToolTip,#TTM_SETTIPTEXTCOLOR,DarkGreen,0)     ;Text Colour
    SendMessage_(iToolTip,#TTM_SETTIPBKCOLOR,PaleGreen,0)       ;Back Colour
    
    Balloon.TOOLINFO\cbSize=SizeOf(TOOLINFO)
    Balloon\uFlags = #TTF_IDISHWND | #TTF_SUBCLASS
    Balloon\hwnd = GadgetID(iGadget)
    Balloon\uId = GadgetID(iGadget)
    Balloon\lpszText = @sTip

    SendMessage_(iToolTip, #TTM_ADDTOOL, 0, @Balloon)

    If (sTitle > "")

        SendMessage_(iToolTip, #TTM_SETTITLE, iIcon, @sTitle)

    EndIf

EndProcedure

;Test
If OpenWindow(#Window,0,0,400,300,"Test Balloons", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)

             StringGadget(#StringGgt, 100, 100, 200, 80, "")
               BalloonTip(#Window, #StringGgt, "Balloon Tip Text" , "", #MB_ICONQUESTION)

EndIf

Repeat 
      iEvent.i = WaitWindowEvent(1)

Until iEvent = #PB_Event_CloseWindow

End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Balloon tooltip ?

Post by RASHAD »

A little bit more

Code: Select all

Global Dim ToolTip(4)

FontID1 = LoadFont(1, "Arial", 10,#PB_Font_HighQuality)
FontID2 = LoadFont(2, "Broadway", 14,#PB_Font_HighQuality)

Procedure BalloonTip(Tooln,WindowID, Gadget,FontID,Title$,Text$, Icon)
  
  ToolTip(Tooln)=CreateWindowEx_(0,"ToolTips_Class32","",#WS_POPUP | #TTS_NOPREFIX | #TTS_BALLOON,0,0,0,0,WindowID,0,GetModuleHandle_(0),0)
  SetWindowTheme_(ToolTip(Tooln), @null.w, @null.w)
  SendMessage_(ToolTip(Tooln),#WM_SETFONT,FontID,0)
  SendMessage_(ToolTip(Tooln),#TTM_SETTIPTEXTCOLOR,$0202FD,0)
  SendMessage_(ToolTip(Tooln),#TTM_SETTIPBKCOLOR,$DCFFFF,0)
  Balloon.TOOLINFO\cbSize=SizeOf(TOOLINFO)
  Balloon\uFlags=#TTF_IDISHWND | #TTF_SUBCLASS
  Balloon\hWnd=GadgetID(Gadget)
  Balloon\uId=GadgetID(Gadget)
  Balloon\lpszText=@Text$
  SendMessage_(ToolTip(Tooln), #TTM_ADDTOOL, 0, Balloon)
  SendMessage_(ToolTip(Tooln), #TTM_SETTITLE, Icon, @Title$)
  
EndProcedure


OpenWindow(0, 235, 2, 400, 200, "ToolTip Test",  #PB_Window_SystemMenu | #PB_Window_TitleBar|#PB_Window_ScreenCentered )    
ButtonGadget(1, 10, 160, 80, 25, "TEST 1")
BalloonTip(1,GadgetID(1), 1,FontID1,"IdeasVacuum","This is a test for"+#CRLF$+"Multiline Balloon",#TOOLTIP_WARNING_ICON)

ButtonGadget(2, 100, 160, 80, 25, "TEST 2")
BalloonTip(2,GadgetID(2), 2,FontID2,"NEXT","OK",#TOOLTIP_ERROR_ICON)


Repeat
  
  Event = WaitWindowEvent()
  
Until Event = #PB_Event_CloseWindow

Egypt my love
Post Reply