Jump to content

Making Tooltips on sliders other than just #'s 1-100


Achilles
 Share

Recommended Posts

I know that you can set tooltips for your sliders that just set the tip with the GUICtrlRead() value of the slider. Is there a way to set this to something else? I saw _GUICtrlSlider_SetToolTips() in the helpfile but I don't know how to use it because the example is basically just a circular use of it.

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

I know that you can set tooltips for your sliders that just set the tip with the GUICtrlRead() value of the slider. Is there a way to set this to something else? I saw _GUICtrlSlider_SetToolTips() in the helpfile but I don't know how to use it because the example is basically just a circular use of it.

@Achilles

I have problems with GuiToolTip.au3 as well.

there are some problematic functions there,

Rasim had a go at it here: ToolTip UDF

Edit2:

_GUIToolTip_Create() seems to be missing the struct for flags and other settings I think are needed for some functions.

Rasim's version has it, but I'm speculating here.

my above conclusion was wrong with a closer look at GuiToolTip.au3

Rasim made a working example that combined _GUIToolTip_Create() (a wrapper for _WinAPI_CreateWindowEx)

and _GUIToolTip_AddTool() (has the struct) with other tooltip sendmessage commands making it easier to understand.

I couldn't initially get the addtool function to work until trying Rasims example. /Edit2

I had a fun time trying to get some of these functions to work.

however I could get some things to work.

what I want is to be able to activate the slider tooltip so it is always on.

I couldn't get the tooltip text to update but I could update the title.

and as the tooltip text is a rather anemic looking font anyway, the tooltip title looks much better for my use,

so by re-dimensioning the tooltip and hiding the text you get an updateable slider tooltip.

try this example :D

Edit1: the usual 20/20 hindsight corrections ;)

-1 instead of $Slider for GUICtrlSetLimit(), some optimizing of the _Slider() function I left out.

I've posted a slightly better version of this in the Examples Forum here

Edit3: made changes as pointed out by Martin in above topic

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiSlider.au3>
#include <GuiToolTip.au3>

Opt('MustDeclareVars', 1)

Global $Slider, $hSlider, $hWndTT, $Dummy, $iBuffer, $button, $iMode = 0

Example()

Func Example()
    Local $msg

    GUICreate("Slider Tooltip Modifying Demo", 280, 100)
    $Slider = GUICtrlCreateSlider(40, 10, 200, 30, BitOR($TBS_AUTOTICKS, $TBS_TOOLTIPS))
    GUICtrlSetLimit(-1, 20, 0) ; change min/max value
    GUICtrlSetData($Slider, 10) ; set cursor
    GUICtrlSetCursor(-1, 0)
   
    $hSlider = GUICtrlGetHandle($Slider)
    $hWndTT = _GUICtrlSlider_GetToolTips($hSlider)
    _GUICtrlSlider_SetTicFreq($hSlider, 1)
    _GUICtrlSlider_SetTipSide($hSlider, $TBTS_BOTTOM)
    _GUIToolTip_SetTitle($hWndTT, "Value 1.00")
    _GUIToolTip_SetMargin($hWndTT, -5, -5, -5, -20)
    _GUIToolTip_SetTipTextColor($hWndTT, 0xFFFFFF)
    _GUIToolTip_SetTipBkColor($hWndTT, 0x985428)
   
    $Dummy = GUICtrlCreateDummy()
    $button = GUICtrlCreateButton("Float/String", 100, 70, 80, 20)
   
    GUIRegisterMsg($WM_HSCROLL, "WM_HVSCROLL")
    GUISetState()

    Do
        $msg = GUIGetMsg()
        Switch $msg
            Case $Dummy
                _Slider()
            Case $button
                _Mode()
        EndSwitch
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Func _Mode()
    $iMode = Not $iMode
    Switch $iMode
        Case 0
            $iBuffer = ""
            GUICtrlSetLimit($Slider, 20, 0) ; change min/max value
        GUICtrlSetData($Slider, 10) ; set cursor
        Case 1
            $iBuffer = ""
            GUICtrlSetLimit($Slider, 26, 1) ; change min/max value
            GUICtrlSetData($Slider, 1) ; set cursor
    EndSwitch
EndFunc   ;==>_Mode

Func _Slider()
    Local $iValue, $sValue
    $iValue = GUICtrlRead($Dummy); read dummy control for value of slider
    ;ConsoleWrite('+$iValue = ' & $iValue & @crlf) ;**
    If $iBuffer <> $iValue Then ; buffer read slider value to prevent unnecessary updating at end of slider range. **
        $iBuffer = $iValue
        Switch $iMode
            Case 0 ; float
                $iBuffer *= 0.1
                $sValue = StringFormat("Value: %.2f", $iBuffer)
            Case 1 ; string
                $sValue = "Value: " & Chr($iBuffer + 64)
        EndSwitch
        _GUIToolTip_SetTitle($hWndTT, $sValue) ; set slider tooltip title text
        _GUIToolTip_Update($hWndTT) ; update slider tooltip
        ConsoleWrite('-Value = ' & $iBuffer & @CRLF)
    EndIf
    Return
EndFunc   ;==>_Slider

Func WM_HVSCROLL($hwnd, $iMsg, $wParam, $lParam) ; Slider
    #forceref $hWnd, $iMsg, $wParam, $lParam
    Switch $lParam
        Case $hSlider
            GUICtrlSendToDummy($Dummy, GUICtrlRead($Slider))
    EndSwitch
EndFunc   ;==>WM_HVSCROLL
Edited by rover

I see fascists...

Link to comment
Share on other sites

rover

Hey! Nice example my friend! ;) Thank you for sharing! :D

Achilles

Google your friend ;)

Example:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiSlider.au3>
#include <ToolTipConstants.au3>

Global Const $TOOLTIPS_CLASSA = "tooltips_class32"
Global Const $CW_USEDEFAULT = 0x80000000
Global Const $HWND_TOPMOST = -1
Global Const $SWP_NOMOVE = 0x2
Global Const $SWP_NOSIZE = 0x1
Global Const $SWP_NOACTIVATE = 0x10

Global $TOOLINFO

$hGUI = GUICreate("Custom ToolTip Demo", 300, 260)

$slider = GUICtrlCreateSlider(10, 210, 200, 20)
$hToolTip = _ToolTipCreate()

GUIRegisterMsg($WM_HSCROLL, "WM_HVSCROLL")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func WM_HVSCROLL($hWndGUI, $MsgID, $WParam, $LParam)
    Switch $LParam
        Case GUICtrlGetHandle($slider)
            
            Local $tBuffer = DllStructCreate("char[256]")
            DllStructSetData($tBuffer, 1, "New custom tooltip #" & Random(0, 100, 1))
            DllStructSetData($TOOLINFO, "lpszText", DllStructGetPtr($tBuffer))
            
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hToolTip, "int", $TTM_UPDATETIPTEXT, "int", 0, _
                    "ptr",  DllStructGetPtr($TOOLINFO))
            
            DllCall("user32.dll", "int", "SendMessage", "hwnd", $hToolTip, "int", $TTM_TRACKACTIVATE, "int", 1, _
                    "ptr", DllStructGetPtr($TOOLINFO))
    EndSwitch
EndFunc   ;==>WM_HVSCROLL

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndSlider
    $hWndSlider = $slider
    If Not IsHWnd($slider) Then $hWndSlider = GUICtrlGetHandle($slider)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndSlider
            Switch $iCode
                Case $NM_RELEASEDCAPTURE ; The control is releasing mouse capture
                    DllCall("user32.dll", "int", "SendMessage", "hwnd", $hToolTip, "int", $TTM_TRACKACTIVATE, "int", 0, _
                            "ptr", DllStructGetPtr($TOOLINFO))
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
    
Func _ToolTipCreate()
    ;Create ToolTip window
    Local $hToolTip = DllCall("user32.dll", "hwnd", "CreateWindowEx", "int", $WS_EX_TOPMOST, "str", $TOOLTIPS_CLASSA, _
                              "str", 0, "int", BitOR($WS_POPUP, $TTS_ALWAYSTIP), "int", $CW_USEDEFAULT, _
                              "int", $CW_USEDEFAULT, "int", $CW_USEDEFAULT, "int", $CW_USEDEFAULT, "hwnd", $hGUI, "hwnd", 0, _
                              "hwnd", 0, "ptr", 0)
    $hToolTip = $hToolTip[0]
    
    ;Set ToolTip window position
    DllCall("User32.dll", "int", "SetWindowPos", "hwnd", $hToolTip, "hwnd", $HWND_TOPMOST, "int", 0, "int", 0, "int", 0, _
            "int", 0, "int", BitOR($SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOACTIVATE))
    
    ;Create rectangle for ToolTip window
    ;Local $tRect = DllStructCreate("int Left;int Top;int Right;int Bottom")
    
    ;DllCall("user32.dll", "int", "GetClientRect", "hwnd", GUICtrlGetHandle($slider), "ptr", DllStructGetPtr($tRect))
    
    ;Create buffer which contain ToolTip text
    Local $tBuffer = DllStructCreate("char[256]")
    DllStructSetData($tBuffer, 1, "This is tooltip new custom tooltip")
    
    ;Create TOOLINFO structure
    $TOOLINFO = DllStructCreate("int cbSize;int uFlags;hwnd hWnd;int uId;int rect[4];hwnd hinst;" & _
                                   "ptr lpszText;int lParam;int lpReserved")
    
    DllStructSetData($TOOLINFO, "cbSize", DllStructGetSize($TOOLINFO))
    DllStructSetData($TOOLINFO, "uFlags", $TTF_IDISHWND)
    ;DllStructSetData($TOOLINFO, "hWnd", $hGUI)
    DllStructSetData($TOOLINFO, "uId", $slider)
    ;DllStructSetData($TOOLINFO, "rect", DllStructGetData($tRect, "Left"), 1)
    ;DllStructSetData($TOOLINFO, "rect", DllStructGetData($tRect, "Top"), 2)
    ;DllStructSetData($TOOLINFO, "rect", DllStructGetData($tRect, "Right"), 3)
    ;DllStructSetData($TOOLINFO, "rect", DllStructGetData($tRect, "Bottom"), 4)
    DllStructSetData($TOOLINFO, "hinst", 0)
    DllStructSetData($TOOLINFO, "lpszText", DllStructGetPtr($tBuffer))
    DllStructSetData($TOOLINFO, "lParam", 0)
    DllStructSetData($TOOLINFO, "lpReserved", 0)
    
    ;Send message to a system, that a creating ToolTip message
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $hToolTip, "int", $TTM_ADDTOOL, "int", 0, _
            "ptr", DllStructGetPtr($TOOLINFO))
    
    ;Set a title for ToolTip
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $hToolTip, "int", $TTM_SETTITLE, "int", 1, "str", "Title")
    
    ;Set ToolTip width
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $hToolTip, "int", $TTM_SETMAXTIPWIDTH, "int", 0, "int", 100)
    
    ;Set ToolTip text color
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $hToolTip, "int", $TTM_SETTIPTEXTCOLOR, "int", 0x0000FF, "int", 0)
    
    ;Set ToolTip back color
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $hToolTip, "int", $TTM_SETTIPBKCOLOR, "int", 0, "int", 0)
    
    Return $hToolTip
EndFunc   ;==>_ToolTipCreate

Some stuff:

MSDN

VBnet

Link to comment
Share on other sites

@Rasim

another great example I see ;)

good work

I can use this to make a slider tooltip that stays on as a tracking label, Thanks! :D

Edit: on closer inspection, an incorrect assumption on my part, see above post

you should submit a bug report to Trac and submit this version as a replacement for _GUIToolTip_Create()

Cheers

Edited by rover

I see fascists...

Link to comment
Share on other sites

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...