VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsToolTip"
Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'-----------------------------------------------------
' MirageBot Tooltip Class
' Written by pscode.com ???
' Edited by Christopher Nevin (lancergli@gmail.com)
'-----------------------------------------------------

Option Explicit

Private Const WM_USER As Long = &H400
Private Const CW_USEDEFAULT As Long = &H80000000
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Const TTS_NOPREFIX As Long = &H2
Private Const TTF_CENTERTIP As Long = &H2
Private Const TTM_ADDTOOLA As Double = (WM_USER + 4)
Private Const TTM_UPDATETIPTEXTA As Double = (WM_USER + 12)
Private Const TTM_SETTIPBKCOLOR As Double = (WM_USER + 19)
Private Const TTM_SETTIPTEXTCOLOR As Double = (WM_USER + 20)
Private Const TTM_SETTITLE As Double = (WM_USER + 32)
Private Const TTS_ALWAYSTIP As Long = &H1
Private Const TTF_SUBCLASS As Long = &H10
Private Const TTF_IDISHWND As Long = &H1
Private Const TTM_SETDELAYTIME As Double = (WM_USER + 3)
Private Const TTDT_AUTOPOP As Integer = 2
Private Const TTDT_INITIAL As Integer = 3
Private Const TOOLTIPS_CLASSA As String = "tooltips_class32"
Private Type TOOLINFO
    lSize As Long
    lFlags As Long
    hWnd As Long
    lID As Long
    lpRect As RECT
    hInstance As Long
    lpStr As String
    lParam As Long
End Type
Public Enum ttIconType
    TTNoIcon = 0
    TTIconInfo = 1
    TTIconWarning = 2
    TTIconError = 3
End Enum
#If False Then
Private TTNoIcon, TTIconInfo, TTIconWarning, TTIconError
#End If
Private mvarBackColor As Long
Private mvarTitle As String
Private mvarForeColor As Long
Private mvarIcon As ttIconType
Private mvarCentered As Boolean
Private mvarTipText As String
Private mvarVisibleTime As Long
Private mvarDelayTime As Long
Private m_lTTHwnd As Long
Private m_lParentHwnd As Long
Private TI As TOOLINFO
Private Declare Sub InitCommonControls Lib "comctl32" ()
Private Declare Function CreateWindowExA Lib "user32" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hWnd As Long) As Long

Public Property Get BackColor() As Long
    BackColor = mvarBackColor
End Property
Public Property Let BackColor(ByVal vData As Long)
    mvarBackColor = vData
    If m_lTTHwnd <> 0 Then SendMessage m_lTTHwnd, TTM_SETTIPBKCOLOR, mvarBackColor, 0&
End Property
Public Property Get Centered() As Boolean
    Centered = mvarCentered
End Property
Public Property Let Centered(ByVal vData As Boolean)
    mvarCentered = vData
End Property
Public Sub Class_Initialize()
    InitCommonControls
    mvarDelayTime = 500
    mvarVisibleTime = 5000
End Sub
Public Sub Class_Terminate()
    On Error Resume Next
    Destroy
End Sub
Public Sub Create(ByVal ParentHwnd As Long)
    Dim lWinStyle As Long
    If m_lTTHwnd <> 0 Then DestroyWindow m_lTTHwnd
    m_lParentHwnd = ParentHwnd
    lWinStyle = TTS_ALWAYSTIP Or TTS_NOPREFIX
    m_lTTHwnd = CreateWindowExA(0&, TOOLTIPS_CLASSA, vbNS, lWinStyle, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0&, 0&, App.hInstance, 0&)
    If mvarCentered Then
        TI.lFlags = TTF_SUBCLASS Or TTF_CENTERTIP Or TTF_IDISHWND
    Else
        TI.lFlags = TTF_SUBCLASS Or TTF_IDISHWND
    End If
    TI.hWnd = m_lParentHwnd
    TI.lID = m_lParentHwnd
    TI.hInstance = App.hInstance
    TI.lSize = Len(TI)
    SendMessage m_lTTHwnd, TTM_ADDTOOLA, 0&, TI
    If LenB(mvarTitle) <> 0 Or mvarIcon <> TTNoIcon Then SendMessage m_lTTHwnd, TTM_SETTITLE, CLng(mvarIcon), ByVal mvarTitle
    If mvarForeColor <> Empty Then SendMessage m_lTTHwnd, TTM_SETTIPTEXTCOLOR, mvarForeColor, 0&
    If mvarBackColor <> Empty Then SendMessage m_lTTHwnd, TTM_SETTIPBKCOLOR, mvarBackColor, 0&
    SendMessage m_lTTHwnd, TTM_SETDELAYTIME, TTDT_AUTOPOP, ByVal mvarVisibleTime
    SendMessage m_lTTHwnd, TTM_SETDELAYTIME, TTDT_INITIAL, ByVal mvarDelayTime
End Sub
Public Property Get DelayTime() As Long
    DelayTime = mvarDelayTime
End Property
Public Property Let DelayTime(ByVal lData As Long)
    mvarDelayTime = lData
End Property
Public Sub Destroy()
    If m_lTTHwnd <> 0 Then DestroyWindow m_lTTHwnd
End Sub
Public Property Get ForeColor() As Long
    ForeColor = mvarForeColor
End Property
Public Property Let ForeColor(ByVal vData As Long)
    mvarForeColor = vData
    If m_lTTHwnd <> 0 Then SendMessage m_lTTHwnd, TTM_SETTIPTEXTCOLOR, mvarForeColor, 0&
End Property
Public Property Get Icon() As ttIconType
    Icon = mvarIcon
End Property
Public Property Let Icon(ByVal vData As ttIconType)
    mvarIcon = vData
    If m_lTTHwnd <> 0 And mvarTitle <> Empty And mvarIcon <> TTNoIcon Then SendMessage m_lTTHwnd, TTM_SETTITLE, CLng(mvarIcon), ByVal mvarTitle
End Property
Public Property Get TipText() As String
    TipText = mvarTipText
End Property
Public Property Let TipText(ByVal vData As String)
    mvarTipText = Replace$(vData, Space$(1), " ")
    TI.lpStr = mvarTipText
    If m_lTTHwnd <> 0 Then SendMessage m_lTTHwnd, TTM_UPDATETIPTEXTA, 0&, TI
End Property
Public Property Get Title() As String
    Title = TI.lpStr
End Property
Public Property Let Title(ByVal vData As String)
    mvarTitle = vData
    If m_lTTHwnd <> 0 And mvarTitle <> Empty And mvarIcon <> TTNoIcon Then SendMessage m_lTTHwnd, TTM_SETTITLE, CLng(mvarIcon), ByVal mvarTitle
End Property
Public Property Get VisibleTime() As Long
    VisibleTime = mvarVisibleTime
End Property
Public Property Let VisibleTime(ByVal lData As Long)
    mvarVisibleTime = lData
End Property
