RE: Moving the Cursor

new topic     » goto parent     » topic index » view thread      » older message » newer message

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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu