RE: Moving the Cursor
- Posted by Phil Russell <pg_russell at lineone.net> Aug 13, 2002
- 533 views
Jon/Don, Congrats to Don for figuring out how to keep the caret position. Just to give you the choice I have amended my version to do the same thing. As an info source, I can recommend Charles Petzold's book on programming the windows API. Online, I get a lot of my win32 info from the Microsoft developer site: http://msdn.microsoft.com/library On this occasion I came across the original EM_SETSEL trick on the following site: http://www.thecodeproject.com This is a C++/C# site but it has a lot of useful ideas if you are willing to decipher the code. HTH Phil ===================== -- Set caret position whilst editing -- Phil Russell August 2002 include win32lib.ew without warning with trace integer Pos constant Win = create( Window, "Caret Position", 0, Default, Default, 200, 100, 0 ), Sle = create( EditText, "", Win, 10, 20, 120, 20, 0 ) function removeDashes( sequence line) sequence new_line new_line = {} for i = 1 to length( line) do if line[i] != '-' then new_line &= line[i] else Pos -= 1 end if end for return new_line end function function addDashes( sequence text) integer length_text length_text = length( text) if length_text > 3 then text = text[1..3] & '-' & text[4..length_text] Pos += 1 end if if length_text > 7 then text = text[1..7] & '-' & text[8..length_text+1] Pos += 1 end if return text end function -- Process events after windows handling is completed procedure after_event (integer self, integer event, sequence parms) atom key, junk, msg msg = parms[1] key = parms[2] -- Amend text after wm_char has been processed if msg=WM_CHAR then -- Get current caret position Pos = lo_word( sendMessage(self, EM_GETSEL, 0, 0 ) ) -- Format text setText(self, addDashes(removeDashes(getText(self)))) -- Reset caret position junk = sendMessage(self, EM_SETSEL, Pos, Pos ) end if end procedure setHandler(Sle, w32HAfterEvent, routine_id("after_event")) WinMain( Win, Normal ) =====================