Valhalla Legends Archive

Programming => General Programming => Topic started by: Inner on May 22, 2004, 08:24 PM

Title: Multiline ToolTipText
Post by: Inner on May 22, 2004, 08:24 PM
Ok, the multiline and everything works until i scroll down. It just likes goes backwards or someting, would anyone know the problem?
Title: Re:Multiline ToolTipText
Post by: Lobo on May 22, 2004, 09:03 PM
Double posting will not get you any faster help. Show some code.
Title: Re:Multiline ToolTipText
Post by: Inner on May 22, 2004, 10:16 PM
I didn't mean to, i didn't know it was moved. =/

Private Sub MakeToolTip(Item As Integer)
   If Item > users.ListItems.Count Or Item = 0 Then Exit Sub
   Set ToolTip = New clsToolTip
   With ToolTip
       
       'Set the handle of the listview
       .HwndParentControl = users.hWnd
       
       'Set the tooltip text, which is stored in the tag of the listview
       .Text = users.ListItems.Item(Item).Tag
       
       'Set the title of the tooltip, leave blank if you don't want it
       .Title = users.ListItems.Item(Item).Text
       
       'Sets the style of the tooltip, Balloon is another option (TTSBalloon)
       .Style = TTSBalloon
       
       'Sets the background color of the tooltip
       .BackColor = &H80000018
       
       'Sets the forecolor of the tooltip
       .ForeColor = vbBlack
       
       'Makes the tooltip with the desired Settings
       Call .Create
   End With
End Sub

Private Sub users_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
   Call MakeToolTip(CInt(y / 220))
End Sub

Public Function Create() As Boolean
   
   On Error GoTo CreateError
   
   Dim lpRect As RECT
   Dim lWinStyle As Long
   
   If lngHwnd <> 0 Then DestroyWindow lngHwnd
   
   lWinStyle = TTS_ALWAYSTIP Or TTS_NOPREFIX
   
   'create baloon style if desired
   If Me.Style = TTBalloon Then lWinStyle = lWinStyle Or TTS_BALLOON
   
   'the parent control has to have been set first
   If Me.HwndParentControl <> 0 Then
       lngHwnd = CreateWindowEx(0&, TOOLTIPS_CLASSA, vbNullString, lWinStyle, _
       CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, _
       Me.HwndParentControl, 0&, App.hInstance, 0&)
       
       'make our tooltip window a "topmost" window
       SetWindowPos lngHwnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, SWP_NOACTIVATE Or SWP_NOSIZE Or SWP_NOMOVE
       
       'get the rect of the parent control
       GetClientRect Me.HwndParentControl, lpRect
       
       'now set our tooltip info structure
       With mtypToolInfo
           'if we want it centered, then set that flag
           If Me.Centered = True Then
               .lFlags = TTF_SUBCLASS Or TTF_CENTERTIP
           Else
               .lFlags = TTF_SUBCLASS
           End If
           
           'set the hwnd prop to our parent control's hwnd
           .lHwnd = Me.HwndParentControl
           .lId = 0
           .hInstance = App.hInstance
           .lpStr = Me.Text
           .lpRect = lpRect
       End With
       
       'add the tooltip structure
       SendMessage lngHwnd, TTM_ADDTOOLA, 0&, mtypToolInfo
       
       'if we want a title or we want an icon
       If Title <> vbNullString Then
           SendMessage lngHwnd, TTM_SETTITLE, 0, ByVal Title
       End If
       
       'Goes all black if you set it to the standard colours
       If ForeColor <> FORE_COLOUR Then
           SendMessage lngHwnd, TTM_SETTIPTEXTCOLOR, ForeColor, 0&     'Set the ForeColor
       End If
       If BackColor <> BACK_COLOUR Then
           SendMessage lngHwnd, TTM_SETTIPBKCOLOR, BackColor, 0&       'Set the BackColor
       End If
       If MultiLine = True Then
           SendMessage lngHwnd, TTM_SETMAXTIPWIDTH, 0&, 0              'Set to multiline
       End If
   End If
   
   Create = True  'All went well!
CreateExit:
   On Error Resume Next
   Exit Function
CreateError:
   Create = False 'Failed!
   Resume CreateExit
End Function


Edit (Grok): added code tags.
Title: Re:Multiline ToolTipText
Post by: hismajesty on May 22, 2004, 10:37 PM
Use the code tags. :)
Title: Re:Multiline ToolTipText
Post by: UserLoser. on May 22, 2004, 10:56 PM
Should do something like...:

Dim lvwHitTestInfo As LVHITTESTINFO
Dim dwItemIndex As Long
   If (lvwUsers.ListItems.Count = 0) Then Exit Sub
   With lvwHitTestInfo
       .pt.X = (X / Screen.TwipsPerPixelX)
       .pt.Y = (Y / Screen.TwipsPerPixelY)
   End With
   dwItemIndex = SendMessage(lvwUsers.hWnd, LVM_HITTEST, 0&, lvwHitTestInfo) + 1

Under your MouseMove

Then...:

Call MakeToolTip(dwItemIndex)


But make sure to destroy the old window (if it exists) before creating a new one
Title: Re:Multiline ToolTipText
Post by: Inner on May 23, 2004, 04:28 PM
Thankyou UserLoser, i got it working fully, and thanks to everyone else for the support.
Title: Re:Multiline ToolTipText
Post by: Grok on May 23, 2004, 08:02 PM
Quote from: Inner on May 23, 2004, 04:28 PM
Thankyou UserLoser, i got it working fully, and thanks to everyone else for the support.

EXPLAIN!  How did yo uget it working fully?  Maybe someone can learn from what you did!

Help make this forum better by posting the answer if someone else didn't post it already.
Title: Re:Multiline ToolTipText
Post by: BaDDBLooD on May 26, 2004, 05:11 PM
yes.. i need to know how to do this ;[
Title: Re:Multiline ToolTipText
Post by: UserLoser. on May 26, 2004, 05:30 PM
Quote from: BaDDBLooD on May 26, 2004, 05:11 PM
yes.. i need to know how to do this ;[

Looks like all the code posted above will allow you to do this
Title: Re:Multiline ToolTipText
Post by: Flame on May 26, 2004, 06:55 PM
There's a few tutorials on PSCode (http://www.pscode.com) which show how to actually make the tooltip which are helpful.  As far as applying the tooltip to a listview, the code UserLoser posted shows exactly how it is done, except for the LVHITTESTINFO, which can be found in This document (http://www.codeguru.com/vb/gen/vb_forms/listviewcontrols/article.php/c5947) which I found off of CodeGuru not long ago.  The article basically shows every step to making these tooltips.
Title: Re:Multiline ToolTipText
Post by: Grok on May 26, 2004, 07:33 PM
My point was that after posting a problem and eventually arriving at the solution, that solution should be obviously posted, as in:

QuoteThankyou UserLoser, i got it working fully, and thanks to everyone else for the support.  WHAT WORKED WAS .... blah blah blah

This affords everyone who searches the forums in the future, looking to solve the same problem, they will find the answer clearly pointed out to them.