Jump to content
Sign in to follow this  
IKilledBambi

Slider Example

Recommended Posts

IKilledBambi

Can I get an example of how to register when the slider changes to lets say 6.

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

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 447, -1, -1, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_OVERLAPPEDWINDOW,$WS_TILEDWINDOW,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS), 0)
$Slider1 = GUICtrlCreateSlider(104, 368, 145, 33, BitOR($TBS_AUTOTICKS,$TBS_FIXEDLENGTH), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Form1
        Case $Form1
        Case $Form1
        Case $Form1
        Case $Slider1
    EndSwitch
WEnd

I tried

Case $Slider1
    If $Slider1 = 6 Then
        MsgBox(1, "Number", "SIX!")
    Else
        MsgBox(1, "Number", "1")
EndSwitch
WEnd

but no go

Edited by IKilledBambi

Share this post


Link to post
Share on other sites
Andreik

To read the value from slider use GuiCtrlRead():

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

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 447, -1, -1, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_OVERLAPPEDWINDOW,$WS_TILEDWINDOW,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS), 0)
$Slider1 = GUICtrlCreateSlider(104, 368, 145, 33, BitOR($TBS_AUTOTICKS,$TBS_FIXEDLENGTH), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Slider1
            MsgBox(0,"SLIDER",GUICtrlRead($Slider1))
    EndSwitch
WEnd

When the words fail... music speaks

Share this post


Link to post
Share on other sites
Pain

I think this is more what you are looking for.

WM_HSCROLL will make it update in realtime.

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

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 447, -1, -1, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_OVERLAPPEDWINDOW,$WS_TILEDWINDOW,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS), 0)
$Slider1 = GUICtrlCreateSlider(104, 368, 145, 33, BitOR($TBS_AUTOTICKS,$TBS_FIXEDLENGTH), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_HSCROLL , "WM_HSCROLL")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
;~       Case $Slider1
;~           MsgBox(0,"SLIDER",GUICtrlRead($Slider1))
    EndSwitch
WEnd

Func WM_HSCROLL($hWnd, $iMsg, $iwParam, $ilParam)
  If GUICtrlRead($Slider1) = 6 Then
      MsgBox(0, "", "SIX")
  EndIf
EndFunc

Share this post


Link to post
Share on other sites
IKilledBambi

Thanks, now my question is how do I control how many options there are? I think I'm on the track with TBM_SETRANGE but I'm not sure how to even implement this.

Edited by IKilledBambi

Share this post


Link to post
Share on other sites
Pain

$slider1 = GUICtrlCreateSlider (10,10,200,20)

GUICtrlSetLimit(-1,200,0) ; change min/max value

Share this post


Link to post
Share on other sites
Andreik

Or like this:

#Include <GuiSlider.au3>
$GUI = GUICreate("Slider",100,100)
$SLIDER = _GUICtrlSlider_Create($GUI,10,30,80,40)
_GUICtrlSlider_SetRange($SLIDER,0,10)
_GUICtrlSlider_SetTicFreq($SLIDER,2)
GUISetState(@SW_SHOW,$GUI)

While 1
    $MSG = GUIGetMsg()
    If $MSG = -3 Then Exit
    TrayTip("SLIDER",_GUICtrlSlider_GetPos($SLIDER),1)
    Sleep(15)
WEnd

The min value is 0 and the max value is 10.

The slider is marked on the interval 0 - 10 after 2 ticks.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
IKilledBambi

Thanks both answers were needed :mellow: Now my question, is there a better way to do it andreik that way is just to resource taxing. Can I make it only call that function if the slider is changed?

Edited by IKilledBambi

Share this post


Link to post
Share on other sites
Andreik

Thanks both answers were needed :mellow: Now my question, is there a better way to do it andreik that way is just to resource taxing. Can I make it only call that function if the slider is changed?

Like here:

#Include <GuiSlider.au3>
$GUI = GUICreate("Slider",100,100)
$SLIDER = GUICtrlCreateSlider(10,30,80,40)
_GUICtrlSlider_SetRange($SLIDER,0,10)
_GUICtrlSlider_SetTicFreq($SLIDER,2)
GUISetState(@SW_SHOW,$GUI)

While 1
    $MSG = GUIGetMsg()
    If $MSG = -3 Then 
        Exit
    ElseIf $MSG = $SLIDER Then
        MsgBox(0,"VALUE",_GUICtrlSlider_GetPos($SLIDER),1)
    EndIf
    Sleep(15)
WEnd

When the words fail... music speaks

Share this post


Link to post
Share on other sites
Valuater

Another look....

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

; Create GUI
GUICreate("Slider Get Tool Tips", 400, 296)
$hSlider = GUICtrlCreateSlider(2, 2, 396, 20, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS, $TBS_ENABLESELRANGE))
GUISetState()

; Set Tool Tips
$hWndTT = _GUICtrlSlider_GetToolTips($hSlider)
_GUICtrlSlider_SetToolTips($hSlider, $hWndTT)

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

8)


NEWHeader1.png

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  

×