nicdev007 Posted April 19, 2012 Share Posted April 19, 2012 Hi All, I have created a program that searches a sqlite database and it works great thanks to all the excellent posts I have found from the community. In essence, as the slider is moved, at every movement it queries the Db table and returns a set of variables. The problem here is that the DB does not have corresponding values for each 'tick', thus I want the slider to jump from one tick to the next. For example if I had a tick at 5, 40, 70, and 90 as soon as I move from the tick "0" to the right, I want the mouse to jump to "5" thus skipping 2,3 and 4. Here is a watered down example of what I have done to date without the Sql bits (I added the 'moving right' and 'moving left' messages to show the intent): expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiSlider.au3> #include <WindowsConstants.au3> #include <GuiSlider.au3> #include <SliderConstants.au3> #include <GuiEdit.au3> Global $TicArray[5] = [5,30,50,70,90] Local $oldpos = MouseGetPos(0) ; Create GUI GUICreate("Slider Set Tic", 400, 296) $hSlider = GUICtrlCreateSlider(2, 2, 396, 20, BitOR($TBS_TOOLTIPS, $TBS_BOTH, $TBS_ENABLESELRANGE)) $edit = GUICtrlCreateEdit("--",50, 50) GUISetState() _GUICtrlSlider_ClearTics($hSlider) ; Set Tics ArrayTicks($TicArray, $hSlider) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $hSlider While $hSlider local $mPos = MouseGetPos(0) If $oldpos < $mPos Then _GUICtrlEdit_SetText($edit, "moving right") ;$oldpos = $mPos ;ExitLoop ElseIf $oldpos > $mPos Then _GUICtrlEdit_SetText($edit, "moving left") ;$oldpos = $mPos ;ExitLoop EndIf Sleep(250) $oldpos = $mPos ExitLoop WEnd EndSwitch WEnd ; Create array tics Func ArrayTicks($array, $CurrentSlider) Local $iMax=UBound($array), $i For $i = 0 to $iMax - 1 _GUICtrlSlider_SetTic($CurrentSlider, $array[$i]) Next EndFunc Any help will be appreciated; Thank you Regards nicdev Life is too short to worry about the things you don't have or cannot do ... So if you don't know how to do it - Learn it! Don't be afraid to ask for help ... Link to comment Share on other sites More sharing options...
BrewManNH Posted April 19, 2012 Share Posted April 19, 2012 Here's one way to do it. It jumps from one tick to the next as you move left and right. There is an issue if you drag it with the mouse, rather than clicking on the slider's thumb and scrolling with the mouse wheel or hitting the left and right arrow keys, it will jump around like a cat on a hot tin roof. Probably an easy fix, but this is only a demo anyways. expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiSlider.au3> #include <WindowsConstants.au3> #include <GuiSlider.au3> #include <SliderConstants.au3> #include <GuiEdit.au3> Global $TicArray[5] = [5, 30, 50, 70, 90] Local $oldpos = 0 ; Create GUI GUICreate("Slider Set Tic", 400, 296) $hSlider = GUICtrlCreateSlider(2, 2, 396, 20, BitOR($TBS_TOOLTIPS, $TBS_BOTH, $TBS_ENABLESELRANGE)) $edit = GUICtrlCreateEdit("--", 50, 50) GUISetState() _GUICtrlSlider_ClearTics($hSlider) ; Set Tics ArrayTicks($TicArray, $hSlider) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch Global $SliderPos = GUICtrlRead($hSlider) If $SliderPos > $oldpos Then GUICtrlSetData($edit, "moving right") Switch GUICtrlRead($hSlider) Case 1 To 5 GUICtrlSetData($hSlider, 5) Case 6 To 30 GUICtrlSetData($hSlider, 30) Case 31 To 50 GUICtrlSetData($hSlider, 50) Case 51 To 70 GUICtrlSetData($hSlider, 70) Case 71 To 90 GUICtrlSetData($hSlider, 90) Case 91 To 100 GUICtrlSetData($hSlider, 100) Case Else GUICtrlSetData($hSlider, 0) EndSwitch $oldpos = GUICtrlRead($hSlider) ElseIf $SliderPos < $oldpos Then GUICtrlSetData($edit, "moving left") Switch GUICtrlRead($hSlider) Case 0 To 4 GUICtrlSetData($hSlider, 0) Case 5 To 29 GUICtrlSetData($hSlider, 5) Case 30 To 49 GUICtrlSetData($hSlider, 30) Case 50 To 69 GUICtrlSetData($hSlider, 50) Case 70 To 89 GUICtrlSetData($hSlider, 70) Case 90 To 99 GUICtrlSetData($hSlider, 90) Case Else GUICtrlSetData($hSlider, 100) EndSwitch $oldpos = GUICtrlRead($hSlider) EndIf WEnd ; Create array tics Func ArrayTicks($array, $CurrentSlider) Local $iMax = UBound($array), $i For $i = 0 To $iMax - 1 _GUICtrlSlider_SetTic($CurrentSlider, $array[$i]) Next EndFunc ;==>ArrayTicks nicdev007 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
nicdev007 Posted April 19, 2012 Author Share Posted April 19, 2012 Hi BrewManNH,Thanks for the reply, and BTW a great idea of how to do it. I never thought of it in that way. I'll try it tomorrow and let you know how it turns out :-) I'm sure we can tame the cat on the hot roof ;-) In think switching on the x -> y of the GUICtrlRead($hSlider) is a good approach.Thanks againGoodnightnicdev Life is too short to worry about the things you don't have or cannot do ... So if you don't know how to do it - Learn it! Don't be afraid to ask for help ... Link to comment Share on other sites More sharing options...
BrewManNH Posted April 19, 2012 Share Posted April 19, 2012 Here's a new version of the script that uses Windows messaging to read that the control is being moved instead of the GUIGetMsg function, this works pretty good without the jumping around. expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiSlider.au3> #include <WindowsConstants.au3> #include <GuiSlider.au3> #include <SliderConstants.au3> #include <GuiEdit.au3> GUIRegisterMsg($WM_HSCROLL, "WM_H_Slider") Global $TicArray[5] = [5, 30, 50, 70, 90] Local $oldpos = 0 ; Create GUI GUICreate("Slider Set Tic", 400, 296) $hSlider = GUICtrlCreateSlider(2, 2, 396, 20, BitOR($TBS_TOOLTIPS, $TBS_BOTH, $TBS_ENABLESELRANGE)) $edit = GUICtrlCreateEdit("--", 50, 50) GUISetState() _GUICtrlSlider_ClearTics($hSlider) ; Set Tics ArrayTicks($TicArray, $hSlider) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ; Create array tics Func ArrayTicks($array, $CurrentSlider) Local $iMax = UBound($array), $i For $i = 0 To $iMax - 1 _GUICtrlSlider_SetTic($CurrentSlider, $array[$i]) Next EndFunc ;==>ArrayTicks Func WM_H_Slider($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $iValue If $lParam = GUICtrlGetHandle($hSlider) Then Local $SliderPos = GUICtrlRead($hSlider) If $SliderPos > $oldpos Then GUICtrlSetData($edit, "moving right") Switch GUICtrlRead($hSlider) Case 1 To 5 GUICtrlSetData($hSlider, 5) Case 6 To 30 GUICtrlSetData($hSlider, 30) Case 31 To 50 GUICtrlSetData($hSlider, 50) Case 51 To 70 GUICtrlSetData($hSlider, 70) Case 71 To 90 GUICtrlSetData($hSlider, 90) Case 91 To 100 GUICtrlSetData($hSlider, 100) Case Else GUICtrlSetData($hSlider, 0) EndSwitch $oldpos = GUICtrlRead($hSlider) ElseIf $SliderPos < $oldpos Then GUICtrlSetData($edit, "moving left") Switch GUICtrlRead($hSlider) Case 0 To 4 GUICtrlSetData($hSlider, 0) Case 5 To 29 GUICtrlSetData($hSlider, 5) Case 30 To 49 GUICtrlSetData($hSlider, 30) Case 50 To 69 GUICtrlSetData($hSlider, 50) Case 70 To 89 GUICtrlSetData($hSlider, 70) Case 90 To 99 GUICtrlSetData($hSlider, 90) Case Else GUICtrlSetData($hSlider, 100) EndSwitch $oldpos = GUICtrlRead($hSlider) EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_H_Slider nicdev007 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Zedna Posted April 19, 2012 Share Posted April 19, 2012 (edited) I think it could be done by some more elegant way through events/messages/API functions.Now I haven't time to experiment with it but maybe I will try later because it seems like interesting challenge :-)Here is link to MSDN reference for start:Slider Notification Messageshttp://msdn.microsoft.com/en-us/library/ekx9yz55%28v=vs.80%29.aspxSlider Control Member Functionshttp://msdn.microsoft.com/en-US/library/4ywwzk3e%28v=vs.80%29.aspxAbout Trackbar Controlshttp://msdn.microsoft.com/en-us/library/...0149%28v=vs.85%29.aspx#TrackbaTrackbar Control Referencehttp://msdn.microsoft.com/en-us/library/windows/desktop/ff486103%28v=vs.85%29.aspxEDIT:I think TBM_SETTIC message is solution - with this you can add your ticks at specified positionshttp://msdn.microsoft.com/en-us/library/windows/desktop/bb760236%28v=vs.85%29.aspxEDIT2: sorry I didn't read carefully all postsBrewManNH in his last did what I had in my mind Edited April 19, 2012 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
BrewManNH Posted April 20, 2012 Share Posted April 20, 2012 My only issue with that last entry is it works good when you drag it with the mouse, but it stutters slightly when you use the mouse scroll wheel. It's slight, but noticeable if you scroll the wheel slow enough. I can get one movement method to work well, but it messes up the other method depending upon which one I focused on. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
nicdev007 Posted April 20, 2012 Author Share Posted April 20, 2012 (edited) Here's a new version of the script that uses Windows messaging to read that the control is being moved instead of the GUIGetMsg function, this works pretty good without the jumping around.Hi again, and thanks for the repost :-) I tried your last code, and frankly it really works well. I am not a "mouse roller" on sliders, thus I would probably not even have noticed it. I'm still playing a bit with it to see if I can get it a bit more stable on the mousewheel.CiaonicdevEDIT: I think it jumps around a lot because we maybe need to update the mouse pointer position at the same time :-) Edited April 20, 2012 by nicdev007 Life is too short to worry about the things you don't have or cannot do ... So if you don't know how to do it - Learn it! Don't be afraid to ask for help ... Link to comment Share on other sites More sharing options...
nicdev007 Posted April 22, 2012 Author Share Posted April 22, 2012 My only issue with that last entry is it works good when you drag it with the mouse, but it stutters slightly when you use the mouse scroll wheel. It's slight, but noticeable if you scroll the wheel slow enough. I can get one movement method to work well, but it messes up the other method depending upon which one I focused on. Just one small adjustment made it work like a charm :-) No more erratic "cat like" jumping round. thanks for your insights BrewmanNH!! expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiSlider.au3> #include <WindowsConstants.au3> #include <GuiSlider.au3> #include <SliderConstants.au3> #include <GuiEdit.au3> GUIRegisterMsg($WM_HSCROLL, "WM_H_Slider") Global $TicArray[5] = [5, 30, 50, 70, 90] Local $oldpos = 0 ; Create GUI GUICreate("Slider Set Tic", 400, 296) $hSlider = GUICtrlCreateSlider(2, 2, 396, 20, BitOR($TBS_TOOLTIPS, $TBS_BOTH, $TBS_ENABLESELRANGE)) $edit = GUICtrlCreateEdit("--", 50, 50) GUISetState() _GUICtrlSlider_ClearTics($hSlider) ; Set Tics ArrayTicks($TicArray, $hSlider) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ; Create array tics Func ArrayTicks($array, $CurrentSlider) Local $iMax = UBound($array), $i For $i = 0 To $iMax - 1 _GUICtrlSlider_SetTic($CurrentSlider, $array[$i]) Next EndFunc ;==>ArrayTicks Func WM_H_Slider($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $iValue If $lParam = GUICtrlGetHandle($hSlider) Then Local $SliderPos = GUICtrlRead($hSlider) If $SliderPos > $oldpos Then GUICtrlSetData($edit, "moving right") Switch GUICtrlRead($hSlider) Case 1 To 5 GUICtrlSetData($hSlider, 5) Case 6 To 30 GUICtrlSetData($hSlider, 30) Case 31 To 50 GUICtrlSetData($hSlider, 50) Case 51 To 70 GUICtrlSetData($hSlider, 70) Case 71 To 90 GUICtrlSetData($hSlider, 90) Case 91 To 100 GUICtrlSetData($hSlider, 100) Case Else GUICtrlSetData($hSlider, 0) EndSwitch $oldpos = $SliderPos ; <-- Changed here ElseIf $SliderPos < $oldpos Then GUICtrlSetData($edit, "moving left") Switch GUICtrlRead($hSlider) Case 0 To 4 GUICtrlSetData($hSlider, 0) Case 5 To 29 GUICtrlSetData($hSlider, 5) Case 30 To 49 GUICtrlSetData($hSlider, 30) Case 50 To 69 GUICtrlSetData($hSlider, 50) Case 70 To 89 GUICtrlSetData($hSlider, 70) Case 90 To 99 GUICtrlSetData($hSlider, 90) Case Else GUICtrlSetData($hSlider, 100) EndSwitch $oldpos = $SliderPos ; <-- Changed here EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_H_Slider Now putting the idea into the main project to see if the Db queries run as smoothly ;-) Thanks again for your insights Best nicdev Life is too short to worry about the things you don't have or cannot do ... So if you don't know how to do it - Learn it! Don't be afraid to ask for help ... Link to comment Share on other sites More sharing options...
Edano Posted June 10, 2013 Share Posted June 10, 2013 i had the same problem and i solved it in a different, more "brutal" way. i placed one little button with arrow at each end of the slider. this lets the user decide if he wants to use the slider or the tick step button. E. [color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font] Link to comment Share on other sites More sharing options...
UEZ Posted June 10, 2013 Share Posted June 10, 2013 Here a another way using windows messaging.expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiSlider.au3> #include <WindowsConstants.au3> #include <GuiSlider.au3> #include <GuiEdit.au3> Global $TicArray[7] = [0, 5, 30, 50, 70, 90, 100] Local $oldpos = MouseGetPos(0) ; Create GUI $hGUI = GUICreate("Slider Set Tic", 400, 296) $iSlider = GUICtrlCreateSlider(2, 2, 396, 20, BitOR($TBS_TOOLTIPS, $TBS_BOTH, $TBS_ENABLESELRANGE)) $hSlider = GUICtrlGetHandle($iSlider) $edit = GUICtrlCreateEdit("--", 50, 50) GUISetState() _GUICtrlSlider_ClearTics($iSlider) ; Set Tics ArrayTicks($TicArray, $iSlider) Global $iSliderPos = 0, $iPos = 0, $iPosOld = -1, $bUpdate = False GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit ;~ Case $iSlider ;~ While $iSlider ;~ Local $mPos = MouseGetPos(0) ;~ If $oldpos < $mPos Then ;~ _GUICtrlEdit_SetText($edit, "moving right") ;~ ;$oldpos = $mPos ;~ ;ExitLoop ;~ ElseIf $oldpos > $mPos Then ;~ _GUICtrlEdit_SetText($edit, "moving left") ;~ ;$oldpos = $mPos ;~ ;ExitLoop ;~ EndIf ;~ Sleep(250) ;~ $oldpos = $mPos ;~ ExitLoop ;~ WEnd EndSwitch WEnd Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam Local $i, $c, $d = 0xFFFFFF, $p Switch $lParam Case $hSlider $iPos = _GUICtrlSlider_GetPos($hSlider) For $i = 0 To UBound($TicArray) - 1 $c = Abs(1 - (($TicArray[$i] + 1) / ($iPos + 1))) If $c < $d Then $d = $c $p = $i EndIf Next _GUICtrlSlider_SetPos($hSlider, $TicArray[$p]) EndSwitch Return "GUI_RUNDEFMSG" EndFunc ;==>WM_HSCROLL ; Create array tics Func ArrayTicks($array, $CurrentSlider) Local $iMax = UBound($array), $i For $i = 0 To $iMax - 1 _GUICtrlSlider_SetTic($CurrentSlider, $array[$i]) Next EndFunc ;==>ArrayTicks I know that the arrow keys are not working this way. Maybe I will find a solution for this...Br,UEZ mesale0077, pica and abberration 3 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
pica Posted November 25, 2013 Share Posted November 25, 2013 UEZ! Thank you so much. This is what I exactly looking for. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now