#Include once "window9.bi"

Type TOOLINFO1
  As UINT cbSize
  As UINT      uFlags
  As HWND      hwnd
  As UINT      uId
  As RECT      rect
  As HINSTANCE hinst
  As integer     lpszText
End Type
Dim Shared Tool As TOOLINFO1

Function GadgetToolTip(ByVal gadget As integer, ByVal text As String,ByVal Mygadget As Integer=0)As Integer Export
  Var  fbguiTemp=CreateWindowEx(WS_EX_TOPMOST,"Tooltips_Class32",0,1 Or 2 Or WS_POPUP,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,Cast(HWND,GadgetID(gadget)),0,0,0)
  If Mygadget<>0 Then
    ADDIN9999 (Mygadget,fbguiTemp)
    ColorAdd(fbguiTemp,GetSysColor(COLOR_WINDOW),GetSysColor(COLOR_WINDOWTEXT))
  EndIf
  SendMessage(fbguiTemp,1027,3,500)
  SendMessage(fbguiTemp,1048,0,160)
  Tool.cbSize=SizeOf(TOOLINFO1)
  Tool.uFlags=16 Or 1
  Tool.hwnd=GadgetID(gadget)
  Tool.uID=cast(UINT,GadgetID(gadget))
  Tool.hInst=0
  Tool.lpszText=Cast(Integer,StrPtr(Text))
  SendMessage(fbguiTemp,1028,0,Cast(LPARAM,@Tool))
  If GGF()<>0 Then
    SendMessage(fbguiTemp,WM_SETFONT,GGF(),0)
  EndIf
  Return Cast(Integer,@Tool)
End Function

Function DelToolTip(ByVal GadgetPARRENT As Integer,ByVal gadget As Integer) As Integer Export
  Tool.hwnd=GadgetID(GadgetPARRENT)
  Tool.uId=Cast(UINT,GadgetID(GadgetPARRENT))
  Return SendMessage(GadgetID(gadget),1029,0,Cast(LPARAM,@Tool))
End Function

Function GetToolTipText(ByVal GadgetPARRENT As Integer,ByVal gadget As Integer) As string Export
  Tool.hwnd=GadgetID(GadgetPARRENT)
  Tool.uId=Cast(UINT,GadgetID(GadgetPARRENT))
  SendMessage(GadgetID(gadget),1035,0,Cast(LPARAM,@Tool))
  Return *cast(Zstring ptr,Tool.lpszText)
End Function

Function DisableToolTip(ByVal gadget As Integer,ByVal state As Byte) As integer Export
  If state=1 Then
    Return SendMessage(GadgetID(gadget),1025,0,0)
  Else
    Return SendMessage(GadgetID(gadget),1025,1,0)
  EndIf
End Function

Function SetToolTipText(ByVal GadgetPARRENT As Integer,ByVal gadget As Integer,ByVal text As String) As Integer Export
  Tool.hwnd=GadgetID(GadgetPARRENT)
  Tool.uId=Cast(UINT,GadgetID(GadgetPARRENT))
  Tool.lpszText=Cast(Integer,StrPtr(Text))
  Return SendMessage(GadgetID(gadget),1036,0,Cast(LPARAM,@Tool))
End Function
