LxP Posted December 4, 2005 Posted December 4, 2005 Hi all,I have a trackbar on a window that accepts any whole-numbered value from 3 to 100. My wish is to write a UDF that takes a single integer and sets that trackbar appropriately:SetLength($Pct)I thought I could get away with using the _GUICtrlSliderSetPos() function (which does indeed move the trackbar), however the label next to the trackbar doesn't update and the program does not become aware of the change in any way.I've resorted to writing the following code which does the job. It works nicely enough, but can anyone offer any improvements? Perhaps a tip on getting _GUICtrlSliderSetPos() to be noticed properly?expandcollapse popup; Adjust the length slider on the options page ; Returns FALSE if an error occurs; TRUE otherwise ; @Error -> 1 if a valid percentage (3..100) isn't given ; @Error -> 2 if the necessary page couldn't be made visible Func SetLength($Pct) If Not IsInt($Pct) Or $Pct < 3 Or $Pct > 100 Then SetError(1) Return False EndIf SetVisiblePage($OPTS_PAGE) If @Error Then SetError(2) Return False EndIf Local $Send If $Pct <= 51 Then $Send = '{HOME}'; 3% If $Pct = 3 Then ; No more ElseIf $Pct <= 13 Then $Send &= '{RIGHT ' & ($Pct - 3) & '}' Else $Send &= '{PGDN}'; 22% If $Pct < 22 Then $Send &= '{LEFT ' & (22 - $Pct) & '}' ElseIf $Pct = 22 Then ; No more ElseIf $Pct <= 31 Then $Send &= '{RIGHT ' & ($Pct - 22) & '}' Else $Send &= '{PGDN}'; 41% If $Pct < 41 Then $Send &= '{LEFT ' & (41 - $Pct) & '}' ElseIf $Pct > 41 Then $Send &= '{RIGHT ' & ($Pct - 41) & '}' EndIf EndIf EndIf Else $Send = '{END}'; 100% If $Pct = 100 Then ; No more ElseIf $Pct >= 91 Then $Send &= '{LEFT ' & (100 - $Pct) & '}' Else $Send &= '{PGUP}'; 81% If $Pct > 81 Then $Send &= '{RIGHT ' & ($Pct - 81) & '}' ElseIf $Pct = 81 Then ; No more ElseIf $Pct >= 72 Then $Send &= '{LEFT ' & (81 - $Pct) & '}' Else $Send &= '{PGUP}'; 62% If $Pct > 62 Then $Send &= '{RIGHT ' & ($Pct - 62) & '}' ElseIf $Pct < 62 Then $Send &= '{LEFT ' & (62 - $Pct) & '}' EndIf EndIf EndIf EndIf Local $PrevOpt = Opt('SendKeyDelay', 1) ControlSend(GetPageHandle($OPTS_PAGE), '', 'msctls_trackbar321', $Send) Opt('SendKeyDelay', $PrevOpt) Return True EndFunc
LxP Posted December 4, 2005 Author Posted December 4, 2005 Well, perhaps this might do the trick:Func SetLength($Pct) If Not IsInt($Pct) Or $Pct < 3 Or $Pct > 100 Then SetError(1) Return False EndIf SetVisiblePage($OPTS_PAGE) If @Error Then SetError(2) Return False EndIf Local $SetValue, $SendValue If $Pct <= 51 Then $SetValue = $Pct + 1 $SendValue = '{LEFT}' Else $SetValue = $Pct - 1 $SendValue = '{RIGHT}' EndIf Local $OptsHandle = GetPageHandle($OPTS_PAGE) _GUICtrlSliderSetPos(ControlGetHandle($OptsHandle, '', 'msctls_trackbar321'), $SetValue) Local $PrevOpt = Opt('SendKeyDelay', 1) ControlSend($OptsHandle, '', 'msctls_trackbar321', $SendValue) Opt('SendKeyDelay', $PrevOpt) Return True EndFuncThe code above asks _GUICtrlSliderSetPos() to set the slider one value off the mark and then issues a single key with ControlSend(), which guarantees that the program (since it has to process the key) is aware of the change to the trackbar.That's the plan anyway. Hopefully when I test it, things work as nicely as before.
Valuater Posted December 4, 2005 Posted December 4, 2005 (edited) this is the part that i was thinking Else $SetValue = $Pct - 1 $SendValue = '{RIGHT}' EndIf but -3 instead of -1 and pressing "Home" first 8) Edited December 4, 2005 by Valuater
LxP Posted December 4, 2005 Author Posted December 4, 2005 I suppose that it ultimately depends on the effect that each keypress will have. In my case sending {LEFT} or {RIGHT} will decrease or increase the value of the trackbar by precisely 1. Thanks for your input!
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