boone301 发表于 2024-6-10 09:11:05

更新滑动条值

大家好
请教大家一个问题,我想更新slider的值,但是一直没有成功,
帮忙看看错在哪里了:


#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_Res_requestedExecutionLevel=None
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <GuiSlider.au3>
#include <MsgBoxConstants.au3>
#include <SliderConstants.au3>



WinWait("Integrated Camera 属性")
WinActivate("Integrated Camera 属性")
WinSetOnTop ("Integrated Camera 属性", "" ,0)
;GUISetState(@SW_ENABLE ,"Integrated Camera 属性")
$msg= _GUICtrlSlider_SetPos(1002,100)
MsgBox(0,"",$msg)


参考例子:
D:\autoit3\Examples\Helpfile\_GUICtrlSlider_SetPos.au3

谢谢
陆迅海

afan 发表于 2024-6-10 10:24:30

1002是内部ID,该参数一般要获取该控件的句柄代入

顽固不化 发表于 2024-6-10 12:14:45

楼主的意思是把一个带有滑动条的窗口上的滑动条进行调节是吧?


我先模拟一个带有滑动条的窗口

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=www.ico
#AutoIt3Wrapper_Outfile=滑动条1.exe
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate('滑动条测试', 514, 97, -1, -1)
$Slider1 = GUICtrlCreateSlider(24, 16, 473, 17)
$Slider2 = GUICtrlCreateSlider(24, 40, 473, 17)
$Slider3 = GUICtrlCreateSlider(24, 64, 473, 17)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd
然后写一个调节滑动条的代码:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=www.ico
#AutoIt3Wrapper_Outfile=设置滑动条.exe
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GuiSlider.au3>
Run('滑动条1.exe')
While 1
        If WinExists('滑动条测试','') Then ExitLoop
WEnd
WinActivate('滑动条测试', '')
Local $HD = WinGetHandle('滑动条测试', '')
Local $HD1 = ControlGetHandle($HD, '', 'msctls_trackbar321')
Local $HD2 = ControlGetHandle($HD, '', 'msctls_trackbar322')
Local $HD3 = ControlGetHandle($HD, '', 'msctls_trackbar323')
_GUICtrlSlider_SetPos($HD1, 20)
Sleep(2000)
_GUICtrlSlider_SetPos($HD2, 55)
Sleep(2000)
_GUICtrlSlider_SetPos($HD3, 80)
Sleep(2000)
WinClose($HD)
Exit



boone301 发表于 2024-6-10 13:51:56

afan 发表于 2024-6-10 10:24
1002是内部ID,该参数一般要获取该控件的句柄代入

你的意思要用句柄吗?
还是没有成功。

afan 发表于 2024-6-10 14:06:59

boone301 发表于 2024-6-10 13:51
你的意思要用句柄吗?
还是没有成功。

句柄是会变的,要获取。3#的虎哥已经举例了 $HD1 = ControlGetHandle($HD, '', 'msctls_trackbar321')

boone301 发表于 2024-6-10 18:07:16

afan 发表于 2024-6-10 14:06
句柄是会变的,要获取。3#的虎哥已经举例了 $HD1 = ControlGetHandle($HD, '', 'msctls_trackbar321') ...

谢谢,在你的帮助下已经解决了:


#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_Res_requestedExecutionLevel=None
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <GuiSlider.au3>
#include <MsgBoxConstants.au3>
#include <SliderConstants.au3>
#include <GuiEdit.au3>
#include <GuiButton.au3>

WinWait("Integrated Camera 属性")
WinActivate("Integrated Camera 属性")
WinSetOnTop ("Integrated Camera 属性", "" ,0)

GUISetState()

$hWnd=ControlGetHandle("Integrated Camera 属性","","");获取控件句柄
_GUICtrlSlider_SetPos($hWnd,200);设置为200

$hWnd=ControlGetHandle("Integrated Camera 属性","","");获取控件句柄
_GUICtrlEdit_SetText($hWnd,200);设置为200

$hWnd=ControlGetHandle("Integrated Camera 属性","","");获取控件句柄
_GUICtrlButton_SetCheck($hWnd,$BST_UNCHECKED);不使用默认值

$hWnd=ControlGetHandle("Integrated Camera 属性","","");获取控件句柄
ControlSend( "Integrated Camera 属性", "", $hWnd, "{ENTER}") ;确认

页: [1]
查看完整版本: 更新滑动条值