Click here to Skip to main content
Click here to Skip to main content

How to implement Windows XP style balloon tooltip using API in VB

, 6 Dec 2005
Rate this:
Please Sign up or sign in to vote.
Very easy to implement ready to use vb class for balloon style tooltip.

Sample screenshot


This article is brought to you by BinaryWorld

URL: http://www.BinaryWorld.net/

Search more than 3500 VB/VB.net/ASP.net SQL Server source code and articles

Dont miss Binaryworld Exclusive API Dictionary...

Click here to check API Dictionary On Binaryworld

Search more than 6185 APIs, 55646 Constants, 455 Types and 985 Examples in our API Dictionary.


Introduction





Using api you can create ballon style tooltip. You can also set varous parameter for tooltip i.e. Delay time, Style, Color etc...

I have implemented a class for Balloon style tooltip.

To run this demo perform the following steps
- Create a standard exe project
- Add a class module rename class1 to CBalloonToolTip
- Add 2 textbox and one command button on form1
- Place Following code in form1

Form1.frm




Dim TT1 As New CBalloonToolTip                            '//Demo for On Demand tooltip
Dim TT2 As New CBalloonToolTip                            '//Demo for mouse over tooltip

Private Declare Function <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=1740">GetKeyState</A> Lib "user32" (ByVal nVirtKey As Long) As Integer

Public Function CapsLockOn() As Boolean
   Dim iKeyState As Integer
   iKeyState = <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=1740">GetKeyState</A>(vbKeyCapital)
   CapsLockOn = (iKeyState = 1 Or iKeyState = -127)
End Function

Private Sub Command1_Click()
   If Text1.Text <> "mypassword" Then
       TT1.Style = TTBalloon
       TT1.Icon = TTIconError
       TT1.Title = IIf(Text1.Text = "", "Blank Password", "Invalid Password")
       TT1.TipText = "Please Enter Correct Password..."
       TT1.PopupOnDemand = True
       TT1.CreateToolTip Text1.hwnd
       TT1.Show 0, Text1.Height / Screen.TwipsPerPixelX - 1    '//In Pixel only
    End If
End Sub

Private Sub Form_Load()
   TT2.Style = TTBalloon
   TT2.Icon = TTIconInfo
   TT2.Title = "Information"
   TT2.TipText = "A little cute tooltip for Textbox2"
   TT2.PopupOnDemand = False
   TT2.ForeColor = vbWhite
   TT2.BackColor = &HCE7110
   TT2.VisibleTime = 6000                                'After 6 Seconds tooltip will go away
    TT2.CreateToolTip Text2.hwnd
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   TT1.Destroy
End Sub

Private Sub Form_Paint()
   TT1.Destroy
End Sub

Private Sub Form_Resize()
   TT1.Destroy
End Sub
Private Sub Form_Unload(Cancel As Integer)
   TT1.Destroy
   TT2.Destroy
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
   If CapsLockOn Then
       TT1.Style = TTBalloon
       TT1.Icon = TTIconWarning
       TT1.Title = "Caps Lock is on"
       TT1.TipText = "Check your caps lock key..."
       TT1.CreateToolTip Text1.hwnd
       TT1.Show 0, Text1.Height / Screen.TwipsPerPixelX - 1
   Else
       TT1.Destroy
   End If
End Sub

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   TT1.Destroy
End Sub

Add the following code in class module

CBalloonToolTip.cls

Option Explicit

Private Declare Sub <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=2339">InitCommonControls</A> Lib "comctl32.dll" ()

''Windows API Functions
Private Declare Function <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=118">CreateWindowEx</A> Lib "user32.dll" Alias "CreateWindowExA" ( _
       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, _
       ByRef lpParam As Any) As Long

Private Declare Function <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=4645">SendMessage</A> Lib "user32.dll" Alias "SendMessageA" ( _
       ByVal hwnd As Long, _
       ByVal wMsg As Long, _
       ByVal wParam As Long, _
       ByRef lParam As Any) As Long

Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" ( _
       ByVal hwnd As Long, _
       ByVal wMsg As Long, _
       ByVal wParam As Long, _
       ByVal lParam As Long) As Long

Private Declare Function <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=161">DestroyWindow</A> Lib "user32" ( _
       ByVal hwnd As Long) As Long

Private Declare Function <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=55">ClientToScreen</A> Lib "user32" ( _
       ByVal hwnd As Long, _
       lpPoint As <A class=Api3 title="Click to view Structure Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=6568">POINTAPI</A>) As Long

''Windows API Constants
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=61147">WM_USER</A> = &H400
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=14022">CW_USEDEFAULT</A> = &H80000000

''Windows API Types
Private Type <A class=Api3 title="Click to view Structure Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=6593">RECT</A>
   left As Long
   top As Long
   right As Long
   bottom As Long
End Type

Private Type <A class=Api3 title="Click to view Structure Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=6568">POINTAPI</A>
   X As Long
   Y As Long
End Type

'Tooltip Window Constants
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58296">TTS_NOPREFIX</A> = &H2
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58233">TTF_TRANSPARENT</A> = &H100
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58227">TTF_CENTERTIP</A> = &H2
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58239">TTM_ADDTOOLA</A> = (<A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=61147">WM_USER</A> + 4)
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58238">TTM_ACTIVATE</A> = <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=61147">WM_USER</A> + 1
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58279">TTM_UPDATETIPTEXTA</A> = (<A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=61147">WM_USER</A> + 12)
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58268">TTM_SETMAXTIPWIDTH</A> = (<A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=61147">WM_USER</A> + 24)
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58269">TTM_SETTIPBKCOLOR</A> = (<A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=61147">WM_USER</A> + 19)
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58270">TTM_SETTIPTEXTCOLOR</A> = (<A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=61147">WM_USER</A> + 20)
Private Const TTM_SETTITLE = (<A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=61147">WM_USER</A> + 32)
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58293">TTS_BALLOON</A> = &H40
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58292">TTS_ALWAYSTIP</A> = &H1
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58231">TTF_SUBCLASS</A> = &H10
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58232">TTF_TRACK</A> = &H20
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58229">TTF_IDISHWND</A> = &H1
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58266">TTM_SETDELAYTIME</A> = (<A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=61147">WM_USER</A> + 3)
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58223">TTDT_AUTOPOP</A> = 2
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58224">TTDT_INITIAL</A> = 3
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58276">TTM_TRACKACTIVATE</A> = <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=61147">WM_USER</A> + 17
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58277">TTM_TRACKPOSITION</A> = <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=61147">WM_USER</A> + 18
Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=61550">WS_POPUP</A> = &H80000000

Private Const <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=57908">TOOLTIPS_CLASSA</A> = "tooltips_class32"

''Tooltip Window Types
Private Type <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=57903">TOOLINFO</A>
   lSize As Long
   lFlags As Long
   hwnd As Long
   lId As Long
   lpRect As <A class=Api3 title="Click to view Structure Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=6593">RECT</A>
   hInstance As Long
   lpStr As String
   lParam As Long
End Type


Public Enum ttIconType
   TTNoIcon = 0
   TTIconInfo = 1
   TTIconWarning = 2
   TTIconError = 3
End Enum

Public Enum ttStyleEnum
   TTStandard
   TTBalloon
End Enum

'local variable(s) to hold property value(s)
Private mvarBackColor As Long
Private mvarTitle As String
Private mvarForeColor As Long
Private mvarIcon As ttIconType
Private mvarCentered As Boolean
Private mvarStyle As ttStyleEnum
Private mvarTipText As String
Private mvarVisibleTime As Long
Private mvarDelayTime As Long
Private mvarPopupOnDemand As Boolean

'private data
Private m_lTTHwnd As Long                                  ' hwnd of the tooltip
Private m_lParentHwnd As Long                              ' hwnd of the window the tooltip attached to
Private ti As <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=57903">TOOLINFO</A>

Private Sub Class_Initialize()
   <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=2339">InitCommonControls</A>
   mvarDelayTime = 500
   mvarVisibleTime = 5000
   mvarPopupOnDemand = False
End Sub
Private Sub Class_Terminate()
   Destroy
End Sub
'//////////////////////////////////////////////////////
Public Property Get VisibleTime() As Long
   VisibleTime = mvarVisibleTime
End Property
Public Property Let VisibleTime(ByVal lData As Long)
   mvarVisibleTime = lData
End Property
'//////////////////////////////////////////////////////
Public Property Get DelayTime() As Long
   DelayTime = mvarDelayTime
End Property
Public Property Let DelayTime(ByVal lData As Long)
   mvarDelayTime = lData
End Property
'//////////////////////////////////////////////////////
Public Property Let Icon(ByVal vData As ttIconType)
   mvarIcon = vData
   If m_lTTHwnd <> 0 And mvarTitle <> Empty And mvarIcon <> TTNoIcon Then
       <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=4645">SendMessage</A> m_lTTHwnd, TTM_SETTITLE, CLng(mvarIcon), ByVal mvarTitle
   End If
End Property
Public Property Get Icon() As ttIconType
   Icon = mvarIcon
End Property
'//////////////////////////////////////////////////////
Public Property Let ForeColor(ByVal vData As Long)
   mvarForeColor = vData
   If m_lTTHwnd <> 0 Then
       <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=4645">SendMessage</A> m_lTTHwnd, <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58270">TTM_SETTIPTEXTCOLOR</A>, mvarForeColor, 0&
   End If
End Property
Public Property Get ForeColor() As Long
   ForeColor = mvarForeColor
End Property
'//////////////////////////////////////////////////////
Public Property Let Title(ByVal vData As String)
   mvarTitle = vData
   If m_lTTHwnd <> 0 And mvarTitle <> Empty And mvarIcon <> TTNoIcon Then
       <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=4645">SendMessage</A> m_lTTHwnd, TTM_SETTITLE, CLng(mvarIcon), ByVal mvarTitle
   End If
End Property
Public Property Get Title() As String
   Title = ti.lpStr
End Property
'//////////////////////////////////////////////////////
Public Property Let PopupOnDemand(ByVal vData As Boolean)
   mvarPopupOnDemand = vData
   'If m_lTTHwnd <> 0 Then
    'End If
End Property
Public Property Get PopupOnDemand() As Boolean
   PopupOnDemand = mvarPopupOnDemand
End Property
'//////////////////////////////////////////////////////
Public Property Let BackColor(ByVal vData As Long)
   mvarBackColor = vData
   If m_lTTHwnd <> 0 Then
       <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=4645">SendMessage</A> m_lTTHwnd, <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58269">TTM_SETTIPBKCOLOR</A>, mvarBackColor, 0&
   End If
End Property
Public Property Get BackColor() As Long
   BackColor = mvarBackColor
End Property
'//////////////////////////////////////////////////////
Public Property Let TipText(ByVal vData As String)
   mvarTipText = vData
   ti.lpStr = vData
   If m_lTTHwnd <> 0 Then
       <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=4645">SendMessage</A> m_lTTHwnd, <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58279">TTM_UPDATETIPTEXTA</A>, 0&, ti
   End If
End Property
Public Property Get TipText() As String
   TipText = mvarTipText
End Property
'//////////////////////////////////////////////////////
Public Property Let Style(ByVal vData As ttStyleEnum)
   mvarStyle = vData
End Property
Public Property Get Style() As ttStyleEnum
   Style = mvarStyle
End Property
'//////////////////////////////////////////////////////
Public Property Let <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=10454">Centered</A>(ByVal vData As Boolean)
   mvarCentered = vData
End Property
Public Property Get <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=10454">Centered</A>() As Boolean
   <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=10454">Centered</A> = mvarCentered
End Property

'X and Y are in Pixel so dont <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=4639">send</A> vbTwips value
Public Sub Show(Optional X As Long = 0, Optional Y As Long = 0)

   Dim pt As <A class=Api3 title="Click to view Structure Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=6568">POINTAPI</A>
   Dim ptTip As Long
   Dim ret As Long

   With pt
       .X = X
       .Y = Y
   End With

   ret = <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=55">ClientToScreen</A>(Form1.Text1.hwnd, pt)

   ptTip = pt.Y * &H10000
   ptTip = ptTip + pt.X

   ' These two messages will set the position of the tooltip:
    ret = <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=4645">SendMessage</A>(m_lTTHwnd, <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58277">TTM_TRACKPOSITION</A>, 0, ByVal ptTip)
   ret = <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=4645">SendMessage</A>(m_lTTHwnd, <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58276">TTM_TRACKACTIVATE</A>, True, ti)

End Sub
Public Function CreateToolTip(ByVal ParentHwnd As Long) As Boolean
   Dim lWinStyle As Long
   If m_lTTHwnd <> 0 Then
       <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=161">DestroyWindow</A> m_lTTHwnd
   End If
   m_lParentHwnd = ParentHwnd

   ''create baloon style if desired
    If mvarStyle = TTBalloon Then lWinStyle = lWinStyle Or <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58293">TTS_BALLOON</A>

   m_lTTHwnd = <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=118">CreateWindowEx</A>(0&, _
           <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=57908">TOOLTIPS_CLASSA</A>, _
           vbNullString, _
           lWinStyle, _
           0&, _
           0&, _
           0&, _
           0&, _
           m_lParentHwnd, _
           0&, _
           0&, _
           0&)

   ''now set our tooltip info structure
    With ti
       '//dont incude <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58231">TTF_SUBCLASS</A> for on demand
        ''if we want it <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=10454">centered</A>, then set that flag
        If mvarCentered Then
           If mvarPopupOnDemand = False Then
               .lFlags = <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58231">TTF_SUBCLASS</A> Or <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58227">TTF_CENTERTIP</A> Or <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58229">TTF_IDISHWND</A>
           Else
               .lFlags = <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58229">TTF_IDISHWND</A> Or <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58232">TTF_TRACK</A> Or <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58227">TTF_CENTERTIP</A>
           End If
       Else
           If mvarPopupOnDemand = False Then
               .lFlags = <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58231">TTF_SUBCLASS</A> Or <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58229">TTF_IDISHWND</A>
           Else
               .lFlags = <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58229">TTF_IDISHWND</A> Or <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58232">TTF_TRACK</A> Or <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58233">TTF_TRANSPARENT</A>
           End If
       End If

       'set the hwnd prop to our parent control's hwnd
        .hwnd = m_lParentHwnd
       .lId = m_lParentHwnd                              '0
        .hInstance = App.hInstance
       '.lpstr = ALREADY SET
        '.lpRect = lpRect
        .lSize = Len(ti)
   End With

   ''add the tooltip structure
    <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=4645">SendMessage</A> m_lTTHwnd, <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58239">TTM_ADDTOOLA</A>, 0&, ti

   ''if we want a title or we want an icon
    If mvarTitle <> vbNullString Or mvarIcon <> TTNoIcon Then
       <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=4645">SendMessage</A> m_lTTHwnd, TTM_SETTITLE, CLng(mvarIcon), ByVal mvarTitle
   End If

   If mvarForeColor <> Empty Then
       <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=4645">SendMessage</A> m_lTTHwnd, <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58270">TTM_SETTIPTEXTCOLOR</A>, mvarForeColor, 0&
   End If

   If mvarBackColor <> Empty Then
       <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=4645">SendMessage</A> m_lTTHwnd, <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58269">TTM_SETTIPBKCOLOR</A>, mvarBackColor, 0&
   End If

   SendMessageLong m_lTTHwnd, <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58266">TTM_SETDELAYTIME</A>, <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58223">TTDT_AUTOPOP</A>, mvarVisibleTime
   SendMessageLong m_lTTHwnd, <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58266">TTM_SETDELAYTIME</A>, <A class=Api2 title="Click to view Constant Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=58224">TTDT_INITIAL</A>, mvarDelayTime

End Function

Public Sub Destroy()
   If m_lTTHwnd <> 0 Then
       <A class=Api1 title="Click to view API Description" href="http://binaryworld.no-ip.info/Main/ApiDetail.aspx?ApiId=161">DestroyWindow</A> m_lTTHwnd
   End If
End Sub

Submitted By : Nayan Patel
Job Description : Currently he is working as an independent consultant. He has experience with VB.net/ASP.net, SQL and other MS technologies. He is MCSD.net, MCDBA and MCSE. He is moderator of binaryworld ( URL: http://BinaryWorld.net. )
View all (455) submissions by this author

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

NSPatel38
Web Developer
United States United States
Currently he is working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.

Comments and Discussions

 
QuestionVery good Class / Create with close icon PinmemberOrgMulle8-Mar-09 23:49 
GeneralTips Appear Twice and no longer work after a control is clicked. PinmemberKaos280012-Sep-08 5:33 
GeneralI have converted this to c# Pinmembernbaker20-Dec-06 9:21 
AnswerRe: I have converted this to c# Pinmembersameeraperera6-Aug-07 23:59 
QuestionRight to Left? PinmemberPiTmA28-Apr-06 12:39 
GeneralC#.net PinmemberWaqasButt25-Jul-05 23:29 
GeneralRe: C#.net Pinmembernbaker20-Dec-06 9:24 
GeneralThe original CTooltip class and some possible problems Pinsuss10Tec Company29-Jun-05 6:46 
Hello guys!
 
My name is Igor Katenev, I am chief of 10Tec Company (www.10Tec.com[^]). It is amazing, but the source code of the CBalloonToolTip class looks very similar to our CTooltip class I published on many sites in the Internet. You can simply enter one of the names of those articles in the Google search box, "Adding multiline balloon tooltips to ListView items" or "Adding multiline balloon tooltips to ListView column headers" or "Adding real Win32 tooltips for windowless controls (Label, Image, etc)", to find those articles. Here are a couple of direct links you can use to read those articles:
 
http://www.codeguru.com/vb/gen/vb_forms/listviewcontrols/article.php/c5947/[^]
http://andreavb.com/forum/viewtopic.php?TopicID=1647[^]
http://www.codeguru.com/Cpp/controls/listview/tooltiptitletip/article.php/c4171/[^]
 
The source code we published is free, so I do not want to raise any claim Smile | :) . I just wanted to give other sources and possible techniques you can use in your apps.
 
By the way, we used the source code of the original CTooltip class in our commercial component, hTooltip (the abbreviation for "handy tooltip", the home page of the product is http://www.10tec.com/Products/ActiveX/hTooltip/index.aspx[^]), and we encountered and solved a lot of problems in this original class while we were implementing hTooltip.
 
The CTooltip (or CBalloonToolTip) class can be used to create tooltips for VB windowless controls which do not have their own API handle (the HWnd property). In fact, you can create the tooltips for the parent form's handle to gain this goal, and one of our articles, "Adding real Win32 tooltips for windowless controls (Label, Image, etc)", demonstrates this approach. But if you have several windowless controls on your form and they can overlap each other, or the form is simply cluttered with many controls, you need to know when the mouse pointer left the area occupied by one control and entered another, and it is not a simple task even for 2 or 3 controls if you work only with the MouseMove event. You need the real MouseEnter and MouseLeave events for your VB controls, and we solved this problem in our component (in fact, it provides you with these events for any control you attach an hTooltip tooltip to).
 
Second, if you need to display an on-demand tooltip for your controls say when the mouse pointer enters the area occupied by the control (our customers ask this functionality enough often), the same problem can occur if you move the mouse pointer very fast because the MouseMove events will be triggered not for contiguous points, and you will need the real MouseEnter/MouseLeave events again.
 
We also found problems when you create a tooltip with the CTooltip class for some intrinsic VB controls, and a part of these problems occurs when your app is used Windows XP visual styles. So test the tooltips in your app in this case very thoroughly! We also found that a tooltip may be no longer displayed after you have clicked the control it is attached too.
 
The problem with the ClientToScreen API call is also solved in our code. Pay attention to the fact that author uses it for the text box Text1 placed on the form Form1, and you need to know the real parent window of the tooltip to specify the proper coordinates. By the way, in our component you do not have such problems at all as you can create a tooltip for ANY VB control (windowless too) with one statement using the CreateForVBCtrl method, and our component can work with twips as well. The hTooltip library can be also used in such development environments as Visual FoxPro, the .NET Framework, VBA in MS Office and so on.
 
The CBalloonToolTip class does not allow you to specify a new line in the tip text where you need it, so you cannot use the CR (carriage return) and LF (line feed) characters or simply vbCrLf in VB6 to specify a new line of text.
 
And last, if you form is a top-most form, you may not see the tooltip window at all or only its part. Test this issue too.
 
Hope this helps you to build a more robust solution that uses the CBalloonToolTip class as now you know what issues you need to test carefully.
 
Best regards,
Igor Katenev
chief of 10Tec Company

GeneralExactly what I was looking for... PinsussAnonymous14-Jun-05 12:45 
GeneralCalling it from ASP Pinmemberfreddyq11-Jun-05 4:52 
Generalvb.net Pinmemberj45mw13-Mar-05 4:54 
GeneralRe: vb.net PinmemberNayan S. Patel13-Mar-05 6:21 
GeneralRe: vb.net Pinmemberj45mw13-Mar-05 16:16 
GeneralRe: vb.net Pinmemberj45mw13-Mar-05 16:31 
GeneralRe: vb.net Pinmemberj45mw13-Mar-05 17:33 
GeneralRe: vb.net PinmemberNayan S. Patel13-Mar-05 17:58 
Generalthis is really usefull for me Pinmembersemion_k3-Mar-05 11:26 
GeneralClientToScreen problem with .NET PinmemberGeoff McKay26-Oct-04 11:06 
GeneralCool! Pinmembertidoy5-Oct-04 11:10 
GeneralWTF PinmemberMr.Prakash11-Aug-04 17:57 
GeneralRe: WTF PinsussAnonymous11-Aug-04 18:09 
GeneralRe: WTF PinsussDarkSnow12-Mar-05 8:52 
GeneralRe: WTF Pinmemberstingrayweb17-Apr-05 18:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 6 Dec 2005
Article Copyright 2004 by NSPatel38
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid