Jump to content
Sign in to follow this  
psynegy

Live Slider Control

Recommended Posts

psynegy

Is it possible to update something live with a slider (much like in the windows sound control panel, which allows to click and drag the slider to adjust the volume.

#include <GuiConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>

Global $GUI[1]
Global $GUI_STATE[1]
Global $CHANCOUNT = 10
Global $SLIDER[$CHANCOUNT+1]

GUICreate("DMX Console", 900, 500)

For $i = 1 to $CHANCOUNT Step +1
    GuiCtrlCreateLabel($i, (10 + (42*($i-1))), 30, 42, 20, $SS_CENTER)
    $SLIDER[$i] = GuiCtrlCreateSlider((10 + (42*($i-1))), 50, 42, 170, BitOR($TBS_VERT, $TBS_BOTH, $TBS_AUTOTICKS))
    GuiCtrlSetLimit($SLIDER[$i], 255, 0)
    GuiCtrlSetData(-1, 255)
Next



While 1
    $GUI_STATE[0] = GUIGetMsg($GUI[0])
    Switch $GUI_STATE[0]
    Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
    For $i = 1 to $CHANCOUNT Step +1
        If $GUI_STATE[0] = $SLIDER[$i] Then
            MsgBox(0, "", 255-GUICtrlRead($SLIDER[$i]))
        EndIf
    Next

    Sleep(10)
    
WEnd

Obviously it won't be MsgBox I call when I do the real thing, but instead of that being called when you release, I want it to be called every time the slider moves so much as a pixel.

Many thanks ^_^

Share this post


Link to post
Share on other sites
Melba23

psynegy,

These snippets are taken from one of my scripts:

; Create slider
Global $hVol_Slider = GUICtrlCreateSlider(10, 10, 100, 20)
GUICtrlSetLimit(-1, 0, 100)

; In While...WEnd loop
$aInfo = GUIGetCursorInfo($hMain_Win)
If $aInfo[4] = $hVol_Slider Then
    Check_Vol_Slider($aInfo)
EndIf

; Function
Func Check_Vol_Slider($aInfo)
    
    While $aInfo[2]
        SoundSetWaveVolume(GUICtrlRead($hVol_Slider))
    ; Set tooltip
        If $aInfo[4] = $hVol_Slider Then
            ToolTip(100 - GUICtrlRead($hVol_Slider))
        Else
            ToolTip("")
        EndIf
    ; Allow tooltip to display
        Sleep(100)          
    ; Poll for loop
        $aInfo = GUIGetCursorInfo($hMain_Win)
    WEnd

    ToolTip("")

EndFunc

Just look at GUIGetCursorInfo in the Help file to see what is going on. I hope you find them useful.

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
Yashied

Maybe this.

#Include <GUIConstantsEx.au3>
#Include <SliderConstants.au3>

GUICreate('Test', 120, 200)
$Label = GUICtrlCreateLabel('255', 70, 10, 30, 20)
$Slider = GUICtrlCreateSlider(20, 10, 40, 180, BitOR($TBS_AUTOTICKS, $TBS_VERT, $TBS_BOTH))
GUICtrlSetLimit(-1, 255, 0)
GUICtrlSetData(-1, 255)
GUISetState()

$Prev = GUICtrlRead($Slider)

while 1
    $Data = GUICtrlRead($Slider)
    if $Data <> $Prev then
        GUICtrlSetData($Label, $Data)
        $Prev = $Data
    endif
    $Msg = GUIGetMsg()
    switch $Msg
        case $GUI_EVENT_CLOSE
            exit
    endswitch
wend

Share this post


Link to post
Share on other sites
psynegy

Both excellent answers, I'd just finished implementing Melba23's solution (which works perfectly thanks), but I'd rather have the level built into the GUI rather than floating, so I'll use Yashied's one for the final thing I reckon.

Share this post


Link to post
Share on other sites
BrettF
smashly

Same thing again, but moving the slider check outside your main While loop.

#include <GuiConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>

Global $CHANCOUNT = 10
Global $SLIDER[$CHANCOUNT+1][3]

$hGui = GUICreate("DMX Console", 900, 500)

For $i = 1 to $CHANCOUNT Step +1
    $SLIDER[$i][2] = GuiCtrlCreateLabel(0, (10 + (42*($i-1))), 30, 42, 20, $SS_CENTER)
    $SLIDER[$i][1] = GuiCtrlCreateSlider((10 + (42*($i-1))), 50, 42, 170, BitOR($TBS_VERT, $TBS_BOTH, $TBS_AUTOTICKS))
    GuiCtrlSetLimit(-1, 255, 0)
    GuiCtrlSetData(-1, 255)
Next
GUISetState()

AdlibEnable("ChkSlider", 50)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            ;;;
    EndSwitch
WEnd

Func ChkSlider()
    For $i = 1 To $CHANCOUNT
        If $SLIDER[$i][0] <> GUICtrlRead($SLIDER[$i][1]) Then
            $SLIDER[$i][0] = GUICtrlRead($SLIDER[$i][1])
            GuiCtrlSetData($SLIDER[$i][2], 255 - $SLIDER[$i][0])
        EndIf
    Next
EndFunc

Share this post


Link to post
Share on other sites
rover

search forum for WM_HSCROLL, many examples of this

register WM_HSCROLL and/or WM_VSCROLL

messages only occur on event

no continuous slider reading in main loop

can be used with OnEvent or loop mode

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

Opt('MustDeclareVars', 1)

;Global Const $WM_HSCROLL = 0x0114
;Global Const $WM_VSCROLL = 0x0115

Global $Slider, $hSlider, $Dummy, $iBuffer, $Label

Example()

Func Example()
    Local $hGUI, $msg

    $hGUI = GUICreate("Slider Demo", 280, 100)
    $Label = GUICtrlCreateLabel('0', 125, 50, 30, 20)
    $Slider = GUICtrlCreateSlider(40, 10, 200, 30, BitOR($TBS_AUTOTICKS, $TBS_TOOLTIPS))
    $hSlider = GUICtrlGetHandle($Slider)
    GUICtrlSetCursor(-1, 0)
    
    $Dummy = GUICtrlCreateDummy()
    
    ;one or both at same time
    GUIRegisterMsg($WM_HSCROLL, "WM_HVSCROLL") ;horz slider
    ;GUIRegisterMsg($WM_VSCROLL, "WM_HVSCROLL");vert slider
    GUISetState()

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

Func _Slider()
    Local $iValue, $sValue
    $iValue = GUICtrlRead($Dummy)
    If $iBuffer <> $iValue Then
        $iBuffer = $iValue
        GUICtrlSetData($Label, $iBuffer)
        ;ConsoleWrite('-Value = ' & $iBuffer & @CRLF)
    EndIf
    Return
EndFunc   ;==>_Slider

Func WM_HVSCROLL($hwnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    Switch $iMsg
        Case $WM_HSCROLL
            Switch $lParam
                Case $hSlider
                    GUICtrlSendToDummy($Dummy, GUICtrlRead($Slider))
            EndSwitch
        Case $WM_VSCROLL
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_HVSCROLL

I see fascists...

Share this post


Link to post
Share on other sites
Melba23

All,

Thanks for the tutorial - I learn so much from these exchanges. :-)

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
Yashied
Melba23

I agree entirely. The use of Dummy is that way is worth a thread on its own - I now realise it is in the Help file, but I wonder how many others did before reading rover's post?

His posts are always worth reading very carefully - even if a little hard to follow now and again for the simple hobbyists like me! :-)

M23

Edit: speeling

Edited by Melba23

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
Melba23

jdg2010,

The volume handling in Vista and Win7 is very different to that in XP - you are limited to modifying the process volume only. Whn I run your script in Vista with the "Volume Control" visible it acts only on the script volume. :)

However, I believe there are a few example scripts out there which can deal with the master volume - try a search. :)

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
somdcomputerguy

While this has no graphics or sliders for that matter, this bit of code affects the main volume on both Windows 7 and Vista PCs. I haven't tried this on one running XP.

HotKeySet("{F2}", "VolUpDownMute") ;ToggleMute
HotKeySet("{F3}", "VolUpDownMute") ;VolDown
HotKeySet("{F4}", "VolUpDownMute") ;VolUp

While 1
    Sleep(100)
WEnd

Func VolUpDownMute()
    Switch @HotKeyPressed
        Case "{F2}"
            Send("{VOLUME_MUTE}")
        Case "{F3}"
            Send("{VOLUME_DOWN}")
        Case "{F4}"
            Send("{VOLUME_UP}")
    EndSwitch
EndFunc
  • Like 1

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.