Page 1 of 1

Formatting a balloon tooltip properly

Posted: Sat Jan 08, 2011 7:44 am
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)


Re: Formatting a balloon tooltip properly

Posted: Sat Jan 08, 2011 5:20 pm
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


Re: Formatting a balloon tooltip properly

Posted: Sun Jan 09, 2011 12:04 am
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.

Re: Formatting a balloon tooltip properly

Posted: Sun Jan 09, 2011 3:30 am
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 

Re: Formatting a balloon tooltip properly

Posted: Sun Jan 09, 2011 3:36 am
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!

Re: Formatting a balloon tooltip properly

Posted: Thu Jun 06, 2024 4:02 pm
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?