am632

slider question

7 posts in this topic

Hi,

I have a basic slider, with numbers between 1 & 100 and the slider works fine, I click a button which displays a msgbox containing the selected number from the slider control but is there a way I can make the slider show the current number as the user slides up & down - like in a small balloon tip above the slider for example? because the user doesnt know which number is selected until the msgbox is displayed.

Thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The helpfile example shows how to do that:

$hSlider = _GUICtrlSlider_Create($hGUI, 2, 2, 396, 20, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS))
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi,

I have a basic slider, with numbers between 1 & 100 and the slider works fine, I click a button which displays a msgbox containing the selected number from the slider control but is there a way I can make the slider show the current number as the user slides up & down - like in a small balloon tip above the slider for example? because the user doesnt know which number is selected until the msgbox is displayed.

Thanks

you can do something like this

while 1
      changeslider()
       sleep(200)
Wend

Func changeslider()
    GUICtrlSetData($yourlabel,$yourslidervalue)
EndFunc

Or:

AdlibRegister("changeslider",200)

Func changeslider()
    GUICtrlSetData($yourlabel,$yourslidervalue)
EndFunc 

$yourslidervalue = slider which you created with current value

$yourlabel = a label which you will create it and will contain the slider value (put in below slider to look like is a part of slider)

Edited by DocTorCoder

DocTorCoder

Share this post


Link to post
Share on other sites

DocTorCoder,

Personally, I would wait until the slider was actually moved rather than run the function every time through the loop: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <SliderConstants.au3>
#include <WinAPI.au3>

Global $nTimer, $bToolTip = False

$hGUI = GUICreate("Test", 500, 500)

$cSlider = GUICtrlCreateSlider(10, 10, 200, 20, $TBS_AUTOTICKS)
$hSlider = GUICtrlGetHandle($cSlider)

GUISetState()

GUIRegisterMsg($WM_HSCROLL, "_WM_HSCROLL")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; If tooltip displayed and no change for 500ms
    If $bToolTip And TimerDiff($nTimer) > 500 Then
        ; Clear tootip
        ToolTip("")
        ; Clear flag
        $bToolTip = False
    EndIf

WEnd

; React to slider movement
Func _WM_HSCROLL($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg

    If $lParam = $hSlider Then
        If _WinAPI_LoWord($wParam) = 5 Then ;$SB_THUMBTRACK
            ; Show tooltip
            ToolTip(GUICtrlRead($cSlider))
            ; Set timestamp
            $nTimer = TimerInit()
            ; Set flag
            $bToolTip = True
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WM_HSCROLL
When passing through the idle loop the flag is checked and nothing more happens until it is set. That means the slider has been moved and now there is a second check to get the time since the last movement - and then the tooltip is cleared if no movement has taken place for a given time. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hi,

Thanks all for the help, Melba23 your example worked perfectly, Thanks

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

easier route:

#include <GuiSlider.au3>
#include <GUIConstantsEx.au3>
Example()

Func Example()

    GUICreate("slider", 220, 100, 100, 200)
    GUISetBkColor(0x00E0FFFF) ; will change background color

    Local $idSlider1 = GUICtrlCreateSlider(10, 10, 200, 20,BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS))
    GUICtrlSetLimit(-1, 200, 0) ; change min/max value
    GUISetState(@SW_SHOW)
    GUICtrlSetData($idSlider1, 45) ; set cursor

    Local $idMsg
    ; Loop until the user exits.
    Do
        $idMsg = GUIGetMsg()
    Until $idMsg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

DocTorCoder,

Personally, I would wait until the slider was actually moved rather than run the function every time through the loop: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <SliderConstants.au3>
#include <WinAPI.au3>

Global $nTimer, $bToolTip = False

$hGUI = GUICreate("Test", 500, 500)

$cSlider = GUICtrlCreateSlider(10, 10, 200, 20, $TBS_AUTOTICKS)
$hSlider = GUICtrlGetHandle($cSlider)

GUISetState()

GUIRegisterMsg($WM_HSCROLL, "_WM_HSCROLL")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; If tooltip displayed and no change for 500ms
    If $bToolTip And TimerDiff($nTimer) > 500 Then
        ; Clear tootip
        ToolTip("")
        ; Clear flag
        $bToolTip = False
    EndIf

WEnd

; React to slider movement
Func _WM_HSCROLL($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg

    If $lParam = $hSlider Then
        If _WinAPI_LoWord($wParam) = 5 Then ;$SB_THUMBTRACK
            ; Show tooltip
            ToolTip(GUICtrlRead($cSlider))
            ; Set timestamp
            $nTimer = TimerInit()
            ; Set flag
            $bToolTip = True
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WM_HSCROLL
When passing through the idle loop the flag is checked and nothing more happens until it is set. That means the slider has been moved and now there is a second check to get the time since the last movement - and then the tooltip is cleared if no movement has taken place for a given time. ;)

M23

 

Correct,to avoid doing same thing when moving event is not there!


DocTorCoder

Share this post


Link to post
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