Results 1 to 14 of 14

Thread: A Tooltips Class

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2015
    Location
    Colorado USA
    Posts
    261

    A Tooltips Class

    ToolTip Class for VB6 Forms

    The attached file contains a replacement (or augment) to the ANSI-only, boxy, single-line tooltips provided by VB6. Features of the new class include:

    • Full Unicode support.
    • RightToLeft support for tooltips on controls and the form itself.
    • Multi-line tooltips.
    • Tooltips can have titles.
    • Tooltips can be rectangular or balloons with stems.
    • Some instrinsic controls can have tooltips that cannot be set in traditional VB6 including the form itself, CheckBox, HScrollBar and VScrollBar.
    • If you are not using VisualStyles, you can set tooltip text and background colors and the margins between the edge of the tooltip and the text.
    • You can set the maximum width of the toolbar and if your line of text is wider than that, Windows will determine where to break lines.
    • You can set how long to delay before pop-up, how long to display the tooltip and how long to re-display the tooltip when yo move away and come back.
    • You can quickly update the text n a tooltip.
    • You can deactivate/reactivate any tooltip at any time.
    • You can put a hyperlink in a tooltip and it will show up as such. I haven’t yet figured out to be able to click on it because the tooltip either moves away or disappears when I go after it. I’ll figure it out soon. I suspect I have to fix the tooltip position and keep it displayed a bit.
    • This system is very simple to use. It requires no special files of any kind.
    • No hooks, callbacks or sub-classing is used (Windows does some but we re protected from it) so using these tooltip functions within the IDE is perfectly safe.
    • The module is very small, adding only 16k to your file.


    Name:  In IDE.jpg
Views: 2126
Size:  25.5 KB

    Name:  Compiled.jpg
Views: 2239
Size:  23.3 KB

    Usage

    Include the class module clToolTips in your project. At the top of each form declare it such as this:

    Code:
    Private myToolTips As clToolTips
    Then in your Form_Load procedure set the module and call the NewSetUp procedure:

    Code:
    Set myToolTips = New clToolTips
    myToolTips.NewSetUp Me
    At this point, the class module knows all about your form and its controls. It has set default values for each of the variables discussed below. You have several ways of setting tooltips now or at any point in the run. Many controls have a ToolTipText property which you can set at design-time or at run-time. The system used in this class module doesn’t make use of any of those because VB6 uses a different method for showing tooltips. But you have the option of using those old ToolTipText values to set the new tooltips. You can do it for one control using the Sub UseToolTipText or use the sub DoAllToolTips to make new tooltips out of any controls that have a value set for ToolTipText.

    The main procedure in the class module is SetToolTip and it allows you to specify the tooltip, whether you want an icon shown and optionally a title.

    One of the nifty things about this tooltip system is that you can have multiline tooltips which can occur in two ways. You can specify a maximum width for one or all of the tooltips (discussed below) and if the tooltip text you supply is wider than the maximum tooltip width then Windows automatically looks for spaces to break the lines. Also, quite often you will want more control over where lines break so you can include vbCrLf (or vbNewLine) in your text wherever you want a line break. This gets to be a hassle so you may want to use a shortcut we provide (“``”) which gets converted into a vbCrLf for you. This character is the uppercase of the tilde character just to the left of the “1” key on Western keyboards. You can change this constant in the class module to be whatever you want. I suggest finding some key on the keyboard that you rarely use and put 2 of them in the constant ReplvbCrLf which is defined around line 166.

    You can deactivate or reactivate any tooltip at any time with the ActivateOrNot procedure.
    You can delete a tooltip by using DeleteToolTip.

    Variables

    There are some variables that are set to default values but you can change them at any time. Once changed, the variable holds that value until you change it again. For example, if you change the text color of the first tooltip you design you can leave the color value alone and all subsequent tooltips will use the same color.

    Beware that some of the variables you can set are ignored if your program uses Visual Styles (themes) because Windows will choose for you. So far, I have found that text color, background color and the 4 internal margin settings are affected by this. BTW, if you are using a control that has the capability to use VisualStyles (like Krool’s VBCCRxx controls), it apparently doesn’t matter if you have VisualStyles turned on or off for a given control because Windows takes over. I think this must be that the tooltip is actually a new window (complete with its own handle) and if VisualStyles are no for the program then the new windows have them turned on as well.

    TTForeColor As Long – Sets the text color (ignored if using VisualStyles). Default -1& which tells the system to let Windows choose the text color. You can use any RGB color or VB constants such as vbGreen.

    TTBackColor As Long – Background color for the tooltip. Default -1& which means let Windows decide. This value is ignored if using VisualStyles.

    TTCentered As Boolean- True => center the text; False => left justify. Default is False.

    TTBalloon As Boolean- True => use a balloon with a stem that points to your control. False => Use a rectangle for the tooltip. Default is True.

    TTWrapTextLength As Long- This is another method of controlling the horizontal size of the tooltip but this one is based on a width in terms of characters in the tooltip rather than a maximum iwdth in pixels. For example, suppose you set a wide max tooltip of half of the screen width but you had a line of text that you wanted to limit to 40 characters. You could do that by setting this variable to 40. You would not have a wide tooltip; Windows will only make the tooltip wide enough to handle the 40-character width. I don’t use this method much so I hae set the default at 0 which means it is not used. BTW, the code for this was modified from some code Elroy on vbForums gave me.

    TTTipWidth As Single- This sets the maximum width of the tooltip expressed in terms of a fraction of the width of the screen with the form and controls. It does not set the width of the tooltip, oonly the maximum. For example, if you set this to 1 you are telling the system that your tooltip can be as wide as the screen but if you set a tooltip with the text “Hello World” the tooltip will be very small. ON the other hand, if you don’t specify line breaks in your tooltip text and the length of the tooltip string is such that it is wider than the maximum toolptip size, Windows will do the line breaks for you and the width of the tooltip will be whatever you have set here as the maximum. If you set this to 0 then there is no text wrapping. The default is 0.3, 30% of your screen’s width.

    TTDelayTime As Integer- Sets how long (milliseconds) a pointer must be stationary over the control for the tooltip to pop up. The default is -1 which will use Microsoft’s default time.

    TTVisibleTime As Integer- Sets how long the tooltip will display if the pointer is stationary. The default is -1 which means Windows handles it (Windows sets this to be 10 times the delay time above).

    TTReshowTime As Integer- Sets the amount of time for subsequent tooltips to appear as the pointer moves from one control to another. The default is -1 which lets Windows handle it (Windows sets it to 1/5th the delay time.

    TTMarginsTop As Long- If nt using VisualStyles you can override the Windows defaults and set your own margins for top, left, bottom and right in pixels. If Top = -1 Windows defaults are used for all margins.

    TTMarginsLeft As Long- See above discussion. The default is -1.

    TTMarginsBottom As Long- See above discussion. The default is -1.

    TTMarginsRight As Long- See above discussion. The default is -1.

    Name:  Hyperlink Tooltip.png
Views: 2073
Size:  31.2 KB
    Attached Files Attached Files

  2. #2
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    597

    Re: A Tooltips Class

    Please include and apply a manifest and compile to see the effect of tooltips.
    Attached Files Attached Files
    Last edited by DaveDavis; Aug 19th, 2020 at 03:17 AM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2015
    Location
    Colorado USA
    Posts
    261

    Re: A Tooltips Class

    There are 3 screenshots in my initial post. Two of them came from running the program with a manifest and I thought I had addressed it quite a lot by going over the VisualSyles stuff. It does make quite a difference. I highlighted that it ignores text and background color changes and margins. The other thing it does it to make hyperlinks not appear as hyperlinks.

    I do now that the tooltips work great with Krool's VBCCRxx controls. One interesting find was that even if you turn off VisualStyles for a given control, the tooltip still acts as if VisualStyles were active. It must be that since the whole app is themed Windows will apply VisualStyles to all new windows including pop-ups. That doesn't make sense to me but at least it makes the entire app's tooltips look the same.

    BTW, I don't know if you have a manifest for VB6 but it makes it easy to check out the effects of VisualStyles on your controls. Here is a link to an old article on how to make and use a manifest file with VB6.EXE to get VisualStyles in the IDE. It's simple and it works.

  4. #4
    Lively Member
    Join Date
    May 2021
    Posts
    95

    Re: A Tooltips Class

    Thank you for this.
    Do you see any reason I wouldn't be able to rejig this to be compatible with VBA (64bit)? I note that the routine for setting the tooltips requires a control with a hWnd (or a hWnd, at least).

  5. #5
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    597

    Re: A Tooltips Class

    Quote Originally Posted by DaveDavis View Post
    Please include and apply a manifest and compile to see the effect of tooltips.
    I go back again.
    I see double tips (with resource file applied, mouse on the 'Command Button' and waiting for tooltip then go to CheckBox). Please investigate.

    Name:  toottip.png
Views: 1206
Size:  18.9 KB
    Attached Files Attached Files

  6. #6
    Member
    Join Date
    Mar 2020
    Location
    Germany (BW)
    Posts
    42

    Re: A Tooltips Class

    Hello, MountainMan!
    FYI, I'm using your class in my app, and I added this little piece of code to stop the class from eating up GDI-Objects.
    Code:
    Private Declare Function DestroyWindow Lib "user32.dll" (ByVal hWnd As Long) As Long
    
    Private Sub Class_Terminate()
    Dim n%
    
       For n = 0 To UBound(Controls)
          DestroyWindow Controls(n).TThWnd
       Next
    
    End Sub
    Greetings
    Seniorchef
    Last edited by Seniorchef; Mar 7th, 2023 at 06:51 AM.

  7. #7
    Addicted Member
    Join Date
    Nov 2016
    Location
    GB
    Posts
    141

    Re: A Tooltips Class

    I have a question: if a control doesn't expose "hwnd" how can it be done? because i use an activex with controls that don't expose "hwnd".
    Last edited by fabel358; Mar 24th, 2023 at 08:32 AM.

  8. #8
    New Member
    Join Date
    Aug 2019
    Posts
    6

    Re: A Tooltips Class

    Place an ActiveX control in a PictureBox and add Tooltip to this PictureBox

  9. #9
    Lively Member
    Join Date
    Jan 2008
    Posts
    67

    Re: A Tooltips Class

    Quote Originally Posted by fabel358 View Post
    I have a question: if a control doesn't expose "hwnd" how can it be done? because i use an activex cone controls that don't expose "hwnd".
    If the control have the method setfocus, use:

    Code:
    Private Declare Function GetFocus Lib "user32" () As Long
    Private Sub getHwndControl(Ctl as Control)
        Ctl.SetFocus
        HwndControl = GetFocus()
    End Sub

  10. #10
    Addicted Member
    Join Date
    Nov 2016
    Location
    GB
    Posts
    141

    Re: A Tooltips Class

    Unfortunately no: my controls don't have the setfocus method; controls have getfocus and lostfocus. Anyway thanks, the method is interesting.

  11. #11
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    1,323

    Re: A Tooltips Class

    What makes you think those controls actually have a hWnd? You didn't offer any information about what controls you are using but if they do have a hWnd, it is trivial to obtain via different methods. You could use Spy++ to find information about their window class and then use FindWindow(). You could also try WindowFromPoint() to get the hWnd of a window at a certain position.

  12. #12
    Addicted Member
    Join Date
    Nov 2016
    Location
    GB
    Posts
    141

    Re: A Tooltips Class

    Ok. I use the activex controls xpcontrols.ocx from "The Trust" in my project. These controls have no "hwnd". I'll try the solution proposed by you.

  13. #13
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    1,323

    Re: A Tooltips Class

    Bottom line is if Spy++ doesn't get you a hWnd then there isn't any!

  14. #14
    Registered User
    Join Date
    May 2023
    Posts
    2

    Re: A Tooltips Class

    seems its not work on a label

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width