如何从滑块控件中读取值?

问题描述 投票:-1回答:1

我使用simplespy.au3在Windows设置窗口中使用_UIA_action()来定位滑块控件。要求用户输入值我发送左右键以使滑块移动。

但我不知道如何获得滑块的当前值。我试过GUICtrlRead()但它不起作用。如何获取滑块控件的当前值?

我的代码:

#RequireAdmin
#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <GuiSlider.au3>
#include <GUIConstants.au3>
#include "UISpy\UIAWrappers\UIAWrappers.au3"

Slider()

Func Slider()
    ;User Input
    $Default = ""
    $input = ""

    While 1
        $input = InputBox("Brightness", "Set Brightness to:", "", " M", -1, -1)
        If @error Then ExitLoop
        If $input < 0 Or $input > 100 Then
            MsgBox(48, "Error!", "Minimum value for brightness is 0 and the Maximum brightness is 100")
            $Default = $input
            ContinueLoop
        ElseIf StringLen($input) > 0 Or $input < 100 Then
            ExitLoop
        EndIf
        If @error = 1 Then
            Exit
        EndIf
    WEnd

    ;Start automation
    Local $iTimeout = 1
    Local $hWnd = WinWait("[Class:Shell_TrayWnd]", "", "[CLASS:Button; INSTANCE:1]")
    ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:1]") ;open the start menu
    Send("Display Settings", 10) ;Type the Display Settings in the start menu
    Sleep(1000)
    Send("{ENTER}")
    AutoItSetOption("MustDeclareVars", 1)
    Local $oP2 = _UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Settings;controltype:=UIA_WindowControlTypeId;class:=ApplicationFrameWindow", $treescope_children)
    _UIA_Action($oP2, "setfocus")
    Local $oP1 = _UIA_getObjectByFindAll($oP2, "Title:=Settings;controltype:=UIA_WindowControlTypeId;class:=Windows.UI.Core.CoreWindow", $treescope_children)
    _UIA_Action($oP1, "setfocus")
    Local $oP0 = _UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_PaneControlTypeId;class:=ScrollViewer", $treescope_children)
    ;First find the object in the parent before you can do something
;   $oUIElement=_UIA_getObjectByFindAll("Changebrightness.mainwindow", "title:=Change brightness;ControlType:=UIA_SliderControlTypeId", $treescope_subtree)
    Local $oUIElement = _UIA_getObjectByFindAll($oP0, "title:=Change brightness;ControlType:=UIA_SliderControlTypeId", $treescope_subtree)
    _UIA_action($oUIElement, "setfocus")

    Send("{LEFT $input}"`enter code here`)

    Sleep(1000)
    Local $value = GUICtrlRead($oUIElement)
    MsgBox($MB_SYSTEMMODAL, "", "Brightness is at: " & $value, $iTimeout)
    Local $setValue = GUICtrlSetData($oUIElement, 50)

    ;UI for verification
    MsgBox(0, "Change Brightness", "Brightness Changed.", $iTimeout)
    Sleep(1000)
    WinClose("Settings") ;Close the active window
EndFunc   ;==>Slider
user-interface windows-10 autoit
1个回答
0
投票

不要操纵滑块。请改用WinAPI:_WinAPI_SetDeviceGammaRamp

© www.soinside.com 2019 - 2024. All rights reserved.