GadgetToolTip usable with multiple lines ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: GadgetToolTip usable with multiple lines ?

Post by netmaestro »

You can easily cause the tooltip to wordwrap by sending the #TTM_SETMAXTIPWIDTH message. However, in order to do that you need to get the handle of the tooltip Purebasic created for you:

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$)
  Shared _Hook, TT_HWND
  _Hook = SetWindowsHookEx_(#WH_CBT, @TT_CBTHookProc(), #Null, GetCurrentThreadId_()) 
  GadgetToolTip(gadget_number, tooltip_text$)
  UnhookWindowsHookEx_(_Hook)
  ProcedureReturn TT_HWND
EndProcedure

OpenWindow(0,0,0,320,240,"")
StringGadget(1,20,40,200,20,"stuff")
ttid = GadgetToolTipEx(1, "This is a tooltip        with multiple lines  ")
SendMessage_(ttid, #TTM_SETMAXTIPWIDTH, 0, 100)
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
BERESHEIT
User avatar
GG
Enthusiast
Enthusiast
Posts: 266
Joined: Tue Jul 26, 2005 12:02 pm
Location: Lieusaint (77), France

Re: GadgetToolTip usable with multiple lines ?

Post by GG »

Thanks netmaestro, that's perfect. :)
Last edited by GG on Tue Oct 18, 2011 4:47 pm, edited 1 time in total.
Purebasic 6.12 64 bits - Windows 11 Pro 64 bits 23H2
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: GadgetToolTip usable with multiple lines ?

Post by gnozal »

Also possible :

Code: Select all

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 ToolTipID() 
  Protected *PB_Globals.PB_Globals 
  *PB_Globals = PB_Object_GetThreadMemory(PB_Gadget_Globals) 
  ProcedureReturn *PB_Globals\ToolTipWindow 
EndProcedure

OpenWindow(0,0,0,320,240,"")
StringGadget(1,20,40,200,20,"stuff")
GadgetToolTip(1, "This is a tooltip        with multiple lines  ")
ttid = ToolTipID()
SendMessage_(ttid, #TTM_SETMAXTIPWIDTH, 0, 100)
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: GadgetToolTip usable with multiple lines ?

Post by WilliamL »

Code: Select all

GadgetToolTip(x,"Why are multiple"+#CR$+"lines NOT possible???")
Works for me! (on Mac) Maybe you need a line feed?

Code: Select all

GadgetToolTip(gethefid(MFile,47),"Month spent/"+Chr(13)+"Posted balance/"+Chr(13)+"Total balance")
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
User avatar
GG
Enthusiast
Enthusiast
Posts: 266
Joined: Tue Jul 26, 2005 12:02 pm
Location: Lieusaint (77), France

Re: GadgetToolTip usable with multiple lines ?

Post by GG »

Doesn't work for me under XP : chr(13) is considered as a blank square in the tooltip.
netmaesto and gnozal's snippets solve my problems. :)
Purebasic 6.12 64 bits - Windows 11 Pro 64 bits 23H2
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: GadgetToolTip usable with multiple lines ?

Post by WilliamL »

I was suggesting using (for the linefeed)

Code: Select all

#CRLF$
but maybe it just doesn't work on your version.
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: GadgetToolTip usable with multiple lines ?

Post by blueznl »

Under Windows I think a CHR(10) is used for linefeeds, but I could be wrong :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
GG
Enthusiast
Enthusiast
Posts: 266
Joined: Tue Jul 26, 2005 12:02 pm
Location: Lieusaint (77), France

Re: GadgetToolTip usable with multiple lines ?

Post by GG »

Absolutely, but same result. :(
Both solutions (netmaestro and gnozal) are very interesting.
Purebasic 6.12 64 bits - Windows 11 Pro 64 bits 23H2
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: GadgetToolTip usable with multiple lines ?

Post by Shardik »

For a Windows solution using #CR$ as a ToolTip linefeed take a look into
a previous code example from me that utilizes netmaestro's ToolTipID()
code:
http://www.purebasic.fr/english/viewtop ... 0&start=11
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: GadgetToolTip usable with multiple lines ?

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 "+#CR$+"Button And Now With More Lines for GG")
  ttip = ToolTipHandle()
 
  SetWindowLongPtr_(ttip, #GWL_STYLE, GetWindowLongPtr_(ttip, #GWL_STYLE) | #TTS_ALWAYSTIP| #TTS_NOPREFIX| #WS_POPUP| #TTS_BALLOON)    ;#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",10,#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
Post Reply