1. RE: Moving the Cursor

Jon Snyder wrote:
> 
> I'm trying to create an input field for a phone number that will 
> automatically add the dashes while the number is being input.  The 
> problem is, is that after calling setText() the cursor is put at the 
> begining of the edit box so the number is entered backwards.  Is there a 
> 
> way to move the cursor to the end of the edit box?
> 
> Here is the code i have so far...
> 
> 
> function removeDashes( sequence line)
>     sequence new_line
>     new_line = {}
>     for i = 1 to length( line) do
> 	if line[i] != '-' then
> 	    new_line &= line[i]
> 	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]
>     end if
>     if length_text > 8 then
> 	text = text[1..7] & '-' & text[8..length_text+1]
>     end if
> 
>     return text
> end function
> 
> boolean changing
> changing = FALSE
> procedure change_edit()
>     
>     if not changing then
> 	changing = TRUE
> 	setText( NUMBER_EDIT,  addDashes( removeDashes( getText( NUMBER_EDIT) ) 
> 
> ))
> 	changing = FALSE
>     end if
> end procedure
> onChange[ NUMBER_EDIT] = routine_id( "change_edit")
> 
> 


hi Jon,
still learning the windows programming myself.
sorry i have no code to show you. but how about..
an edit box for each part of the phone number, placed beside one another 
making it look like one box.
as each part of the phone number is keyed then the appropriate box is 
used by the code. an edit box could be the hyphen all by itself in 
between the other parts of the phone number. would work if area code is 
entered. if 3 numbers are keyed then they are assigned to the first box 
then the remainder is assigned to the box after the hyphen.

later
rudy toews

lotterywars

new topic     » topic index » view message » categorize

2. RE: Moving the Cursor

rudy toews wrote:
> 
> Jon Snyder wrote:
> > 
> > I'm trying to create an input field for a phone number that will 
> > automatically add the dashes while the number is being input.  The 
> > problem is, is that after calling setText() the cursor is put at the 
> > begining of the edit box so the number is entered backwards.  Is there a 
> > 
> > 
> > way to move the cursor to the end of the edit box?
> > 
> > Here is the code i have so far...
> > 
> > 
> > function removeDashes( sequence line)
> >     sequence new_line
> >     new_line = {}
> >     for i = 1 to length( line) do
> > 	if line[i] != '-' then
> > 	    new_line &= line[i]
> > 	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]
> >     end if
> >     if length_text > 8 then
> > 	text = text[1..7] & '-' & text[8..length_text+1]
> >     end if
> > 
> >     return text
> > end function
> > 
> > boolean changing
> > changing = FALSE
> > procedure change_edit()
> >     
> >     if not changing then
> > 	changing = TRUE
> > 	setText( NUMBER_EDIT,  addDashes( removeDashes( getText( NUMBER_EDIT) ) 
> > 
> > 
> > ))
> > 	changing = FALSE
> >     end if
> > end procedure
> > onChange[ NUMBER_EDIT] = routine_id( "change_edit")
> > 
> > 
> hi Jon,
> still learning the windows programming myself.
> sorry i have no code to show you. but how about..
> an edit box for each part of the phone number, placed beside one another 
> 
> making it look like one box.
> as each part of the phone number is keyed then the appropriate box is 
> used by the code. an edit box could be the hyphen all by itself in 
> between the other parts of the phone number. would work if area code is 
> entered. if 3 numbers are keyed then they are assigned to the first box 
> then the remainder is assigned to the box after the hyphen.
> 
> later
> rudy toews
> 
> lotterywars
> 

I thought about doing that, but i don't like that.  I have a box that is 
the default area code and then a box that takes either a 7 digit number 
or a 10 digit number.  Even with your solution i would need to know how 
to move the cursor to the end of the edit box because if the backspace 
key was hitat the begining of the second box, the cursor should move to 
the end of the first box.

--jon snyder

new topic     » goto parent     » topic index » view message » categorize

3. RE: Moving the Cursor

Dan,

Thanks. That's a good idea, but I think that there has to be a better 
way.  

The main reason that i didn't want to have different text boxes was to 
allow the flexibility of using a default area code or just entering 10 
digits into the edit box.  If you noticed my "addDashes()" routine 
formated a 7 digit number like this, 123-4567, and a 10 digit number 
like this, 123-456-7890.  If just 7 digits were entered it would use the 
default area code as the area code.  I realize you could do this with 
multiple edit boxes, but i think that would be more mess than its worth.

There had to be some c routine that would be able to move the cursor to 
the end of an edit box.  Would it be that hard just to link to some c 
routine that would do this?

I also thought of the possiblity of just fooling the key handler into 
thinking that the "End" button was pressed.  I don't know how to even 
start doing something like that.

--Jon Snyder

Dan Moyer wrote:
> Jon,
> 
> Here's an attempt to be helpful; it does *some* of what you want, but 
> not
> exactly always, maybe it could be fixed up, or at least prompt a better
> attempt?
> 
> It uses the "3" edit boxes you *didn't* like, backspaces correctly 
> *some* of
> the time to the *end* of the previous number field (& *doesn't* other 
> times,
> moves to *beginning* of previous instead), & moves from the prefix to 
> the
> last part of the number on filling in 3 digits.  I didn't put the "-"
> between the boxes, nor make the area code move to prefix after filling 
> in 3
> there.  It also uses the "unlink the handler" idea that Don Phillips
> suggested, though I had to use a "dummy" procedure to do it right, "0"
> didn't work for me.
> 
> You could argue that it doesn't actually force positioning of the 
> cursor, &
> you'd be right.  :(   This simple problem seems harder (to me) than it
> sounds!  Maybe there's a simpler solution we're overlooking?
> 
> 
> Dan Moyer
> 
> 
> ----------------------------------------------------------------------------
> 
> -----------
> include Win32Lib.ew
> without warning
> 
> ----------------------------------------------------------------------------
> 
> ----
> constant Window1 = create( Window, "Window1", 0, Default, Default, 400, 
> 300,
> 0 )
> constant Prefix  = create( EditText, "", Window1, 52, 56, 30, 28, 0 )
> constant AreaCode = create( EditText, "123", Window1, 15, 56, 30, 28, 0 
> )
> global constant NUMBER_EDIT = create( EditText, "", Window1, 92, 56, 60, 
> 28,
> 0 )
> 
> constant
>     aStatusBar      = create( StatusBar, "", Window1, 0, 25, 20, 20, 0)
> 
> -----------------------------------------------
> setFocus(Prefix)  -- didn't seem to work, had to re-do the order of 
> creation
>                   -- to make 2nd edit box (Prefix) start out with focus, not
> sure why
> 
> procedure dummy()  -- to unlink handler when changing text in edit boxes
> end procedure
> 
> sequence TheNumber  -- actually just the last part of the number
> sequence ThePrefix
> -------------------------------------------------
> 
> procedure change_prefix()
> 
>   ThePrefix = getText(Prefix)
>   setText(aStatusBar, ThePrefix)
>   if length(ThePrefix) = 3 then
>       setFocus(NUMBER_EDIT)
>   elsif length(ThePrefix) > 3 then
>     onChange[ Prefix] = routine_id("dummy")  -- unlink handler
>     setText(Prefix, ThePrefix[1..3])
>     setFocus(NUMBER_EDIT)
>     -- following needed 4..length; just 4 by itself gave the ascii?
>     setText(NUMBER_EDIT, ThePrefix[4..length(ThePrefix)] )
>     setFocus(NUMBER_EDIT)
>     onChange[ Prefix] = routine_id( "change_prefix") -- relink handler
>   end if
> end procedure
> onChange[ Prefix] = routine_id( "change_prefix")
> 
> 
> --  CHECK FOR BACKSPACE KEY IN THE EDIT BOXES
> --  IF EDIT BOX EMPTY, MOVE BACK TO PREVIOUS EDIT BOX:
> 
> procedure onKeyDown_NUMBER_EDIT(int keyCode, int shift )
>   if keyCode = VK_BACK and length(getText(NUMBER_EDIT)) = 0 then
>      setFocus(Prefix)
>   end if
> 
> end procedure
> onKeyDown[NUMBER_EDIT] = routine_id("onKeyDown_NUMBER_EDIT")
> 
> procedure onKeyDown_Prefix(int keyCode, int shift )
>   if keyCode = VK_BACK and length(getText(Prefix)) = 0 then
>      setFocus(AreaCode)
>   end if
> 
> end procedure
<snip>

new topic     » goto parent     » topic index » view message » categorize

4. RE: Moving the Cursor

Yo Yo Yo,
Hey to all the people on here that know me.  Looks like I finally joined 
the List. :P

To thoes of ya who don't know me, You'll soon get to know me. blink

Anyways, Regarding the Moving the Cursor Problem.  I have a easy 
solution to that.  Intercept Key Strokes, and look for the Tab Button to 
be pushed, or the Enter button to be pushed.  Use MoveZOrder to move to 
the next Control if the Input Key Stroke is VK_RETURN, then use 
getText(), and setText() to get and format the Phone Number.

Easily Done:

procedure onKeyDown_PhoneInput(integer id, integer event, sequence 
param)
  sequence phone_num
  if param[1] = VK_TAB or param[1] = VK_RETURN then
     phone_num = getText(PhoneInput)
     phone_num = "(" & phone_num[1..3] & ") " & phone_num[4..6] & "-" & 
phone_num[7..length(phone_num)]
     if param[1] = VK_RETURN then
        moveZOrder(nextControl)
        returnValue(-1)
     end if
  end if
end procedure
setHandler(PhoneInput,w32HKeyDown,routine_id("onKeyDown_PhoneInput"))

That's all there is to it.

TTFN,  (Ta-Ta For Now)

new topic     » goto parent     » topic index » view message » categorize

5. RE: Moving the Cursor

Hi All,

Here is my attempt at moving the caret (not the cursor - I think that 
means the mouse pointer):

-- Set caret position whilst editing
-- Phil Russell August 2002

include win32lib.ew
without warning
with trace

constant
    Win     = create( Window, "Caret Position", 0, Default, Default, 
200, 100, 0 ),
    Sle    = create( EditText, "", Win, 10, 20, 120, 20, 0 )

-- Add formatting to text string
function addDashes( sequence text)

     if find( length( text), {3,8}) then
		text = text &'-'
     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 and key != VK_BACK then
	 	setText(self, addDashes(getText(self)))
	 	junk = sendMessage(self, EM_SETSEL, 0, -1 )
	 	junk = sendMessage(self, EM_SETSEL, -1, -1 )
	 end if

end procedure

setHandler(Sle, w32HAfterEvent, routine_id("after_event"))
WinMain( Win, Normal )

Works for me on Win2K

Regards,

Phil Russell

new topic     » goto parent     » topic index » view message » categorize

6. RE: Moving the Cursor

Jon Snyder wrote:
> 
> I'm trying to create an input field for a phone number that will 
> automatically add the dashes while the number is being input.  The 
> problem is, is that after calling setText() the cursor is put at the 
> begining of the edit box so the number is entered backwards.  Is there a 
> 
> way to move the cursor to the end of the edit box?
> 
> Here is the code i have so far...

<SNIP>

Sorry Jon, I have been a little busy the last couple of days and I
wasnt following along.  Just read all the posts, and thought I would
jump in.  It seems (to me) that you are looking for this:

==========
function removeDashes( sequence line)
    sequence new_line
    new_line = {}
    for i = 1 to length( line) do
        if line[i] != '-' then
            new_line &= line[i]
        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]
    end if
    if length_text > 8 then
        text = text[1..7] & '-' & text[8..length_text+1]
    end if

    return text
end function

procedure change_edit()
    onChange[ NUMBER_EDIT] = -1
    setText( NUMBER_EDIT, addDashes( removeDashes( getText( NUMBER_EDIT) 
) ))
    onChange[ NUMBER_EDIT] = routine_id( "change_edit") 
end procedure
onChange[ NUMBER_EDIT] = routine_id( "change_edit") 

procedure KeyPress( atom keyCode, atom shift )
    atom RetVal
    if keyCode != 35 then
        RetVal = w32Func( xPostMessage, 
{getHandle(NUMBER_EDIT),WM_KEYDOWN,35,0} )
    end if
end procedure
onKeyDown[ NUMBER_EDIT] = routine_id( "KeyPress")
==========

Let me know if I am wrong...
Don Phillips

new topic     » goto parent     » topic index » view message » categorize

7. RE: Moving the Cursor

Hi Don,

Your method seems to work fine as far as I can tell.  I have amended my 
earlier post to use the same add/removeDashes functions for comparison.  
Seems to be equivalent, just a couple of lines shorter ;)

Regards,

Phil

-- Set caret position whilst editing
-- Phil Russell August 2002

include win32lib.ew
without warning
with trace

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]
        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]
    end if
    if length_text > 8 then
        text = text[1..7] & '-' & text[8..length_text+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 and key != VK_BACK then
	 	setText(self, addDashes(removeDashes(getText(self))))
	 	-- This sets the caret to the end of the text
	 	junk = sendMessage(self, EM_SETSEL, 0, -1 )
	 	junk = sendMessage(self, EM_SETSEL, -1, -1 )
	 end if

end procedure
setHandler(Sle, w32HAfterEvent, routine_id("after_event"))

WinMain( Win, Normal )

new topic     » goto parent     » topic index » view message » categorize

8. RE: Moving the Cursor

Thanks Phil and Don.

I'm begining to think that Derek Parnell was right and that it's more 
trouble than its worth to try and put dashes in the edit box.  I came 
across an error with either of your solutions.  If you try to edit the 
number from the middle then the caret gets put at the end and not after 
the number just entered.  

To fix this, one would have to find where the caret is and then put the 
caret back in the next place.

As a side note, Could someone explain these lines of code.  I think that 
they do the same thing.

Phil's code
> 	 	-- This sets the caret to the end of the text
> 	 	junk = sendMessage(self, EM_SETSEL, 0, -1 )
> 	 	junk = sendMessage(self, EM_SETSEL, -1, -1 )

Don's code
>   if keyCode != 35 then
>        RetVal = w32Func( xPostMessage, 
>{getHandle(NUMBER_EDIT),WM_KEYDOWN,35,0} )

What does the "magic number" 35 stand for?

--Jon

Phil Russell wrote:
> Hi Don,
> 
> Your method seems to work fine as far as I can tell.  I have amended my 
> earlier post to use the same add/removeDashes functions for comparison.  
> 
> Seems to be equivalent, just a couple of lines shorter ;)
> 
> Regards,
> 
> Phil
> 
> -- Set caret position whilst editing
> -- Phil Russell August 2002
> 
> include win32lib.ew
> without warning
> with trace
> 
> 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]
>         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]
>     end if
>     if length_text > 7 then
>         text = text[1..7] & '-' & text[8..length_text+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 and key != VK_BACK then
> 	 	setText(self, addDashes(removeDashes(getText(self))))
> 	 	-- This sets the caret to the end of the text
> 	 	junk = sendMessage(self, EM_SETSEL, 0, -1 )
> 	 	junk = sendMessage(self, EM_SETSEL, -1, -1 )
> 	 end if
> 
> end procedure
> setHandler(Sle, w32HAfterEvent, routine_id("after_event"))
> 
> WinMain( Win, Normal )
> 
>

new topic     » goto parent     » topic index » view message » categorize

9. RE: Moving the Cursor

> Thanks Phil and Don.
> 
> I'm begining to think that Derek Parnell was right and that it's more 
> trouble than its worth to try and put dashes in the edit box.  I came 
> across an error with either of your solutions.  If you try to edit the 
> number from the middle then the caret gets put at the end and not after 
> the number just entered.  


> To fix this, one would have to find where the caret is and then put the 
> caret back in the next place.
> 
> As a side note, Could someone explain these lines of code.  I think that 
> 
> they do the same thing.
> 
> Phil's code
> > 	 	-- This sets the caret to the end of the text
> > 	 	junk = sendMessage(self, EM_SETSEL, 0, -1 )
> > 	 	junk = sendMessage(self, EM_SETSEL, -1, -1 )

EM_SETSEL is used for "selecting" ranges of text.
0, -1 will select all.
-1, -1 will (I think) remove the selection.

Net result being that the cursor is moved to the end.

> Don's code
> >   if keyCode != 35 then
> >        RetVal = w32Func( xPostMessage, 
> >{getHandle(NUMBER_EDIT),WM_KEYDOWN,35,0} )
> 
> What does the "magic number" 35 stand for?

35 stands for the "end" key, so every keypress places the
cursor at the end of the text.



Basically they both do that exact same thing, just a different
way.

I know what your looking for, gimme a couple of days and I am
sure I can come up with something...

Don Phillips

new topic     » goto parent     » topic index » view message » categorize

10. RE: Moving the Cursor

Okie, after poking around with it I came up with this.
It has the interesting side effect of not allowing the
removal of the dashes directly which I think is cool.

I also modified the style of the edit box to restrict
the input to numbers only.

==========
include Win32Lib.ew

constant
MainWin	= create( Window, "", NULL, 0.25, 0.25, 0.5, 0.5, 0 ),
NUMBER_EDIT = create( EditText, "", MainWin, 10, 10, 150, 25, ES_NUMBER 
)

atom Pos

function removeDashes( sequence line)
    sequence new_line
    new_line = {}
    for i = 1 to length( line) do
        if line[i] != '-' then
            new_line &= line[i]
        end if
    end for
    return new_line
end function

function addDashes( sequence text)
    integer length_text 
    length_text = length( text)
    
    if length_text > 2 then
        text = text[1..3] & '-' & text[4..length_text]
        Pos += 1
    end if
    if length_text > 5 then
        text = text[1..7] & '-' & text[8..length_text+1]
        Pos += 1
    end if

    return text
end function

procedure change_edit()
    Pos = w32Func( xSendMessage, {getHandle(NUMBER_EDIT),EM_GETSEL,0,0} 
)
    onChange[ NUMBER_EDIT] = -1
    setText( NUMBER_EDIT, addDashes( removeDashes( getText( NUMBER_EDIT) 
) ))
    onChange[ NUMBER_EDIT] = routine_id( "change_edit")
    Pos = w32Func( xSendMessage, 
{getHandle(NUMBER_EDIT),EM_SETSEL,lo_word(Pos),lo_word(Pos)} )
end procedure
onChange[ NUMBER_EDIT] = routine_id( "change_edit") 

WinMain( MainWin, Normal )
==========

new topic     » goto parent     » topic index » view message » categorize

11. RE: Moving the Cursor

Don,

That's great. This is exactly how i wanted it to work.  I made a couple 
changes to the code.  In the remove dashes routine it decrements Pos if 
there is a dash.  Also the add dashes doesn't add the dash until later 
so it can read in a 10 or a 7 digit number.

Where did you get the information to know how to do this?  Is it in the 
Win32Lib docs?

==================
include Win32Lib.ew

constant
MainWin = create( Window, "", NULL, 0.25, 0.25, 0.5, 0.5, 0 ),
NUMBER_EDIT = create( EditText, "", MainWin, 10, 10, 150, 25, ES_NUMBER 
),
LABEL = create( LText, "", MainWin, 100, 100, 200, 24, 0)

atom Pos

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

procedure change_edit()
    Pos = lo_word( w32Func( xSendMessage, 
{getHandle(NUMBER_EDIT),EM_GETSEL,0,0} 
))
    onChange[ NUMBER_EDIT] = -1
    setText( NUMBER_EDIT, addDashes( removeDashes( getText( NUMBER_EDIT) 

) ))
    onChange[ NUMBER_EDIT] = routine_id( "change_edit")
    
    setText(    LABEL , sprintf( "%d", Pos ))
	Pos = w32Func( xSendMessage, 
{getHandle(NUMBER_EDIT),EM_SETSEL, Pos, Pos} )
end procedure
onChange[ NUMBER_EDIT] = routine_id( "change_edit") 

WinMain( MainWin, Normal )

Don Phillips wrote:
> Okie, after poking around with it I came up with this.
> It has the interesting side effect of not allowing the
> removal of the dashes directly which I think is cool.
> 
> I also modified the style of the edit box to restrict
> the input to numbers only.
> 
> ==========
> include Win32Lib.ew
> 
> constant
> MainWin	= create( Window, "", NULL, 0.25, 0.25, 0.5, 0.5, 0 ),
> NUMBER_EDIT = create( EditText, "", MainWin, 10, 10, 150, 25, ES_NUMBER 
> )
> 
> atom Pos
> 
> function removeDashes( sequence line)
>     sequence new_line
>     new_line = {}
>     for i = 1 to length( line) do
>         if line[i] != '-' then
>             new_line &= line[i]
>         end if
>     end for
>     return new_line
> end function
> 
> function addDashes( sequence text)
>     integer length_text 
>     length_text = length( text)
>     
>     if length_text > 2 then
>         text = text[1..3] & '-' & text[4..length_text]
>         Pos += 1
>     end if
>     if length_text > 5 then
>         text = text[1..7] & '-' & text[8..length_text+1]
>         Pos += 1
>     end if
> 
>     return text
> end function
> 
> procedure change_edit()
>     Pos = w32Func( xSendMessage, {getHandle(NUMBER_EDIT),EM_GETSEL,0,0} 
> )
>     onChange[ NUMBER_EDIT] = -1
>     setText( NUMBER_EDIT, addDashes( removeDashes( getText( NUMBER_EDIT) 
> ) ))
>     onChange[ NUMBER_EDIT] = routine_id( "change_edit")
>     Pos = w32Func( xSendMessage, 
> {getHandle(NUMBER_EDIT),EM_SETSEL,lo_word(Pos),lo_word(Pos)} )
> end procedure
> onChange[ NUMBER_EDIT] = routine_id( "change_edit") 
> 
> WinMain( MainWin, Normal )
> ==========
> 
>

new topic     » goto parent     » topic index » view message » categorize

12. RE: Moving the Cursor

Hi Jon,
   You should change "if length_text > 7 then" to "if length_text >= 7
then" to get a better result. Try deleting after the 8 number with your
code and one with that change, and also in your code the - i added when
the 8th number is added, it should be the 7th.

Best Regards,
    Guillermo Bonvehi

new topic     » goto parent     » topic index » view message » categorize

13. RE: Moving the Cursor

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 )
=====================

new topic     » goto parent     » topic index » view message » categorize

14. RE: Moving the Cursor

Jon Snyder wrote:
> Don,
> 
> That's great. This is exactly how i wanted it to work.  I made a couple 
> changes to the code.  In the remove dashes routine it decrements Pos if 
> there is a dash.  Also the add dashes doesn't add the dash until later 
> so it can read in a 10 or a 7 digit number.

Good idea

> Where did you get the information to know how to do this?  Is it in the 
> Win32Lib docs?

Ahh no, I rarely (if ever) look at the Win32 docs.  When I am
trying to solve some problem I usually pull up the complete
API reference for the control in question to see what messages
are available.

new topic     » goto parent     » topic index » view message » categorize

15. RE: Moving the Cursor

> Gee, this makes me wanna document the library - not!

LOL, s'not quite what I meant :P

I am just hanging around the board... I dont program in
Euphoria anymore.  Not really.  But I do like solving
interesting little programming problems so I look around
daily to see if theres anything interesting I can contribute
to.

Another reason I dont look at it often, is for the most
part I have it committed to memory.  Which is quite
annoying considering my abandonment of Euphoria.

Don

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu