|
-
April 30th, 1999, 09:49 AM
#1
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
-
April 30th, 1999, 01:11 PM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|