Jump to content

Moving a non-AutoIt trackbar?


LxP
 Share

Recommended Posts

Hi all,

I have a trackbar on a window that accepts any whole-numbered value from 3 to 100. My wish is to write a UDF that takes a single integer and sets that trackbar appropriately:

SetLength($Pct)

I thought I could get away with using the _GUICtrlSliderSetPos() function (which does indeed move the trackbar), however the label next to the trackbar doesn't update and the program does not become aware of the change in any way.

I've resorted to writing the following code which does the job. It works nicely enough, but can anyone offer any improvements? Perhaps a tip on getting _GUICtrlSliderSetPos() to be noticed properly?

; Adjust the length slider on the options page
; Returns FALSE if an error occurs; TRUE otherwise
; @Error -> 1 if a valid percentage (3..100) isn't given
; @Error -> 2 if the necessary page couldn't be made visible
Func SetLength($Pct)

    If Not IsInt($Pct) Or $Pct < 3 Or $Pct > 100 Then
        SetError(1)
        Return False
    EndIf

    SetVisiblePage($OPTS_PAGE)
    If @Error Then
        SetError(2)
        Return False
    EndIf

    Local $Send
    If $Pct <= 51 Then
        $Send = '{HOME}'; 3%
        If $Pct = 3 Then
        ; No more
        ElseIf $Pct <= 13 Then
            $Send &= '{RIGHT ' & ($Pct - 3) & '}'
        Else
            $Send &= '{PGDN}'; 22%
            If $Pct < 22 Then
                $Send &= '{LEFT ' & (22 - $Pct) & '}'
            ElseIf $Pct = 22 Then
            ; No more
            ElseIf $Pct <= 31 Then
                $Send &= '{RIGHT ' & ($Pct - 22) & '}'
            Else
                $Send &= '{PGDN}'; 41%
                If $Pct < 41 Then
                    $Send &= '{LEFT ' & (41 - $Pct) & '}'
                ElseIf $Pct > 41 Then
                    $Send &= '{RIGHT ' & ($Pct - 41) & '}'
                EndIf
            EndIf
        EndIf
    Else
        $Send = '{END}'; 100%
        If $Pct = 100 Then
        ; No more
        ElseIf $Pct >= 91 Then
            $Send &= '{LEFT ' & (100 - $Pct) & '}'
        Else
            $Send &= '{PGUP}'; 81%
            If $Pct > 81 Then
                $Send &= '{RIGHT ' & ($Pct - 81) & '}'
            ElseIf $Pct = 81 Then
            ; No more
            ElseIf $Pct >= 72 Then
                $Send &= '{LEFT ' & (81 - $Pct) & '}'
            Else
                $Send &= '{PGUP}'; 62%
                If $Pct > 62 Then
                    $Send &= '{RIGHT ' & ($Pct - 62) & '}'
                ElseIf $Pct < 62 Then
                    $Send &= '{LEFT ' & (62 - $Pct) & '}'
                EndIf
            EndIf
        EndIf
    EndIf
        
    Local $PrevOpt = Opt('SendKeyDelay', 1)
    ControlSend(GetPageHandle($OPTS_PAGE), '', 'msctls_trackbar321', $Send)
    Opt('SendKeyDelay', $PrevOpt)
    Return True

EndFunc
Link to comment
Share on other sites

Well, perhaps this might do the trick:

Func SetLength($Pct)

    If Not IsInt($Pct) Or $Pct < 3 Or $Pct > 100 Then
        SetError(1)
        Return False
    EndIf

    SetVisiblePage($OPTS_PAGE)
    If @Error Then
        SetError(2)
        Return False
    EndIf

    Local $SetValue, $SendValue
    If $Pct <= 51 Then
        $SetValue = $Pct + 1
        $SendValue = '{LEFT}'
    Else
        $SetValue = $Pct - 1
        $SendValue = '{RIGHT}'
    EndIf
    Local $OptsHandle = GetPageHandle($OPTS_PAGE)
    _GUICtrlSliderSetPos(ControlGetHandle($OptsHandle, '', 'msctls_trackbar321'), $SetValue)
    Local $PrevOpt = Opt('SendKeyDelay', 1)
    ControlSend($OptsHandle, '', 'msctls_trackbar321', $SendValue)
    Opt('SendKeyDelay', $PrevOpt)

    Return True

EndFunc

The code above asks _GUICtrlSliderSetPos() to set the slider one value off the mark and then issues a single key with ControlSend(), which guarantees that the program (since it has to process the key) is aware of the change to the trackbar.

That's the plan anyway. Hopefully when I test it, things work as nicely as before.

Link to comment
Share on other sites

I suppose that it ultimately depends on the effect that each keypress will have. In my case sending {LEFT} or {RIGHT} will decrease or increase the value of the trackbar by precisely 1.

Thanks for your input!

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...