Jump to content

Using the GUIToolTip UDF


BrewManNH
 Share

Recommended Posts

Here's a snippet that demonstrates how to use the _GUIToolTip_xxx UDF functions, it's only a brief demo showing some of the techniques to use them. There are no examples in the help file that show how to create them, display them, or use them in general, so I had to figure this out by grabbing snippets here and there from around the internet and seeing how they work.

There are several UDFs that utilize the tooltip UDF with explanations on how to use them with the controls that they are made for, for example the ListView and Tabs UDFs have functions that allow you to create tooltips for those controls, but not any general purpose examples are around the forum. It took me a while to find out how to get these to work but once I got the basics down they weren't hard to use at all.

This script shows you how to create the tooltip, and how you can color them once they're created. It's heavily commented so it should be easy to follow. Take note of the comment after the _GUIToolTip_SetTipTextColor function, it's important to realize how to color the text correctly.

#include <GUIConstantsEx.au3>
#include <GUIToolTip.au3>
Opt('MustDeclareVars', 1)
Example()

Func Example()
    Local $MESSAGE = "The following buttons have been clicked"
    Local $add, $clear, $close, $msg, $mylist

    Local $hGUI = GUICreate("My GUI list")
    Local $hToolTip = _GUIToolTip_Create($hGUI, $TTS_BALLOON) ; create a balloon style tooltip control

    ; turn off visual style for the tooltip otherwise color settings won't work
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hToolTip, "wstr", 0, "wstr", 0)
    ; if you remove the previous line the tooltip displays normally, but you can't color it

    $add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
    Local $hAdd = GUICtrlGetHandle($add) ; we need handles of the controls to use them with the tooltips
    $clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
    Local $hClear = GUICtrlGetHandle($clear)
    $mylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97)
    Local $hMylist = GUICtrlGetHandle($mylist)
    $close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)
    Local $hClose = GUICtrlGetHandle($close)
    GUISetState()
    ; the last number (9) in the below functions indicates that the $iID parameter is a handle to the control and not an identifier of the tooltip
    ; as well as subclassing the tooltip control
    _GUIToolTip_AddTool($hToolTip, 0, "Add something to the list", $hAdd, 0, 0, 0, 0, 9) ; this sets a tooltip to the add button
    _GUIToolTip_AddTool($hToolTip, 0, "This is the close button", $hClose, 0, 0, 0, 0, 9) ; this sets a tooltip to the close button
    _GUIToolTip_AddTool($hToolTip, 0, "This is the ListBox", $hMylist, 0, 0, 0, 0, 9) ; this sets a tooltip to the list control
    _GUIToolTip_AddTool($hToolTip, 0, "Clear the list box", $hClear, 0, 0, 0, 0, 9) ; this sets a tooltip to the clear button
    _GUIToolTip_AddTool($hToolTip, 0, "This is a tooltip for the whole GUI", $hGUI, 0, 0, 0, 0, 9) ; this sets a tooltip to the GUI, and not any control
    _GUIToolTip_SetTipBkColor($hToolTip, "0xA6EEA4") ; RGB value of the color for the background of the tooltip
    _GUIToolTip_SetTipTextColor($hToolTip, "0x6835EE") ; ColorRef value (BGR instead of RGB) for the text color of the tooltip

    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $add
                GUICtrlSetData($mylist, "You clicked button No1|")
            Case $msg = $clear
                GUICtrlSetData($mylist, "")
            Case $msg = $close
                MsgBox(0, "", "the closing button has been clicked", 2)
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Example

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Here's the same script with multiline tooltip text.

#include <GUIConstantsEx.au3>
#include <GUIToolTip.au3>
Opt('MustDeclareVars', 1)
Example()

Func Example()
    Local $MESSAGE = "The following buttons have been clicked"
    Local $add, $clear, $close, $msg, $mylist

    Local $hGUI = GUICreate("My GUI list")
    Local $hToolTip = _GUIToolTip_Create($hGUI, $TTS_BALLOON) ; create a balloon style tooltip control

    ; turn off visual style for the tooltip otherwise color settings won't work
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hToolTip, "wstr", 0, "wstr", 0)
    ; if you remove the previous line the tooltip displays normally, but you can't color it

    ; This line will allow the tooltip to show multiple lines. If the line is too long to fit, it will be 
    ; wrapped to the next line. If you add @CRLF to the tip text without this line, it will only display the firstline
    ; of text.
    _GUIToolTip_SetMaxTipWidth($hToolTip, 1000) ;;1000 is only proforma, you can set it longer or shorter

    $add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
    Local $hAdd = GUICtrlGetHandle($add) ; we need handles of the controls to use them with the tooltips
    $clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
    Local $hClear = GUICtrlGetHandle($clear)
    $mylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97)
    Local $hMylist = GUICtrlGetHandle($mylist)
    $close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)
    Local $hClose = GUICtrlGetHandle($close)
    GUISetState()
    ; the last number (9) in the below functions indicates that the $iID parameter is a handle to the control and not an identifier of the tooltip
    ; as well as subclassing the tooltip control
    _GUIToolTip_AddTool($hToolTip, 0, "Add something to the list" & @CRLF & "Click this button", $hAdd, 0, 0, 0, 0, 9) ; this sets a tooltip to the add button
    _GUIToolTip_AddTool($hToolTip, 0, "This is the close button", $hClose, 0, 0, 0, 0, 9) ; this sets a tooltip to the close button
    _GUIToolTip_AddTool($hToolTip, 0, "This is the ListBox", $hMylist, 0, 0, 0, 0, 9) ; this sets a tooltip to the list control
    _GUIToolTip_AddTool($hToolTip, 0, "Clear the list box", $hClear, 0, 0, 0, 0, 9) ; this sets a tooltip to the clear button
    _GUIToolTip_AddTool($hToolTip, 0, "This is a tooltip " & @CRLF & "for the whole GUI", $hGUI, 0, 0, 0, 0, 9) ; this sets a tooltip to the GUI, and not any control
    _GUIToolTip_SetTipBkColor($hToolTip, "0xA6EEA4") ; RGB value of the color for the background of the tooltip
    _GUIToolTip_SetTipTextColor($hToolTip, "0x6835EE") ; ColorRef value (BGR instead of RGB) for the text color of the tooltip

    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $add
                GUICtrlSetData($mylist, "You clicked button No1|")
            Case $msg = $clear
                GUICtrlSetData($mylist, "")
            Case $msg = $close
                MsgBox(0, "", "the closing button has been clicked", 2)
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Example

You have to add _GUIToolTip_SetMaxTipWidth to get it to display multiline text, don't ask me why, but that's how it works. :)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Here is a modified version of the original script, this modification demonstrates that you can use multiple ToolTip controls and have different settings apply to each of them.

#include <GUIConstantsEx.au3>
#include <GUIToolTip.au3>
Opt('MustDeclareVars', 1)
Example()

Func Example()
    Local $MESSAGE = "The following buttons have been clicked"
    Local $add, $clear, $close, $msg, $mylist

    Local $hGUI = GUICreate("My GUI list")
    Local $hToolTip1 = _GUIToolTip_Create($hGUI, $TTS_BALLOON) ; create a balloon style tooltip control
    Local $hToolTip2 = _GUIToolTip_Create($hGUI, $TTS_BALLOON) ; create a balloon style tooltip control

    ; turn off visual style for the tooltip otherwise color settings won't work
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hToolTip1, "wstr", 0, "wstr", 0)
    ; if you remove the previous line the tooltip displays normally, but you can't color it

    ; This line will allow the tooltip to show multiple lines. If the line is too long to fit, it will be
    ; wrapped to the next line. If you add @CRLF to the tip text without this line, it will only display the firstline
    ; of text.
    _GUIToolTip_SetMaxTipWidth($hToolTip1, 1000) ;;1000 is only proforma, you can set it longer or shorter

    $add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
    Local $hAdd = GUICtrlGetHandle($add) ; we need handles of the controls to use them with the tooltips
    $clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
    Local $hClear = GUICtrlGetHandle($clear)
    $mylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97)
    Local $hMylist = GUICtrlGetHandle($mylist)
    $close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)
    Local $hClose = GUICtrlGetHandle($close)
    GUISetState()
    ; the last number (9) in the below functions indicates that the $iID parameter is a handle to the control and not an identifier of the tooltip
    ; as well as subclassing the tooltip control
    _GUIToolTip_AddTool($hToolTip1, 0, "Add something to the list" & @CRLF & "Click this button", $hAdd, 0, 0, 0, 0, 9) ; this sets a tooltip to the add button
    _GUIToolTip_AddTool($hToolTip1, 0, "This is the close button", $hClose, 0, 0, 0, 0, 9) ; this sets a tooltip to the close button
    _GUIToolTip_AddTool($hToolTip1, 0, "This is the ListBox", $hMylist, 0, 0, 0, 0, 9) ; this sets a tooltip to the list control
    ; Because these tools are added to ToolTip2, the visual style setting doesn't apply on them
    ; Also, because the function _GUIToolTip_SetMaxTipWidth wasn't applied to ToolTip2, the second line for the Clear button won't show.
    _GUIToolTip_AddTool($hToolTip2, 0, "Clear the list box" & @CRLF & "Click this button", $hClear, 0, 0, 0, 0, 9) ; this sets a tooltip to the clear button
    _GUIToolTip_AddTool($hToolTip2, 0, "This is a tooltip " & @CRLF & "for the whole GUI", $hGUI, 0, 0, 0, 0, 9) ; this sets a tooltip to the GUI, and not any control
    _GUIToolTip_SetTipBkColor($hToolTip1, "0xA6EEA4") ; RGB value of the color for the background of the tooltip
    _GUIToolTip_SetTipTextColor($hToolTip1, "0x6835EE") ; ColorRef value (BGR instead of RGB) for the text color of the tooltip

    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $add
                GUICtrlSetData($mylist, "You clicked button No1|")
            Case $msg = $clear
                GUICtrlSetData($mylist, "")
            Case $msg = $close
                MsgBox(0, "", "the closing button has been clicked", 2)
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Example

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

BrewManNH,

Thank you. I made five examples in the help file.

"0xA6EEA4", RGB

_GUIToolTip_SetTipBkColor($hToolTip1, "0xA6EEA4") ; RGB value of the color for the background of the tooltip
_GUIToolTip_SetTipBkColor($hToolTip1, 0xA6EEA4) ; BGR value of the color for the background of the tooltip

Color better

_GUIToolTip_SetTipBkColor($hToolTip1, 0x395A00)
_GUIToolTip_SetTipTextColor($hToolTip1, 0x1EBFFF)

11 examples of added here

Edited by AZJIO
Link to comment
Share on other sites

Very nice Azjio, this UDF has been lacking in examples and updates.

Without any examples of how to use it, I never tried it before, now that I've got the basics down I can at least see its advantages over the default tooltips for style purposes if nothing else.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Here is an example to use the default Windows tooltip but with a different font :

#include <GUIConstantsEx.au3>
#include <GUIToolTip.au3>

Opt("MustDeclareVars", 1)

_Example()

Func _Example()
Local $hGUI, $hTool, $btnAdd, $hFont, $iMsg

#region GUI
    $hGUI = GUICreate("My GUI", 200, 200)
    $btnAdd = GUICtrlCreateButton("Button", 60, 75, 75, 25)
    GUISetState()
#endregion

#region ToolTip
    $hTool = _GUIToolTip_Create($hGUI)
    _GUIToolTip_SetMaxTipWidth($hTool, 1000) ;1000 is only proforma, you can set it longer or shorter << enables multi-lines text

$hFont = _WinAPI_CreateFont(30, 0) ;30px font
_WinAPI_SetFont($hTool, $hFont) ;sets the font to the tooltip

    _GUIToolTip_AddTool($hTool, 0, _
"line 1" & @CrLf & "line 2", _ ;text
GUICtrlGetHandle($btnAdd), _ ;ctrl handle
0, 0, 0, 0, 9) ; this sets a tooltip to the add button
#endregion

    While $iMsg <> $GUI_EVENT_CLOSE
        $iMsg = GUIGetMsg()
    WEnd
EndFunc   ;==>Example
Link to comment
Share on other sites

I was scanning the ToolTipConstants.au3 file and realized that there are constants in there for the AddTool function, but those constants don't match the values in the help file. For example, the help file states that you should use 8 to subclass the tooltip control.

8 - Indicates that the control should subclass the tool's window

But the tooltip constant for that is 16 "Global Const $TTF_SUBCLASS = 0x00000010", in scanning the code for the AddTool function, there's another function in there that converts the incorrect code into the needed code for the tooltip. The author of the tooltip udf used an 8 bit binary code for the settings for the AddTool function which is then read and converted to the necessary values by this function (_GUIToolTip_BitsToTTF) rather than using the constants that were already there to do it. Seems like a long about way to do things if the constants are already provided.

I'd fix this mess if it wouldn't cause script breaking changes in the UDF, but unfortunately it will cause old scripts to break if it's done. I should probably do it anyways and damn the torpedos.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...