1. RE: Scrolling Edit Controls

Hi Chris,

I don't know if there's an easier way to do this but I just whipped up a 
demo for you.  Hope it helps.

---------------------------------------
include win32lib.ew

constant
    Win = create( Window,"Edit Demo",0,Default,Default,200,220,0 ),
    Mle1 = create( MleText, "", Win, 10, 10, 170, 120, 0 ),
    Button1 = create( PushButton,"Insert Text",Win,10,150,70,32,0 ),
    Button2 = create( PushButton,"Append Text",Win,100,150,70,32,0 ),
    
   MyTxt = "When in the Course of human Events " &
           "it becomes necessary for one People " &
           "to dissolve the Political Bands which " &
           "have connected them with another, and " &
           "to assume among the Powers of the " &
           "Earth, the separate and equal Station " &
           "to which the Laws of Nature and of " &
           "Nature's God entitle them, a decent " &
           "Respect to the Opinions of Mankind " &
           "requires that they should declare the " &
           "causes which impel them to the " &
           "Separation. "

-- Insert text at current caret position --
global procedure insertText( integer id, sequence text )
   atom txt_ptr, result

   -- convert to lpsz
   txt_ptr = acquire_mem(0, text )

   -- replace selection; True means allow undo
   result = sendMessage( id, EM_REPLACESEL, True, txt_ptr )

   -- Free the string
   release_mem( txt_ptr )
end procedure

-- Insert text at end of edit control's existing text --
global procedure appendText( integer id, sequence text )
   atom editlength, result

   editlength = length( getText( id ) )
   result = sendMessage( id, EM_SETSEL, editlength, editlength )
   insertText( id, text )
end procedure
   -----------------------------
procedure onOpen_Win()
   setText( Mle1, MyTxt )
end procedure
onOpen[Win] = routine_id( "onOpen_Win" )
   -----------------------------
procedure onClick_Button1()
   insertText( Mle1, "Inserted Text. " )
end procedure
onClick[Button1] = routine_id( "onClick_Button1" )
   -----------------------------
procedure onClick_Button2()
   appendText( Mle1, "Appended Text. " )
end procedure
onClick[Button2] = routine_id( "onClick_Button2" )
   -----------------------------
WinMain( Win, Normal )

-- Brian


Chris wrote:
> How do I make an MLE autoscroll, and update the caret position to the 
> end of the text?
> 
> Right now I'm using setText to update the MLE, but that replaces all of 
> the text, setting the scoll tab, and caret position to 0.
> 
> Is there a routine for appending text to an edit control?
> How can I manually scroll the MLE, and update the caret position?
> 
> I'm using win32lib.
> 
> Chris
> 
>

new topic     » topic index » view message » categorize

2. RE: Scrolling Edit Controls

Thank you,
  That's even faster than setText. I had looked up how to modify edit 
text in the win32API help file, but I didn't understand how the params 
work for sendMessage. That clears things up.

Chris

Brian Broker wrote:
> Hi Chris,
> 
> I don't know if there's an easier way to do this but I just whipped up a 
> 
> demo for you.  Hope it helps.
> 
> ---------------------------------------
> include win32lib.ew
> 
> constant
>     Win = create( Window,"Edit Demo",0,Default,Default,200,220,0 ),
>     Mle1 = create( MleText, "", Win, 10, 10, 170, 120, 0 ),
>     Button1 = create( PushButton,"Insert Text",Win,10,150,70,32,0 ),
>     Button2 = create( PushButton,"Append Text",Win,100,150,70,32,0 ),
>     
>    MyTxt = "When in the Course of human Events " &
>            "it becomes necessary for one People " &
>            "to dissolve the Political Bands which " &
>            "have connected them with another, and " &
>            "to assume among the Powers of the " &
>            "Earth, the separate and equal Station " &
>            "to which the Laws of Nature and of " &
>            "Nature's God entitle them, a decent " &
>            "Respect to the Opinions of Mankind " &
>            "requires that they should declare the " &
>            "causes which impel them to the " &
>            "Separation. "
> 
> -- Insert text at current caret position --
> global procedure insertText( integer id, sequence text )
>    atom txt_ptr, result
> 
>    -- convert to lpsz
>    txt_ptr = acquire_mem(0, text )
> 
>    -- replace selection; True means allow undo
>    result = sendMessage( id, EM_REPLACESEL, True, txt_ptr )
> 
>    -- Free the string
>    release_mem( txt_ptr )
> end procedure
> 
> -- Insert text at end of edit control's existing text --
> global procedure appendText( integer id, sequence text )
>    atom editlength, result
> 
>    editlength = length( getText( id ) )
>    result = sendMessage( id, EM_SETSEL, editlength, editlength )
>    insertText( id, text )
> end procedure
>    -----------------------------
> procedure onOpen_Win()
>    setText( Mle1, MyTxt )
> end procedure
> onOpen[Win] = routine_id( "onOpen_Win" )
>    -----------------------------
> procedure onClick_Button1()
>    insertText( Mle1, "Inserted Text. " )
> end procedure
> onClick[Button1] = routine_id( "onClick_Button1" )
>    -----------------------------
> procedure onClick_Button2()
>    appendText( Mle1, "Appended Text. " )
> end procedure
> onClick[Button2] = routine_id( "onClick_Button2" )
>    -----------------------------
> WinMain( Win, Normal )
> 
> -- Brian
> 
> 
> Chris wrote:
> > How do I make an MLE autoscroll, and update the caret position to the 
> > end of the text?
> > 
> > Right now I'm using setText to update the MLE, but that replaces all of 
> > the text, setting the scoll tab, and caret position to 0.
> > 
> > Is there a routine for appending text to an edit control?
> > How can I manually scroll the MLE, and update the caret position?
> > 
> > I'm using win32lib.
> > 
> > Chris
> > 
> >

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

Search



Quick Links

User menu

Not signed in.

Misc Menu