Page 1 of 1

Tooltip handle

Posted: Tue Mar 17, 2009 3:53 am
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.

Posted: Tue Mar 17, 2009 8:53 am
by Michael Vogel
Thanks,

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

Michael

Posted: Tue Mar 17, 2009 3:05 pm
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.

Posted: Wed Mar 18, 2009 4:42 pm
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

Posted: Sun Mar 22, 2009 7:28 pm
by Andesdaf
@netmaestro & ts-soft:
Thanks, i can just use it.

Re: Tooltip handle

Posted: Sat Jun 02, 2012 1:52 pm
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