Page 1 of 1
Re: GadgetToolTip usable with multiple lines ?
Posted: Tue Oct 18, 2011 3:09 pm
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
Re: GadgetToolTip usable with multiple lines ?
Posted: Tue Oct 18, 2011 4:24 pm
by GG
Thanks netmaestro, that's perfect.

Re: GadgetToolTip usable with multiple lines ?
Posted: Tue Oct 18, 2011 4:37 pm
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
Re: GadgetToolTip usable with multiple lines ?
Posted: Tue Oct 18, 2011 5:06 pm
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")
Re: GadgetToolTip usable with multiple lines ?
Posted: Tue Oct 18, 2011 5:35 pm
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.

Re: GadgetToolTip usable with multiple lines ?
Posted: Tue Oct 18, 2011 5:42 pm
by WilliamL
I was suggesting using (for the linefeed)
but maybe it just doesn't work on your version.
Re: GadgetToolTip usable with multiple lines ?
Posted: Tue Oct 18, 2011 7:20 pm
by blueznl
Under Windows I think a CHR(10) is used for linefeeds, but I could be wrong

Re: GadgetToolTip usable with multiple lines ?
Posted: Wed Oct 19, 2011 9:01 am
by GG
Absolutely, but same result.
Both solutions (netmaestro and gnozal) are very interesting.
Re: GadgetToolTip usable with multiple lines ?
Posted: Wed Oct 19, 2011 10:43 am
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
Re: GadgetToolTip usable with multiple lines ?
Posted: Wed Oct 19, 2011 11:44 am
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