Re: How to combine a slider and an edit control in win32lib
- Posted by penpal0andrew May 07, 2009
- 836 views
One detail turned out to be important. And that is that the edit box is always going to have a value between 10 and 99. The actual range is 10 to 70. But this makes it easier to do the user interface. The idea of controls having private values is a good one, but not needed here, and also a global variable would have worked as well. The paint event is the wrong place to place code, since it caused the control to not get painted! The most complicated thing about windows programming is that actions done in processing one event can cause other events to happen. Is there a good source which discusses this?
Here is code which I am happy with now:
procedure SHIFTLEVER_onScroll (integer self, integer event, sequence params)--params is ( int pos ) -- must place value of shift lever into the shift lever number setText (SHIFTLEVER_E, getScrollPos( SHIFTLEVER )) end procedure setHandler( SHIFTLEVER, w32HScroll, routine_id("SHIFTLEVER_onScroll")) procedure SHIFTLEVER_E_onKeyDown (integer self, integer event, sequence params)--params is ( atom scanCode, atom shift ) -- clear the field if full - event is done before the key is added sequence textval -- Get the number typed in to the EditBox textval = getText(self) --This is needed since I am only part way to entering the field if length(textval) < 2 then return end if setText(self,"") end procedure setHandler( SHIFTLEVER_E, w32HKeyDown, routine_id("SHIFTLEVER_E_onKeyDown")) procedure SHIFTLEVER_E_onKeyUp (integer self, integer event, sequence params)--params is ( int scanCode, int shift ) object val sequence textval sequence range -- Get the number typed in to the EditBox val = getNumber(self) textval = getText(self) --This is needed since I am only part way to entering the field if length(textval) < 2 then return end if range = getScrollRange(SHIFTLEVER) if val < range[1] then val = range[1] -- use the lowest allowed. end if if val > range[2] then val = range[2] -- use the highest allowed. end if -- Set the new position of the 'thumb' - does not hurt to always do it setScrollPos(SHIFTLEVER, val) end procedure setHandler( SHIFTLEVER_E, w32HKeyUp, routine_id("SHIFTLEVER_E_onKeyUp")) procedure SHIFTLEVER_E_onLostFocus (integer self, integer event, sequence params)--params is () -- make sure editbox has valid number setText(self, getScrollPos(SHIFTLEVER)) end procedure setHandler( SHIFTLEVER_E, w32HLostFocus, routine_id("SHIFTLEVER_E_onLostFocus"))
The last one is needed for the case when the user only entered none or one digit and went away from the edit box.
Andy