Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. rich edit control query

rich edit control query

Scheduled Pinned Locked Moved C / C++ / MFC
databaseadobejsontutorialquestion
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    harsha_1234
    wrote on last edited by
    #1

    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

    _ C A 3 Replies Last reply
    0
    • H harsha_1234

      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

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      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_

      H 1 Reply Last reply
      0
      • H harsha_1234

        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

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        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]

        H 1 Reply Last reply
        0
        • _ _AnsHUMAN_

          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_

          H Offline
          H Offline
          harsha_1234
          wrote on last edited by
          #4

          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

          _ 1 Reply Last reply
          0
          • H harsha_1234

            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

            A Offline
            A Offline
            Akt_4_U
            wrote on last edited by
            #5

            CString m_str; m_richedit.GetWindowText(m_str); m_str.Insert( Index, "string to be inserted" ); m_richedit.SetWindowText (m_str);

            akt

            A 1 Reply Last reply
            0
            • A Akt_4_U

              CString m_str; m_richedit.GetWindowText(m_str); m_str.Insert( Index, "string to be inserted" ); m_richedit.SetWindowText (m_str);

              akt

              A Offline
              A Offline
              Akt_4_U
              wrote on last edited by
              #6

              ooh sorry pls ignore the above reply thanks

              akt

              1 Reply Last reply
              0
              • C Cedric Moonen

                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]

                H Offline
                H Offline
                harsha_1234
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • H harsha_1234

                  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

                  _ Offline
                  _ Offline
                  _AnsHUMAN_
                  wrote on last edited by
                  #8

                  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, 2006

                  Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

                  H 1 Reply Last reply
                  0
                  • _ _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, 2006

                    Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

                    H Offline
                    H Offline
                    harsha_1234
                    wrote on last edited by
                    #9

                    yes thank's anshuman actually i am doing multilevel undo redo thanks and regards Harshal

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups