Formatting a balloon tooltip properly

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4792
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Formatting a balloon tooltip properly

Post by Fangbeast »

I use the below code to create balloon tooltips, works fine. But I also want to create formatted text but the code doesn't use a font that I can do this with (May be O/S dependant?). I can't use spaces to pad each line out to the correct length because of the font it uses.

Is there a possibility to change the font used by this code so that I can 'line' things up?

Currently, I get:

Title: Harry gets a dog
Format: paperback
Pages: 34

Code: Select all

  ToolTipControl = CreateWindowEx_(0, "ToolTips_Class32", "", #WS_POPUP | #TTS_NOPREFIX | #TTS_BALLOON, 0, 0, 0, 0, WindowID(btWindow), 0, GetModuleHandle_(0), 0)

  SetWindowPos_(ToolTipControl, #HWND_TOPMOST, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE)

  SendMessage_(ToolTipControl,  #TTM_SETTIPTEXTCOLOR, 0, 0)
  SendMessage_(ToolTipControl,  #TTM_SETTIPBKCOLOR, $F58C0A, 0)
  SendMessage_(ToolTipControl,  #TTM_SETMAXTIPWIDTH, 0, 290)

  Button.TOOLINFO\cbSize  = SizeOf(TOOLINFO)
  Button\uFlags           = #TTF_IDISHWND | #TTF_SUBCLASS
  Button\hwnd             = WindowID(btWindow)
  Button\uID              = GadgetID(btGadget)
  Button\hInst            = 0
  Button\lpszText         = @btText

  SendMessage_(ToolTipControl, #TTM_ADDTOOL, 0, Button)
  SendMessage_(ToolTipControl, #TTM_UPDATE, 0, 0)

Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Formatting a balloon tooltip properly

Post by RASHAD »

Fangbeast Hi and Happy New Year
The next snippet by 'Andreas' (I think)

Code: Select all

Global hTooltip.l 

#TTS_BUBBLE = $40

Global Dim Tool.TOOLINFO(0) 
Procedure AddTip(Handle,Text.s) 
Tool(0)\cbSize = SizeOf(TOOLINFO) 
Tool(0)\uFlags = #TTF_SUBCLASS|#TTF_IDISHWND 
Tool(0)\hwnd = Handle 
Tool(0)\uId = Handle 
Tool(0)\hInst = GetModuleHandle_(0) 
Tool(0)\lpszText = @Text 
SendMessage_(hTooltip,#TTM_ADDTOOL,0,@Tool(0)); 
EndProcedure 


If OpenWindow(0, 100, 200, 195, 260, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget) 

hTooltip = CreateWindowEx_(#WS_EX_TOPMOST, "tooltips_class32", 0,#TTS_ALWAYSTIP|#TTS_NOPREFIX|#WS_POPUP|#TTS_BUBBLE,#CW_USEDEFAULT,#CW_USEDEFAULT, #CW_USEDEFAULT,#CW_USEDEFAULT,WindowID(0), 0, GetModuleHandle_(0), 0); 
SetWindowTheme_(hTooltip, @null.w, @null.w)

SendMessage_(hTooltip,#TTM_SETDELAYTIME,#TTDT_INITIAL,0) 

SendMessage_(hTooltip,#TTM_SETTIPTEXTCOLOR,$0002FF,0)                  ;TextColor Tooltip 
SendMessage_(hTooltip,#TTM_SETTIPBKCOLOR,$D1FFFF,0)                    ;BackColor Tooltip 

SendMessage_(hTooltip,#TTM_SETMAXTIPWIDTH,0,160)                       ;Max tip width

r.RECT 
SetRect_(r,10,10,10,10)                                                ;Tip Margins
SendMessage_(hTooltip,#TTM_SETMARGIN,0,r)

SendMessage_(hTooltip,#TTM_ACTIVATE,#False,0)                          ;DeActivate

SendMessage_(hTooltip,#TTM_ACTIVATE,#True,0)                           ;Activate

LoadFont(0, "Tahoma",10,#PB_Font_HighQuality) 
SendMessage_(hTooltip,#WM_SETFONT,FontID(0),0) 

ButtonGadget(0, 10,10,80,24,"OK") 
AddTip(GadgetID(0),"Title: Harry gets a dog Format: paperback     Pages: 34") 


Repeat 
    EventID.l = WaitWindowEvent() 
    If EventID = #PB_Event_CloseWindow 
      FreeFont(0) 
      Quit = 1 
    EndIf 
  Until Quit = 1 
EndIf 
End

Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4792
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Formatting a balloon tooltip properly

Post by Fangbeast »

Rashad, I didn't explain it properly...

Let's say I break these lines up a little to illustrate it: (Mind you, the forum font has the same problem as the balloon tooltips, the font is proportional and so things don't line up)

The balloon format handles CRLF properly so I can add them.

"Title: Harry gets a dog" + Chr(13) + Chr(10) +
"Format: paperback." + Chr(13) + Chr(10) +
"Pages: 34"

On my monitor with a standard font, "Harry", "paperback" and "34" will line up exactly under each other with the title fields under each other padded out with the correct number of spaces (The forum post won't show this of course).

I want to be able to change the balloon tooltip font to non proportional so that i can line up the fields and text neatly.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Formatting a balloon tooltip properly

Post by RASHAD »

Fangles you can change the font so easily

Code: Select all

Procedure AddTip(Handle,Text.s)
SendMessage_(hTooltip,#WM_SETFONT,LoadFont(0,"Tahoma",14),#True)  ;*******
Tool(0)\cbSize = SizeOf(TOOLINFO) 
Tool(0)\uFlags = #TTF_SUBCLASS|#TTF_IDISHWND 
Tool(0)\hwnd = Handle 
Tool(0)\uId = Handle 
Tool(0)\hInst = GetModuleHandle_(0) 
Tool(0)\lpszText = @Text 
SendMessage_(hTooltip,#TTM_ADDTOOL,0,@Tool(0)); 
EndProcedure 
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4792
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Formatting a balloon tooltip properly

Post by Fangbeast »

RASHAD wrote:Fangles you can change the font so easily

Code: Select all

Procedure AddTip(Handle,Text.s)
SendMessage_(hTooltip,#WM_SETFONT,LoadFont(0,"Tahoma",14),#True)  ;*******
Tool(0)\cbSize = SizeOf(TOOLINFO) 
Tool(0)\uFlags = #TTF_SUBCLASS|#TTF_IDISHWND 
Tool(0)\hwnd = Handle 
Tool(0)\uId = Handle 
Tool(0)\hInst = GetModuleHandle_(0) 
Tool(0)\lpszText = @Text 
SendMessage_(hTooltip,#TTM_ADDTOOL,0,@Tool(0)); 
EndProcedure 
Thanks Rashad, I didn't know that. Now to do some testing!! Woohoooo!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
hoangdiemtinh
User
User
Posts: 97
Joined: Wed Nov 16, 2022 1:51 pm

Re: Formatting a balloon tooltip properly

Post by hoangdiemtinh »

RASHAD wrote: Sun Jan 09, 2011 3:30 am Fangles you can change the font so easily

Code: Select all

Procedure AddTip(Handle,Text.s)
SendMessage_(hTooltip,#WM_SETFONT,LoadFont(0,"Tahoma",14),#True)  ;*******
Tool(0)\cbSize = SizeOf(TOOLINFO) 
Tool(0)\uFlags = #TTF_SUBCLASS|#TTF_IDISHWND 
Tool(0)\hwnd = Handle 
Tool(0)\uId = Handle 
Tool(0)\hInst = GetModuleHandle_(0) 
Tool(0)\lpszText = @Text 
SendMessage_(hTooltip,#TTM_ADDTOOL,0,@Tool(0)); 
EndProcedure 
Thanks @RASHAD for sharing.

Why when I add a ToolTip as above and change the language for the Window (the languages ​​are added to 1 combobox), then I see the ToolTip displayed on top of each other?

(The window has 1 parent window, and 3 child window).

How to clear the memory of the previous Tooltip?
PC: Windows 10 x64, 8GB RAM. PB ver: 6.x
--
I love PB5 vs PB6 :)
Post Reply