|
-
June 25th, 2003, 05:19 AM
#1
deselecting text..
Hi:
i am using following code
//CTextEditor is propertypage
//m_Editor is CEdit
BOOL CTextEditor::OnSetActive()
{
m_Editor.SetWindowText(m_Text);
return CPropertyPage::OnSetActive();
}
the result is that the whole text in the CEdit is selected...can someone help me how to stop selection of the text...
thanks
Ahmed
-
June 25th, 2003, 05:32 AM
#2
m_Edit.SetSel(0,0) to put the insertion mark before the text.
m_Edit.SetSel(-1,-1) to put the insertion mark after the text.
-
June 25th, 2003, 05:40 AM
#3
try it out.
CEdit *e;
e=(CEdit*)GetDlgItem(IDC_SEARCHTEXT);
e->SetSel(-1,m_SEARCHTEXT.GetLength(),FALSE);
//IDC_SEARCHTEXT => id of the edit control
//m_SEARCHTEXT => CString variable of IDC_SEARCHTEXT
Last edited by rdonline1; June 25th, 2003 at 05:58 AM.
-
June 25th, 2003, 05:41 AM
#4
Originally posted by gstercken
m_Edit.SetSel(-1,-1) to put the insertion mark after the text.
Are you sure that this will work? It is not mentioned in the documentation and usually I did
Code:
m_Edit.SetSel(m_Content.GetLength(), m_Content.GetLength())
where 'm_Content' is an associated member variable of type 'CString' to the content of the edit control...
-
June 25th, 2003, 05:53 AM
#5
Originally posted by Andreas Masur
Are you sure that this will work? It is not mentioned in the documentation and usually I did...
Yes, it works, although I must admit that it is not documented exactly like that. MSDN says:
If the nStart parameter is 0 and the nEnd parameter is –1, all the text in the edit control is selected. If nStart is –1, any current selection is removed. The caret is placed at the end of the selection indicated by the greater of the two values nEnd and nStart.
This always made me conclude that -1 generally means "after the last character", and in fact, it behaves like that. But I agree that using GetLength() is somewhat safer.
-
June 25th, 2003, 07:09 AM
#6
Originally posted by gstercken
MSDN says:
If the nStart parameter is 0 and the nEnd parameter is –1, all the text in the edit control is selected. If nStart is –1, any current selection is removed. The caret is placed at the end of the selection indicated by the greater of the two values nEnd and nStart.
Well...that is the kind of fun I always have with the MSDN. The october 2001 version does not mention it the way as you have quoted for the edit control... 
From your quote it is at least clearer than what I have...
-
June 25th, 2003, 07:34 AM
#7
setsel is not working...
Rather when i changed the tab order of CEdit ... now its working fine..It was the tab order creating problems..it was setting focus to CEdit when activating...
Thanks
AHmed
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
|