CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Posts
    20

    Changing CEdit text on the fly

    I'm trying to write a routine to update the text in a CEdit control as it is being typed. For example, typing:

    '#A' will produce the text 'Audit' in the edit control.

    I can update the text, but I am unable to reset the position of the caret after using the SetWindowText() function to update the window text. Regardless of where I set the caret, it always appears at the very beginning of the edit control.

    I'm using the following code to obtain and set the caret position:


    index = CharFromPos( GetCaretPos());
    CEdit::OnChar(nChar, nRepCnt, nFlags);
    GetWindowText( newtext );




    Substition routine converts 'newtext' to 'buffer' and updates the value of index to reflect the new text position.


    SetWindowText( buffer );
    SetCaretPos( PosFromChar( index ));




    Is there another way to update the text in the edit control without using Get/SetWindowText?

    Carnegie


  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Changing CEdit text on the fly

    You need to use SetSel() to position the caret. Basically, when you select an area within an edit control, the caret moves to the end of the selected position. For example, if you want to move the caret in position 2 of the edit field, you would call CEdit::SetSel(2,2)

    You may have to play around with this function a little. I've seen some quirkiness in the way it works. It's a backdoor way of setting the cursor position, but it does work.

    Regards,

    Paul McKenzie


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured