Tooltip handle

Share your advanced PureBasic knowledge/code with the community.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Tooltip handle

Post by netmaestro »

You can create an API tooltip control and make it any way you want, but I thought it would be fun to make customized changes to native PB tooltips. To do this, you need the handle of the tooltip but GadgetToolTip() doesn't return that. I don't know what it is returning, but it isn't the handle. So I made a couple of solutions, pick whichever you like (if any :wink: )

ToolTipID version:

Code: Select all

Procedure EnumProc(hwnd, lparam)
  Shared ctrl
  cn$ = Space(100)
  GetClassName_(hwnd, @cn$, 99)
  If UCase(cn$) = "TOOLTIPS_CLASS32"
    With ti.TOOLINFO
      \cbSize = SizeOf(TOOLINFO)
      \hwnd = GetParent_(ctrl)
      \uid = ctrl
    EndWith
    If SendMessage_(hwnd, #TTM_GETTOOLINFO, 0, @ti)
      PokeI(lparam, hwnd)
      ProcedureReturn 0
    Else
      ProcedureReturn 1
    EndIf
  Else
    ProcedureReturn 1
  EndIf
EndProcedure

ProcedureDLL.i ToolTipID(gadget)
  Shared ctrl
  ctrl = gadget
  EnumWindows_(@EnumProc(),@TTID)
  ProcedureReturn TTID
EndProcedure

; test program
OpenWindow(0,0,0,320,240,"")
StringGadget(1,20,40,200,20,"stuff")
GadgetToolTip(1, "This is a tooltip")
ttid = ToolTipID(GadgetID(1))
SetWindowLong_(ttid,#GWL_STYLE,GetWindowLong_(ttid,#GWL_STYLE)|#TTS_BALLOON &~#WS_BORDER)
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
GadgetToolTipEx version:

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

; Test

OpenWindow(0,0,0,320,240,"")
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
Note that the border has to come off if you're changing to a balloon.
BERESHEIT
User avatar
Michael Vogel
Addict
Addict
Posts: 2680
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Thanks,

these functions should find a way to get into the next PB versions :!:

Michael
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

you can also add gadgets like an imagegadget to a tooltip for image preview purposes!!!


I have almost perfected this, and it works like a charm. No need to create additional popup windows with callbacks. Just use the existing tooltip and an an imagegadget to it and use the window properties of the htooltip to store the PB ID of the imagegadget and the displayed image. The OS ten manages its display, position ect.

As soon as I extract the source from the large program I am writing and get it working as a standalone, I will post an example.

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

here another version :wink:

Code: Select all

Structure GadgetGlobals
  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 *gg.GadgetGlobals  
  *gg = PB_Object_GetThreadMemory(PB_Gadget_Globals)  
  ProcedureReturn *gg\ToolTipWindow  
EndProcedure

; test program
OpenWindow(0,0,0,320,240,"")
StringGadget(1,20,40,200,20,"stuff")
GadgetToolTip(1, "This is a tooltip")
ttid = ToolTipID()
SetWindowLongPtr_(ttid,#GWL_STYLE,GetWindowLongPtr_(ttid,#GWL_STYLE)|#TTS_BALLOON &~#WS_BORDER)
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow 
for x86 and x64
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Andesdaf
User
User
Posts: 69
Joined: Sun Mar 22, 2009 2:53 pm
Location: GER, Saxony

Post by Andesdaf »

@netmaestro & ts-soft:
Thanks, i can just use it.
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Tooltip handle

Post by Little John »

This is exactly what I was looking for. Many thanks to you, netmaestro and ts-soft!
Many tips here on the forum about Tooltips are unnecessarily complicated.
And customizing several aspects of native PB tooltips is easy, once we have the handle.

I needed the handle for increasing the timeout. The default setting of 5 seconds often isn't enough, and it's annoying when a tooltip disappears while reading it.

Code: Select all

Macro SetTooltipTimeout (_hTooltip_, _msec_)
   ; -- Set timeout for all tooltips in the program
   ;    (GadgetToolTip() must have been called before at least once)
   ; in: _hTooltip_: Tooltip-ID (Handle)
   ;     _msec_    : Timeout in milliseconds (max. 32767)
   SendMessage_(_hTooltip_, #TTM_SETDELAYTIME, #TTDT_AUTOPOP, _msec_)
EndMacro
Michael Vogel wrote:these functions should find a way to get into the next PB versions :!:
Yes :!:

Regards, Little John
Post Reply