Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CEdit, set cursor position

989 views
Skip to first unread message

Jon Evans

unread,
Sep 2, 2004, 10:19:09 AM9/2/04
to
How do you set the cursor position in a CEdit control ?

Reading back through previous threads seems to indicate
that you somehow use CEdit's SetSel(). Can anyone tell me
what parameters to pass ? I want the cursor to be at the right
of any text and with no text highlighted.

If I have just used CEdit's SetWindowText() and then
called SetSel(1000,1000) (1000 being much greater
than text length) then this appears to work.

However the CEdit resides on a property page used as
a wizard, and I'm finding it impossible to control the CEdit
when people arrive on the page from another page's 'back'
or 'next' button. I can get the cursor to the end of the text
but the blasted text is still highlighted :-(

Before I completely loose the plot and try sending virtual
right key presses to the control, can anyone suggest how
to do it properly ?

TTFN,
Jon

BRM

unread,
Sep 2, 2004, 10:37:05 AM9/2/04
to
Use the text length as the start position and zero for the length.

So, something like:

CEdit txtText;
CString strText = "This is a test.";
txtText.SetWindowText(strText);
txtText.SetCurSel(strText.GetLength(),0);

BRM

Joseph M. Newcomer

unread,
Sep 2, 2004, 12:22:39 PM9/2/04
to
If the selection start and end are the same, you see no selection, you just get the caret.

Set the selection in the OnSetActive handler. You also need to set the focus first.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Jon Evans

unread,
Sep 6, 2004, 5:03:05 AM9/6/04
to

"Joseph M. Newcomer" wrote:

> If the selection start and end are the same, you see no selection, you just get the caret.
>
> Set the selection in the OnSetActive handler. You also need to set the focus first.
> joe
>

Thanks Joe,

This is where the problem lies. I'm intercepting OnSetActive()
and that is when I cant seem to position the cursor withough
highlights.

Elsewhere I have buttons that used to append text to the
control (date and time for example) and the finish with :-

m_wndEditName.SetWindowText( csNew ) ;
m_wndEditName.SetFocus() ;
m_wndEditName.SetSel( csNew.GetLength(), csNew.GetLength() ) ;

This works !

However, in OnSetActive() :-

int nChars = m_wndEditName.GetLength() ;
m_wndEditName.SetSel( nChars, nChars )

positions the cursor at the end of the line but
also highlights part of the text.

TTFN,
Jon

0 new messages