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. CRichEditCtrl

CRichEditCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++tutorialquestion
11 Posts 6 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.
  • V VinayCool

    Hi, I need your help very urgently.... I have only 2days left to complete my MCA Academic project can u please help me with the CRichEditCtrl control.. I am totaly new to VC++ and i have no idea how to work with CRichEditCtrl .. Can u please tell how work with CRichEditCtrl ? i want to pass the entire text file to CRichEditCtrl and i want to highlight some words after passing the text file to CRichEditCtrl i have created rich edit control IDC_FCONT m_FCONT of type CRichEditCtrl char ch; FILE *fp; fp=fopen(str,"r"); if(fp==NULL) { MessageBox("error opening file.",MB_OK | MB_ICONINFORMATION); return; } ch=getc(fp); while(!feof(fp)) { //putch(ch); ch=getc(fp); } // m_FCONT.SetWindowText(); fclose(fp); } can u please help me..... Thanking you .... i will be waiting... :doh: Regards, Vinay Charan.

    N Offline
    N Offline
    Nibu babu thomas
    wrote on last edited by
    #2

    VinayCool wrote:

    i want to pass the entire text file to CRichEditCtrl

    Look up StreamIn and StreamOut

    VinayCool wrote:

    and i want to highlight some words after passing the text file to CRichEditCtrl

    Search in MSDN for Using CRichEditCtrl. This article covers almost all functions of CRichEditCtrl.


    Nibu thomas A Developer Programming tips[^]  My site[^]

    1 Reply Last reply
    0
    • V VinayCool

      Hi, I need your help very urgently.... I have only 2days left to complete my MCA Academic project can u please help me with the CRichEditCtrl control.. I am totaly new to VC++ and i have no idea how to work with CRichEditCtrl .. Can u please tell how work with CRichEditCtrl ? i want to pass the entire text file to CRichEditCtrl and i want to highlight some words after passing the text file to CRichEditCtrl i have created rich edit control IDC_FCONT m_FCONT of type CRichEditCtrl char ch; FILE *fp; fp=fopen(str,"r"); if(fp==NULL) { MessageBox("error opening file.",MB_OK | MB_ICONINFORMATION); return; } ch=getc(fp); while(!feof(fp)) { //putch(ch); ch=getc(fp); } // m_FCONT.SetWindowText(); fclose(fp); } can u please help me..... Thanking you .... i will be waiting... :doh: Regards, Vinay Charan.

      Steve EcholsS Offline
      Steve EcholsS Offline
      Steve Echols
      wrote on last edited by
      #3

      I get the vague feeling I'm doing someone's homework.... You can either lookup CRichEditCtrl's StreamIn function or if you need a quick and dirty file reader (for small files), do something like: FILE *fp = fopen(str,"r"); if (fp) { // goto the end of file fseek(fp, 0L, SEEK_END); // get the length of the file long fileLen = ftell(fp); // go back to the start of the file rewind(fp); // allocate buffer for file contents char* text = new char[fileLen + 1]; // read the file into the buffer fread(text, 1, fileLen, fp); // set the window text m_FCONT.SetWindowText(text); delete [] text; fclose(fp); } else { MessageBox("error opening file.",MB_OK | MB_ICONINFORMATION); return; } This code is totally untested, but should give you the general idea. Good luck!


      - S 50 cups of coffee and you know it's on!

      • S
        50 cups of coffee and you know it's on!
        Code, follow, or get out of the way.
      V 1 Reply Last reply
      0
      • V VinayCool

        Hi, I need your help very urgently.... I have only 2days left to complete my MCA Academic project can u please help me with the CRichEditCtrl control.. I am totaly new to VC++ and i have no idea how to work with CRichEditCtrl .. Can u please tell how work with CRichEditCtrl ? i want to pass the entire text file to CRichEditCtrl and i want to highlight some words after passing the text file to CRichEditCtrl i have created rich edit control IDC_FCONT m_FCONT of type CRichEditCtrl char ch; FILE *fp; fp=fopen(str,"r"); if(fp==NULL) { MessageBox("error opening file.",MB_OK | MB_ICONINFORMATION); return; } ch=getc(fp); while(!feof(fp)) { //putch(ch); ch=getc(fp); } // m_FCONT.SetWindowText(); fclose(fp); } can u please help me..... Thanking you .... i will be waiting... :doh: Regards, Vinay Charan.

        _ Offline
        _ Offline
        _anil_
        wrote on last edited by
        #4

        http://www.codeproject.com/richedit/htmlricheditctrlssl.asp the above link can give you some idea. :-) Regards Anil

        V 1 Reply Last reply
        0
        • V VinayCool

          Hi, I need your help very urgently.... I have only 2days left to complete my MCA Academic project can u please help me with the CRichEditCtrl control.. I am totaly new to VC++ and i have no idea how to work with CRichEditCtrl .. Can u please tell how work with CRichEditCtrl ? i want to pass the entire text file to CRichEditCtrl and i want to highlight some words after passing the text file to CRichEditCtrl i have created rich edit control IDC_FCONT m_FCONT of type CRichEditCtrl char ch; FILE *fp; fp=fopen(str,"r"); if(fp==NULL) { MessageBox("error opening file.",MB_OK | MB_ICONINFORMATION); return; } ch=getc(fp); while(!feof(fp)) { //putch(ch); ch=getc(fp); } // m_FCONT.SetWindowText(); fclose(fp); } can u please help me..... Thanking you .... i will be waiting... :doh: Regards, Vinay Charan.

          N Offline
          N Offline
          NiceNaidu fo
          wrote on last edited by
          #5

          The most important thing you need to do is Call AfxInitRichEdit() function in u r InitInstance() of u r application.AfxInitRichEdit loads RICHED32.DLL to initialize version 1.0 of the rich edit control. Appu.. "If you judge people, you have no time to love them."

          V 1 Reply Last reply
          0
          • Steve EcholsS Steve Echols

            I get the vague feeling I'm doing someone's homework.... You can either lookup CRichEditCtrl's StreamIn function or if you need a quick and dirty file reader (for small files), do something like: FILE *fp = fopen(str,"r"); if (fp) { // goto the end of file fseek(fp, 0L, SEEK_END); // get the length of the file long fileLen = ftell(fp); // go back to the start of the file rewind(fp); // allocate buffer for file contents char* text = new char[fileLen + 1]; // read the file into the buffer fread(text, 1, fileLen, fp); // set the window text m_FCONT.SetWindowText(text); delete [] text; fclose(fp); } else { MessageBox("error opening file.",MB_OK | MB_ICONINFORMATION); return; } This code is totally untested, but should give you the general idea. Good luck!


            - S 50 cups of coffee and you know it's on!

            V Offline
            V Offline
            VinayCool
            wrote on last edited by
            #6

            Hi Steve Echols, Thank you very much, code is 100% working. But at the end of edit of edit box i am getting some junk values as shown below. ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍýýýýÝÝÝÝÝÝÝÝÝ Can u please also tell me how to highlight a particular word in the Rich edit box. if want to high light a word america in the rich edit box ,the word may apper more then once.. can u please give me some inforamtion... Regards, Vinay Charan.

            Steve EcholsS 1 Reply Last reply
            0
            • _ _anil_

              http://www.codeproject.com/richedit/htmlricheditctrlssl.asp the above link can give you some idea. :-) Regards Anil

              V Offline
              V Offline
              VinayCool
              wrote on last edited by
              #7

              Hi Anil, Thanks for the link... Regards, Vinay Charan.

              1 Reply Last reply
              0
              • N NiceNaidu fo

                The most important thing you need to do is Call AfxInitRichEdit() function in u r InitInstance() of u r application.AfxInitRichEdit loads RICHED32.DLL to initialize version 1.0 of the rich edit control. Appu.. "If you judge people, you have no time to love them."

                V Offline
                V Offline
                VinayCool
                wrote on last edited by
                #8

                Hi Appu, Thanks for the information,it will be usefull for me. Regards, Vinay Charan.

                1 Reply Last reply
                0
                • V VinayCool

                  Hi, I need your help very urgently.... I have only 2days left to complete my MCA Academic project can u please help me with the CRichEditCtrl control.. I am totaly new to VC++ and i have no idea how to work with CRichEditCtrl .. Can u please tell how work with CRichEditCtrl ? i want to pass the entire text file to CRichEditCtrl and i want to highlight some words after passing the text file to CRichEditCtrl i have created rich edit control IDC_FCONT m_FCONT of type CRichEditCtrl char ch; FILE *fp; fp=fopen(str,"r"); if(fp==NULL) { MessageBox("error opening file.",MB_OK | MB_ICONINFORMATION); return; } ch=getc(fp); while(!feof(fp)) { //putch(ch); ch=getc(fp); } // m_FCONT.SetWindowText(); fclose(fp); } can u please help me..... Thanking you .... i will be waiting... :doh: Regards, Vinay Charan.

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #9

                  See Control within a control & Subclassing with a cool example[^]maybe it is some helpful to you how to work CRichEditCtrl_**


                  **_

                  whitesky


                  1 Reply Last reply
                  0
                  • V VinayCool

                    Hi Steve Echols, Thank you very much, code is 100% working. But at the end of edit of edit box i am getting some junk values as shown below. ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍýýýýÝÝÝÝÝÝÝÝÝ Can u please also tell me how to highlight a particular word in the Rich edit box. if want to high light a word america in the rich edit box ,the word may apper more then once.. can u please give me some inforamtion... Regards, Vinay Charan.

                    Steve EcholsS Offline
                    Steve EcholsS Offline
                    Steve Echols
                    wrote on last edited by
                    #10

                    VinayCool wrote:

                    But at the end of edit of edit box i am getting some junk values as shown below.

                    You need a terminating null on the text (which I forgot): Change the lines in bold: // allocate buffer for file contents **char* text = new char[fileLen + 1];** // read the file into the buffer fread(text, 1, fileLen, fp); **// null terminate the string text[fileLen] = 0;**

                    VinayCool wrote:

                    Can u please also tell me how to highlight a particular word in the Rich edit box.

                    Like I mentioned yesterday, you can do somthing like: CHARFORMAT cf; memset(&cf, 0, sizeof(CHARFORMAT)); cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_BOLD; cf.dwEffects = CFE_BOLD; // **** pseudo-code **** for (int i = 0; i < size of your word list; i++) { m_FCONT.SetSel(word_position[i], word_length[i]); m_FCONT.SetSelectionCharFormat(cf); } Hope that works!


                    - S 50 cups of coffee and you know it's on! -- modified at 3:07 Thursday 25th May, 2006

                    • S
                      50 cups of coffee and you know it's on!
                      Code, follow, or get out of the way.
                    V 1 Reply Last reply
                    0
                    • Steve EcholsS Steve Echols

                      VinayCool wrote:

                      But at the end of edit of edit box i am getting some junk values as shown below.

                      You need a terminating null on the text (which I forgot): Change the lines in bold: // allocate buffer for file contents **char* text = new char[fileLen + 1];** // read the file into the buffer fread(text, 1, fileLen, fp); **// null terminate the string text[fileLen] = 0;**

                      VinayCool wrote:

                      Can u please also tell me how to highlight a particular word in the Rich edit box.

                      Like I mentioned yesterday, you can do somthing like: CHARFORMAT cf; memset(&cf, 0, sizeof(CHARFORMAT)); cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_BOLD; cf.dwEffects = CFE_BOLD; // **** pseudo-code **** for (int i = 0; i < size of your word list; i++) { m_FCONT.SetSel(word_position[i], word_length[i]); m_FCONT.SetSelectionCharFormat(cf); } Hope that works!


                      - S 50 cups of coffee and you know it's on! -- modified at 3:07 Thursday 25th May, 2006

                      V Offline
                      V Offline
                      VinayCool
                      wrote on last edited by
                      #11

                      Hi Steve Echols, Thank for helping me for completing my project. Code is working i declared these vaiables char word_position[50]; char word_length[50]; Steve how to pass the word ??? where i ahve to pass the word which has to be highlighted ?? I have stored the word here which has to be hightlighted w = m_WORD; ---------------------------------- CHARFORMAT cf; memset(&cf, 0, sizeof(CHARFORMAT)); cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_BOLD; cf.dwEffects = CFE_BOLD; UpdateData(TRUE); CString w; w = m_WORD; int len = strlen(word); char word_position[50]; char word_length[50]; // **** pseudo-code **** for (int p = 0; p < len ; p++) { m_FCONT.SetSel(word_position[p], word_length[p]); m_FCONT.SetSelectionCharFormat(cf); } Regards, Vinay Charan.

                      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