rich edit control query
-
hi all, as we can insert the text in an rich edit control with SetWindowText(string) API but is it possible to insert some character in between the existing string?? i mean if i know the caret position to insert that character and the actual character to insert then can i insert the characterwith this information?? e.g. if current text in rich edit control is love is in the air. and if i want to insert the character after "in" as "in/" so how i can do that?? please let me know if someone know's how to do this!! Thanks and Regards Harshal shete
-
hi all, as we can insert the text in an rich edit control with SetWindowText(string) API but is it possible to insert some character in between the existing string?? i mean if i know the caret position to insert that character and the actual character to insert then can i insert the characterwith this information?? e.g. if current text in rich edit control is love is in the air. and if i want to insert the character after "in" as "in/" so how i can do that?? please let me know if someone know's how to do this!! Thanks and Regards Harshal shete
harsha_1234 wrote:
love is in the air. and if i want to insert the character after "in" as "in/" so how i can do that??
Like this: You can use CString::Replace() to replace the text.
CString m_str; m_richedit.GetWindowText(m_str); m_str.Replace ("in","in/"); m_richedit.SetWindowText (m_str);
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
hi all, as we can insert the text in an rich edit control with SetWindowText(string) API but is it possible to insert some character in between the existing string?? i mean if i know the caret position to insert that character and the actual character to insert then can i insert the characterwith this information?? e.g. if current text in rich edit control is love is in the air. and if i want to insert the character after "in" as "in/" so how i can do that?? please let me know if someone know's how to do this!! Thanks and Regards Harshal shete
Another option is to use CRichEditCtrl::SetSel[^] to set the 'carret' position (in fact, the text which is selecetd in the control, if nStartChar is equal to nEndChar, then, you specify a carret position). You can then use CRichEditCtrl::ReplaceSel[^] to replace the text which is selected (ans thus, insert text also).
Cédric Moonen Software developer
Charting control [Updated - v1.1] -
harsha_1234 wrote:
love is in the air. and if i want to insert the character after "in" as "in/" so how i can do that??
Like this: You can use CString::Replace() to replace the text.
CString m_str; m_richedit.GetWindowText(m_str); m_str.Replace ("in","in/"); m_richedit.SetWindowText (m_str);
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
yes this is one way but in this way we need to call GetWindowText and then after changing the text we will say SetWindowText what i want to do is that if i have a character and the caret position that is going to tell me where to insert that character then i will do SetCaretPos(point) and now programmatically i want to insert that character ata that position so how i can achieve that?? and thank's for replying harshal shete
-
hi all, as we can insert the text in an rich edit control with SetWindowText(string) API but is it possible to insert some character in between the existing string?? i mean if i know the caret position to insert that character and the actual character to insert then can i insert the characterwith this information?? e.g. if current text in rich edit control is love is in the air. and if i want to insert the character after "in" as "in/" so how i can do that?? please let me know if someone know's how to do this!! Thanks and Regards Harshal shete
-
CString m_str; m_richedit.GetWindowText(m_str); m_str.Insert( Index, "string to be inserted" ); m_richedit.SetWindowText (m_str);
akt
-
Another option is to use CRichEditCtrl::SetSel[^] to set the 'carret' position (in fact, the text which is selecetd in the control, if nStartChar is equal to nEndChar, then, you specify a carret position). You can then use CRichEditCtrl::ReplaceSel[^] to replace the text which is selected (ans thus, insert text also).
Cédric Moonen Software developer
Charting control [Updated - v1.1]yes this is a good approach actually i am doing multilevel undo/redo for richedit ctrl(CRichEditCtrl) and when i searched on codeproject i didn't got any undo redo code for CRichEditCtrl. so currently i am making dynamic stack in which i am storing the caret position and the character.in OnChar handler. and i am thinking that when user will say undo i will pop one frame and will insert that character in the rich edit control at that position. Is it a good approach?? and is there no other API that will just take the character and caret position o insert the character?? Thanks and regards Harshal shete
-
yes this is one way but in this way we need to call GetWindowText and then after changing the text we will say SetWindowText what i want to do is that if i have a character and the caret position that is going to tell me where to insert that character then i will do SetCaretPos(point) and now programmatically i want to insert that character ata that position so how i can achieve that?? and thank's for replying harshal shete
harsha_1234 wrote:
what i want to do is that if i have a character and the caret position that is going to tell me where to insert that character then i will do
CPoint pt=m_richedit.GetCaretPos (); int i=m_richedit.CharFromPos (pt); CHARRANGE chRange; // comment this line chRange.cpMin =i; // comment this line chRange.cpMax =i; // comment this line m_richedit.SetSel (chRange); // m_richedit.SetSel(i,i); m_richedit.ReplaceSel ("/"); // will also work
I hope this helps and fits your requirement. -- modified at 5:01 Thursday 14th September, 2006Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
harsha_1234 wrote:
what i want to do is that if i have a character and the caret position that is going to tell me where to insert that character then i will do
CPoint pt=m_richedit.GetCaretPos (); int i=m_richedit.CharFromPos (pt); CHARRANGE chRange; // comment this line chRange.cpMin =i; // comment this line chRange.cpMax =i; // comment this line m_richedit.SetSel (chRange); // m_richedit.SetSel(i,i); m_richedit.ReplaceSel ("/"); // will also work
I hope this helps and fits your requirement. -- modified at 5:01 Thursday 14th September, 2006Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
yes thank's anshuman actually i am doing multilevel undo redo thanks and regards Harshal