Jump to content

How to detect value changes in Slider controls


Go to solution Solved by Nine,

Recommended Posts

Posted

I am adding a feature to a project that detects changes in Input boxes. It already successfully detects changes and displays a "Unsaved Changes" label in the GUI. If I undo those changes, the "Unsaved Changes" label is hidden. I'm kind of proud of myself for figuring that part out.

I am using WM_COMMAND to detect the changes. However, when I tried the same technique with Slider controls, it did not work. And I was kind of expecting it to fail. I checked over the SliderConstants.au3 file to see if there was anything that I could work with in there.

I could probably do something with GUICtrlSetOnEvent since this project uses OnEvent mode. But I was really hoping to monitor the Slider value changes in WM_COMMAND so that it's all together with the Input controls.

Does anyone know if it's possible to watch for Slider value changes in WM_COMMAND?

Thank you :)

 

Func ED_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local Static $b01 = True, $b02 = True, $b03 = True, $b04 = True, $b05 = True, $b06 = True, $b07 = True, $b08 = True, $b09 = True
    Local Static $b10 = True, $b11 = True, $b12 = True, $b13 = True, $b14 = True, $b15 = True
    Local $iCode = BitShift($wParam, 16)
         Case GUICtrlGetHandle($BorderColorInput)
            Switch $iCode
                Case $EN_SETFOCUS
                    $bWatchSaveChanges = True
                Case $EN_CHANGE
                    If $bWatchSaveChanges And GUICtrlRead($BorderColorInput) <> $sWatchBorderColorInput Then
                        GUICtrlSetState($idPart4, $GUI_SHOW)
                        $b01 = False
                    Else
                        $b01 = True
                        If $bWatchSaveChanges Then
                            If $b01 And $b02 And $b03 And $b04 And $b05 And $b06 And $b07 And $b08 And $b09 And $b10 And $b11 And $b12 And $b13 And $b14 And $b15 Then
                                GUICtrlSetState($idPart4, $GUI_HIDE)
                            EndIf
                        EndIf
                    EndIf
            EndSwitch
        Case GUICtrlGetHandle($TitlebarColorInput)
            Switch $iCode
                Case $EN_SETFOCUS
                    $bWatchSaveChanges = True
                Case $EN_CHANGE
                    If $bWatchSaveChanges And GUICtrlRead($TitlebarColorInput) <> $sWatchTitlebarColorInput Then
                        GUICtrlSetState($idPart4, $GUI_SHOW)
                        $b02 = False
                    Else
                        $b02 = True
                        If $bWatchSaveChanges Then
                            If $b01 And $b02 And $b03 And $b04 And $b05 And $b06 And $b07 And $b08 And $b09 And $b10 And $b11 And $b12 And $b13 And $b14 And $b15 Then
                                GUICtrlSetState($idPart4, $GUI_HIDE)
                            EndIf
                        EndIf
                    EndIf
            EndSwitch
        Case GUICtrlGetHandle($BlurColorIntensitySliderInact)
            Switch $iCode
                Case $EN_SETFOCUS
                    $bWatchSaveChanges = True
                Case $EN_CHANGE
                    If $bWatchSaveChanges And GUICtrlRead($BlurColorIntensitySliderInact) <> $sWatchBlurColorIntensitySliderInact Then
                        ConsoleWrite("slider trigger" & @CRLF)
                        GUICtrlSetState($idPart4, $GUI_SHOW)
                        $b03 = False
                    Else
                        $b03 = True
                        If $bWatchSaveChanges Then
                            If $b01 And $b02 And $b03 And $b04 And $b05 And $b06 And $b07 And $b08 And $b09 And $b10 And $b11 And $b12 And $b13 And $b14 And $b15 Then
                                GUICtrlSetState($idPart4, $GUI_HIDE)
                            EndIf
                        EndIf
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc  ;==>ED_WM_COMMAND

 

Posted

I am on my smartphone, without any coding possibilities right now, but why do you want to go with WD_COMMAND?

You could also try using AdLibRegister to register a function that constantly checks for slider value updates (simple polling). I guess in a GUI each 250ms is totally enough to check and trigger the label change (hint text etc.).

Just another approach which is easily implemented in my point of view.

Besides that @WildByDesign , best regards as usually, Sven 😀 .

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server, 🔗 Cheat Sheet🔗 autoit-webdriver-boilerplate

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Posted
4 minutes ago, SOLVE-SMART said:

but why do you want to go with WD_COMMAND?

The reason why I decided to go with WM_COMMAND is because I already had it in place to do some things with comboboxes. So I only ended up having to add "Case $EN_CHANGE" for each Input box to deal with changes.

Also, there are 13 input boxes plus 2 slider controls. So it just seemed like the best option for me.

7 minutes ago, SOLVE-SMART said:

You could also try using AdLibRegister to register a function that constantly checks for slider value updates (simple polling). I guess in a GUI each 250ms is totally enough to check and trigger the label change (hint text etc.).

This is a good idea. I've used AdLibRegister before in a few projects. This should do the job, for sure. I'll wait a bit and see what other possible suggestions may come along. Although I feel like sliders aren't used a lot so there may not be too much to reference. I'll do some more reading into it as well.

Best regards as well. Cheers! :)

  • Solution
Posted

For the record, you need to use WM_NOTIFY not WM_COMMAND.  Here a working example how to use $TRBN_THUMBPOSCHANGING on Win11 (didn't test on other OS).

#include <GUIConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", True)

Global Const $TRBN_THUMBPOSCHANGING = -1502
Global Const $tagTRBTHUMBPOSCHANGING = $tagNMHDR & ";dword Pos;int Reason"
Global Const $TBS_NOTIFYBEFOREMOVE = 2048

Global $idSlider

Example()

Func Example()
  Local $hGUI = GUICreate("Example", 500, 500)

  $idSlider = GUICtrlCreateSlider(10, 10, 200, 20, $TBS_NOTIFYBEFOREMOVE)
  GUISetState()

  GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
  WEnd
EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  Local $tChange = DllStructCreate($tagTRBTHUMBPOSCHANGING, $lParam)
  If $tChange.IDfrom = $idSlider And $tChange.Code = $TRBN_THUMBPOSCHANGING Then
    ConsoleWrite("Position = " & $tChange.Pos & @CRLF)
  EndIf
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Posted
3 hours ago, Nine said:

For the record, you need to use WM_NOTIFY not WM_COMMAND.  Here a working example how to use $TRBN_THUMBPOSCHANGING on Win11 (didn't test on other OS).

This is beautiful, fast and accurate. This is exactly what I was hoping for. Thank you for your time, I appreciate it.

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
  • Recently Browsing   0 members

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