Page 1 of 1

Balloon tooltip ?

Posted: Sun Feb 13, 2011 6:52 pm
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

Re: Balloon tooltip ?

Posted: Sun Feb 13, 2011 7:00 pm
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


Re: Balloon tooltip ?

Posted: Sun Feb 13, 2011 8:24 pm
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?

Re: Balloon tooltip ?

Posted: Sun Feb 13, 2011 8:26 pm
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.

Re: Balloon tooltip ?

Posted: Mon Feb 14, 2011 12:23 pm
by Alireza
I'm interesting too!
can u add a option as it's show after specific time? eg after 5sec

Re: Balloon tooltip ?

Posted: Mon Feb 14, 2011 4:26 pm
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

Re: Balloon tooltip ?

Posted: Mon Feb 14, 2011 7:01 pm
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:

Re: Balloon tooltip ?

Posted: Mon Feb 14, 2011 10:54 pm
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


Re: Balloon tooltip ?

Posted: Tue Feb 15, 2011 1:18 am
by charvista
:P
RASHAD, you are my Hero!!! Many Thanks!!! :P
:P

Re: Balloon tooltip ?

Posted: Fri Feb 18, 2011 5:21 am
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

Re: Balloon tooltip ?

Posted: Fri Feb 18, 2011 9:05 am
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