Slider(滑动条)实时显示例子
本帖最后由 风行者 于 2011-6-4 09:33 编辑刚好用到,搜索论坛居然没搜到相关例子,后来查msdn解决
方便以后查看,需要的就拿去吧,代码如下:
Global Const $WM_HSCROLL = 0x0114
$Form1 = GUICreate("滑动条实时显示", 314, 120, 192, 124)
$Label1 = GUICtrlCreateLabel("当前数值:50", 16, 24, 131, 28)
GUICtrlSetFont(-1, 16, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Slider1 = GUICtrlCreateSlider(8, 72, 297, 33)
GUICtrlSetLimit(-1,100,0)
GUICtrlSetData(-1,50)
GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")
GUISetState()
Do
Until GUIGetMsg()=-3
Func WM_HSCROLL($Hwnd, $iMsg, $Wparam, $iLparam)
$nNotifyCode = BitShift($Wparam, 16);高位为控件标识
$nID = BitAND($Wparam, 0x000FFFF) ;低位为数值
Switch $nID
Case $Slider1
GUICtrlSetData($Label1, "当前数值:" &$nNotifyCode)
EndSwitch
EndFunc ;==>WM_HSCROLL 我先收下了..以后应该用的着...谢谢楼主提供了 貌似没有按住时实时显示、点刻度尺也没变化~ 稍稍改了下Global Const $WM_HSCROLL = 0x0114
GUICreate("滑动条实时显示", 314, 120)
$Label1 = GUICtrlCreateLabel('50', 16, 24, 131, 28)
GUICtrlSetFont(-1, 16, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Slider1 = GUICtrlCreateSlider(8, 72, 297, 33)
GUICtrlSetLimit(-1, 100, 0)
$vS = 50
GUICtrlSetData(-1, $vS)
GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")
GUISetState()
Do
Until GUIGetMsg() = -3
Func WM_HSCROLL($Hwnd, $iMsg, $Wparam, $iLparam)
Switch BitAND($Wparam, 0x000FFFF)
Case 5
$vS = BitShift($Wparam, 16)
GUICtrlSetData($Label1, $vS)
Case 2, 3
GUICtrlSetData($Label1, GUICtrlRead($Slider1))
EndSwitch
EndFunc ;==>WM_HSCROLL
学习了,谢谢lz分享 楼主是缘鸟的管理员把 在官网有,不过不太好搜索,感谢AFAN提供的例子 向楼主源码精神致敬 路过留名,以后备用,如果能把两者功能合一就更强大了 楼主的确实有些问题:不是实时显示, 只有拖动停止后才会显示.
afan 大侠的虽然实时显示了, 但是并没有判断是哪个Slider控件的消息, 这样如果一个界面有多个Slider控件, 就会出问题.
正好我用到这个, 顺便把我改动后的发出来.
Global Const $WM_HSCROLL = 0x0114
Global $Slider, $hSlider, $Label
GUICreate('滑动条实时显示', 350, 120)
$Slider = GUICtrlCreateSlider(8, 20, 297, 33)
$hSlider = GUICtrlGetHandle(-1)
GUICtrlSetLimit(-1, 100, 0)
$Label = GUICtrlCreateLabel('0', 313, 24, 100, 28)
GUICtrlSetFont(-1, 16, 800)
$Slider = GUICtrlCreateSlider(8, 72, 297, 33)
$hSlider = GUICtrlGetHandle(-1)
GUICtrlSetLimit(-1, 100, 0)
$Label = GUICtrlCreateLabel('0', 313, 75, 100, 28)
GUICtrlSetFont(-1, 16, 800)
GUIRegisterMsg($WM_HSCROLL, 'WM_HSCROLL')
GUISetState()
Do
Until GUIGetMsg() = -3
Func WM_HSCROLL($Hwnd, $Msg, $Wparam, $Lparam)
Switch $Lparam
Case $hSlider
GUICtrlSetData($Label, GUICtrlRead($Slider))
Case $hSlider
GUICtrlSetData($Label, GUICtrlRead($Slider))
EndSwitch
EndFunc ;==>WM_HSCROLL
受教了 看了你们的代码 又让我学到了window消息 学习一下,论坛越发的好 先收下了,很好的例子! 呵收藏着了,不错的东西 利害啊!!!学习了 谢谢共享,支持楼主
页:
[1]
2