Tooltip handle
Posted: Tue Mar 17, 2009 3:53 am
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
)
ToolTipID version:
GadgetToolTipEx version:
Note that the border has to come off if you're changing to a balloon.

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
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