Re: GadgetTooltip, using lines instead of single line
Posted: Thu Nov 09, 2023 6:32 pm
@Mijikai
Thank you, I was already looking for the code ...
But don't use SysAllocString, just the pointer to the text.
TTM_AddTool creates a copy of the text itself.
Rect was wrong because tooltip is subclass from gadget
Update
- hInst not used
- Added FreeToolTip for release resources
Thank you, I was already looking for the code ...
But don't use SysAllocString, just the pointer to the text.
TTM_AddTool creates a copy of the text itself.
Rect was wrong because tooltip is subclass from gadget
Update
- hInst not used
- Added FreeToolTip for release resources
Code: Select all
EnableExplicit
Procedure.i ToolTip(Gadget, Text.s, Width = 150)
Protected hwnd.i
Protected ti.TOOLINFO
If IsGadget(Gadget)
ti\cbSize = SizeOf(TOOLINFO)
ti\uFlags = #TTF_SUBCLASS
ti\hWnd = GadgetID(Gadget)
ti\uId = Gadget
ti\lpszText = @Text
ti\rect\left = 0
ti\rect\top = 0
ti\rect\right = GadgetWidth(Gadget)
ti\rect\bottom = GadgetHeight(Gadget)
hwnd = CreateWindowEx_(#Null,#TOOLTIPS_CLASS,#Null,
#WS_POPUP|#TTS_ALWAYSTIP,
#CW_USEDEFAULT,#CW_USEDEFAULT,#CW_USEDEFAULT,
#CW_USEDEFAULT,ti\hWnd,#Null,ti\hInst,#Null)
If hwnd
SetProp_(ti\hWnd, "MyToolTipHandle", hwnd)
SendMessage_(hwnd,#TTM_ADDTOOL,#Null,@ti)
SendMessage_(hwnd,#TTM_SETMAXTIPWIDTH,#Null,Width)
ProcedureReturn #True
EndIf
EndIf
ProcedureReturn #False
EndProcedure
Procedure FreeToolTip(Gadget)
Protected r1, hwnd, ti.TOOLINFO
If IsGadget(Gadget)
hwnd = RemoveProp_(GadgetID(Gadget), "MyToolTipHandle")
If hwnd
ti\cbSize = SizeOf(TOOLINFO)
ti\hWnd = GadgetID(Gadget)
ti\uId = Gadget
SendMessage_(hwnd,#TTM_DELTOOL,#Null,@ti)
EndIf
EndIf
EndProcedure
Procedure.i Main()
If OpenWindow(0,0,0,800,600,"Dummy",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(1,10,30,200,30,"Hello World!")
ToolTip(1,"Hello World!" + #CR$ + "How does this magic work?" + #CR$ + "Black Magic!!!!")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case 1
FreeToolTip(1)
EndSelect
EndSelect
ForEver
FreeToolTip(1)
CloseWindow(0)
EndIf
ProcedureReturn #Null
EndProcedure
End Main()