borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (VB 3)Next Topic (Exe files and Icons....) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Custom Tooltips Query
Poster Message
paulatroundarch
Level: Guest


icon Custom Tooltips Query

Hi - I'm writing about "Custom ToolTips with multiline text and Balloon shape" project (http://www.andreavb.com/tip050007.html).  Can anybody help me with a quick alteration?  Basically there are instances when the tooltip for a particular object on my form needs to change (simple though fictional example, based on a toggle switch: "Turn this function on", "Turn this function off").  If I simply apply AddCustomToolTip a second time to an object, I end up with multiple tooltips all displaying when the mouse is over the object.  Is there a way to disassociate or delete the tooltip from the object so that I can add a new one?  I have to say I'm not all that hot at VB so would appreciate any help / code examples you can provide.  Thanks!

24-04-2003 at 10:24 PM
| Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: Custom Tooltips Query

As far as I can see I think you are out of luck. With the current impleentation there is no way to get around this. I am going to examine the code to see if there is a way to add a remove tooltips procedure that will allow you to replace it. As for now I think you will have to just stick with one tooltip. If you desperately need to change the tip, you can make 2 controls of the same size and stuff. Make one invisible and change their visibilty each time the feature is enabled or disabled. I will get back to you if I find a way.

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

08-05-2003 at 02:11 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
SteveG
Level: Sage


Registered: 15-04-2002
Posts: 56
icon Re: Custom Tooltips Query

Use this within your code

object.ToolTipText = string

where object is your control and string is the required tooltip.

I have tested this on a simple button and it works.



08-05-2003 at 02:25 PM
View Profile Send Email to User Show All Posts | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: Custom Tooltips Query

SteveG, the ToolTipText we have been discussing on this thread is based on code that can be downloaded from the link given by paulatroundarch. I have just tried doing what you said and the same problem comes up, the control displays 2 tooltips.

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

08-05-2003 at 02:46 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: Custom Tooltips Query

Good news, there is a way to change you tooltip provided you make the modification to the ToolTip.bas module that I have supplied. Those who don't know what we are talking about can download the code at http://www.andreavb.com/tip050007.html).  to see what we are talking about. If you unzip the file you will find a module called ToolTip.Bas which allows you to add custom mulitiline balloon tip text to any contrl with the hWnd property, this is what we are going to change. The limitations it has are that there is no way to change the the tip or to remove it.

The changes you will need to make start with the TOldWndProc structure in the module and add a module level boolean variable as such:

Private Type TOldWndProc
    hWnd As Long
    hControl As Long
    ptrForm As Long
    Info As TOOLINFO
    lPrevWndProc As Long
End Type
Private TipIsChanging As Boolean


next we will change the AddCustomToolTip procedure to this, just paste this code it works:

' Add the Custom ToolTip to the specified object
Public Sub AddCustomToolTip(x As Object, ToolTipText As String, FormOwner As Form)
    Dim ti As TOOLINFO
    Dim dwStyle As Long
    Dim hTip As Long

    ' A tooltip control with the TTS_ALWAYSTIP style appears when the cursor is
    ' on a tool, regardless of whether the tooltip control's owner window is active
    ' or inactive. Without this style, the tooltip control appears when the tool's
    ' owner window is active, but not when it is inactive.
    hTip = CreateWindowEx(0&, "tooltips_class32", "", TTS_ALWAYSTIP, _
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, _
        FormOwner.hWnd, 0&, App.hInstance, 0&)
    With ti
      .cbSize = Len(ti)
      .uFlags = TTF_IDISHWND + TTF_SUBCLASS
      .hWnd = x.hWnd
      .uId = x.hWnd
      .lpszText = ToolTipText
    End With
    SendMessage hTip, TTM_ADDTOOL, 0&, ti
    ' SubClass the tooltip window
    If TipIsChanging Then
      TipIsChanging = False
    Else
      ReDim Preserve WndProc(NumTips)
    End If
    With WndProc(NumTips)
      .hWnd = hTip
      .hControl = x.hWnd
      .ptrForm = ObjPtr(FormOwner)    'don't keep a live reference of the form
      .Info = ti
      .lPrevWndProc = SetWindowLong(hTip, GWL_WNDPROC, AddressOf CustomTipProc)
    End With
    NumTips = NumTips + 1
    ' Remove Border from ToolTip
    dwStyle = GetWindowLong(hTip, GWL_STYLE)
    dwStyle = dwStyle And (Not WS_BORDER)
    SetWindowLong hTip, GWL_STYLE, dwStyle
End Sub


After the change, the sub now saves the handle of the object that owns the tip, the TOOLINFO structure that contains info about it and a pointer to the owner form along with the stuff kept in it previously. To allow you to change and delete items, paste the following code into the module as well.

Public Sub ChangeToolTip(obj As Object, newtip As String)
  Dim lng As Long, Info As TOOLINFO, hWnd As Long
  Dim lPrevWndProc As Long, found As Boolean, ptrForm As Long
  
  'find out if the object is in the array
  For lng = LBound(WndProc) To UBound(WndProc)
    With WndProc(lng)
      If .hControl = obj.hWnd Then      'we have found our item
        lPrevWndProc = .lPrevWndProc
        Info = .Info
        ptrForm = .ptrForm
        hWnd = .hWnd
        found = True
        Exit For
      End If
    End With
  Next
  
  'do this only if something was found. Ignore otherwise
  'could have chosen to raise an error but anyone changing a tip they
  'haven't provided deserves to be ignored.
  If found Then
    DeleteArrayItem WndProc, lng, NumTips
    SetWindowLong hWnd, GWL_WNDPROC, lPrevWndProc
    SendMessage hWnd, TTM_DELTOOL, 0&, Info
    'now that it has been removed, create another one
    'tell AddCustomToolTip that it is us changing the tip
    TipIsChanging = True
    AddCustomToolTip obj, newtip, GetForm(ptrForm)
  End If
End Sub

Private Sub DeleteArrayItem(arr() As TOldWndProc, ByVal Index As Long, ByRef NumElements As Long)
  'make sure that a valid item is being deleted
  Debug.Assert Index <= UBound(arr) And Index >= LBound(arr)
  Dim lng As Long
  
  For lng = Index To UBound(arr) - 1
    arr(lng) = arr(lng + 1)
  Next
  'now change the number of elements
  NumElements = NumElements - 1
'  ReDim Preserve arr(NumElements) As TOldWndProc        'resize the array
End Sub


'return a form reference from a pointer
Private Function GetForm(ByVal Pointer As Long) As Form
  Dim xForm As Form
  CopyMemory xForm, Pointer, 4
  Set GetForm = xForm
  CopyMemory xForm, 0&, 4
End Function

Public Sub RemoveTip(obj As Object)
  Dim lng As Long, found As Boolean
  For lng = LBound(WndProc) To UBound(WndProc)
    With WndProc(lng)
      If .hControl = obj.hWnd Then
        SetWindowLong .hWnd, GWL_WNDPROC, .lPrevWndProc
        SendMessage .hWnd, TTM_DELTOOL, 0&, .Info
        found = True
        Exit For
      End If
    End With
  Next
  If found Then DeleteArrayItem WndProc, lng, NumTips
End Sub


That is the code that does the work, now for the user interface bit. Have a form with 3 command buttons, Command1, Command2 and Command3. Paste the following code to the form.

Private Sub Form_Load()
  Dim msg as string, msg2 as string, msg3 as string
  msg = "This is an example of a" & vbCrlf
  msg = msg & "Custom tooltip window with" & vbcrlf
  msg = msg & "multiline text. This tip will" & vbcrlf
  msg = msg  & "change if you clidk this button"
  msg2 = "This tooltip text will" & vbcrlf
  msg2 = msg2 & "disppear when you click this button."
  msg3 = "This tip just tells you that Fadz is fabulous." & vbcrlf
  msg3 = "Click here to close the app"
  AddCustomToolTip Command1, msg, me
  AddCustomToolTip Command2, msg2, Me
  AddCustomToolTip Command3, msg3, Me
End Sub

Private Sub Command1_Click()
  static msg as string
  if msg = "" Then
    msg = "As you can see this tooltip" & vbcrlf
    msg = msg & "has changed."
  end if
  ChangeToolTip Command1, msg
End sub

Private Sub Command2_Click()
  'delete tooltip
  RemoveTip Command2
End Sub

Private Sub Command3_Click()
  Unload Me
end sub


I have just rushed through this code and I'm sure the same thing could be achieved with less code. My primary concern was to see it work. Also, you may notice code duplication in ChangeToolTip and RemoveTip. I had forgotten to implement RemoveTip until the last minute & didn't wnat to review any of my code. Anyway, it works and that's all that matters, happy coding!

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

09-05-2003 at 12:20 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: Custom Tooltips Query

Oops. I forgot one bit. You should also add a declare statement for the CopyMemory API function in the ToolTip.bas module. I use a type library for API access so I never have to write a declare statement and I tend to forget those when I give pple code. The code is as follows:

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (Destination As Any, Source As Any, ByVal Length As Long)


That's it this time. Bye...     

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

09-05-2003 at 12:31 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: Custom Tooltips Query

I am curious how a tooltip causes so much to-do...lol...

if someone has a screen shot of one of these "custom mutliline balloon tooltips" I would be interested in seeing that...  

____________________________
Eggheads unite! You have nothing to lose but your yolks.

09-05-2003 at 12:40 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: Custom Tooltips Query

quote:
~Bean~ wrote:
I am curious how a tooltip causes so much to-do...lol...

if someone has a screen shot of one of these "custom mutliline balloon tooltips" I would be interested in seeing that...  


That I Can do, here goes




Now I guess you know what we are going on about. Hey.

[Edited by admin on 14-05-2003 at 08:10 AM GMT]

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer
09-05-2003 at 01:19 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: Custom Tooltips Query

I am still curious...

____________________________
Eggheads unite! You have nothing to lose but your yolks.

13-05-2003 at 02:19 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: Custom Tooltips Query

I guess you don't need to be curious anymore. The problem has been fixed. Bye.



____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

14-05-2003 at 11:42 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Chopa
Level: Guest

icon Re: Custom Tooltips Query

Just in case you all guy want to simplify this all, you might want to use tooltips from this website: http://www.tooltips.net

I swear they do much a better job, and they are much easier to use.

19-06-2003 at 10:05 AM
| Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: Custom Tooltips Query

I tried those tooltips from that site and I get an error on this line...

Set manager = New VXPTooltipManager

"ActiveX couldn't create Object"

The dll seemed to register OK so I dunno...

____________________________
Eggheads unite! You have nothing to lose but your yolks.

19-06-2003 at 12:48 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Chopa
Level: Guest

icon Re: Custom Tooltips Query

What OS? Which VB environment?

If you just write about it into conference: http://www.tooltips.net/cgi-bin/yabb/YaBB.pl

We will sort it out immediately.
There gotta be something you were doing wrong.



[Edited by Chopa on 19-06-2003 at 12:54 PM GMT]

19-06-2003 at 12:53 PM
| Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: Custom Tooltips Query

tried it on win98...and I dunno what I did wrong, all I did was copy/paste the code, register the dll,  and add the reference

____________________________
Eggheads unite! You have nothing to lose but your yolks.

20-06-2003 at 03:21 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Chopa
Level: Guest

icon Re: Custom Tooltips Query

It says in the Downloads clearly that for Windows 95/98/Me read here: http://www.tooltips.net/mslu.html

Basically, you just needed to copy file unicows.dll into your windows system directory. And that's only on Windows 95/98/Me.

Regards,

20-06-2003 at 03:29 PM
| Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: Custom Tooltips Query

thx chopa!

____________________________
Eggheads unite! You have nothing to lose but your yolks.

20-06-2003 at 05:36 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB General : Custom Tooltips Query
Previous Topic (VB 3)Next Topic (Exe files and Icons....) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder