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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Creating CRichEditCtrl Version 2.0/3.0

Creating CRichEditCtrl Version 2.0/3.0

Scheduled Pinned Locked Moved C / C++ / MFC
questionannouncement
18 Posts 3 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.
  • D David Crow

    What specifically is not working for you? If the control's parent is a dialog, add a control variable to the dialog's .H file, and then in the dialog's OnInitDialog() method, add: AfxInitRichEdit(); richedit.Create(...);

    S Offline
    S Offline
    Steve S
    wrote on last edited by
    #3

    Might be that they're wanting specifically to create a richedit with Word-style paragraph formatting (left, centre, right, align). The default MFC way means that an old style rich edit is created all the time. In some cases, the way I've done this is in OnInitDialog to get the old one's attributes, trash it and recreate the control in place, before calling the default OnInitDialog in case that maps a control. There are two Windows class names, "RichEdit" which is v1.0 and RICHEDIT_CLASS which expands at compile time to produce the appropriate name for v2 or later. Steve S

    1 Reply Last reply
    0
    • D David Crow

      What specifically is not working for you? If the control's parent is a dialog, add a control variable to the dialog's .H file, and then in the dialog's OnInitDialog() method, add: AfxInitRichEdit(); richedit.Create(...);

      L Offline
      L Offline
      Larry J Siddens
      wrote on last edited by
      #4

      The AfxInitRichEdit() loads the RICHED32.DLL with is version 1.0. I want to load 2.0/3.0 Thanks Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

      D 1 Reply Last reply
      0
      • L Larry J Siddens

        The AfxInitRichEdit() loads the RICHED32.DLL with is version 1.0. I want to load 2.0/3.0 Thanks Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #5

        My bad. When I saw richedit32, I just assumed v3.2, not 1.0. You have to go to richedit20 in order to get v3.0.:doh: Are we confused yet?:confused: So, the moral to your story is that the CRichEditCtrl class does not support the Rich Edit v2.0 control. In order to use Rich Edit 2.0 in an MFC application, call LoadLibrary() to load the Riched20.dll and access its functionality through the Win32 API. Hmmm

        L 1 Reply Last reply
        0
        • D David Crow

          My bad. When I saw richedit32, I just assumed v3.2, not 1.0. You have to go to richedit20 in order to get v3.0.:doh: Are we confused yet?:confused: So, the moral to your story is that the CRichEditCtrl class does not support the Rich Edit v2.0 control. In order to use Rich Edit 2.0 in an MFC application, call LoadLibrary() to load the Riched20.dll and access its functionality through the Win32 API. Hmmm

          L Offline
          L Offline
          Larry J Siddens
          wrote on last edited by
          #6

          So you use the LoadLibrary to load the riched20.dll and use the handle to set the fonts, formating, . . . Correct? Can you place a small example. I have not called items from the library. Thanks Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

          D 1 Reply Last reply
          0
          • L Larry J Siddens

            So you use the LoadLibrary to load the riched20.dll and use the handle to set the fonts, formating, . . . Correct? Can you place a small example. I have not called items from the library. Thanks Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #7

            HMODULE hLibrary = LoadLibrary("riched20.dll"); m_richedit = CreateWindowEx(0, RICHEDIT_CLASS, "", WS_CHILD | WS_VISIBLE | ES_MULTILINE, 5, 50, 100, 100, GetSafeHwnd(), NULL, NULL, NULL); ::SendMessage(m_richedit, WM_PASTE, 0, 0);

            L 1 Reply Last reply
            0
            • D David Crow

              HMODULE hLibrary = LoadLibrary("riched20.dll"); m_richedit = CreateWindowEx(0, RICHEDIT_CLASS, "", WS_CHILD | WS_VISIBLE | ES_MULTILINE, 5, 50, 100, 100, GetSafeHwnd(), NULL, NULL, NULL); ::SendMessage(m_richedit, WM_PASTE, 0, 0);

              L Offline
              L Offline
              Larry J Siddens
              wrote on last edited by
              #8

              You are loading the library to check if the riched20.dll is there correct? Now I have one more question. Have you been able to print that area correctly? If so, how? I'm trying to do that. The problem is that we don't know what the output device will be at the time of creation. Interesting twist huh? Thanks again. Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

              D 1 Reply Last reply
              0
              • L Larry J Siddens

                You are loading the library to check if the riched20.dll is there correct? Now I have one more question. Have you been able to print that area correctly? If so, how? I'm trying to do that. The problem is that we don't know what the output device will be at the time of creation. Interesting twist huh? Thanks again. Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #9

                Use EM_SETTARGETDEVICE to set the target device. Then use EM_FORMATRANGE and EM_DISPLAYBAND to display the control's contents. See the MSDN article Q129860.

                L 1 Reply Last reply
                0
                • D David Crow

                  Use EM_SETTARGETDEVICE to set the target device. Then use EM_FORMATRANGE and EM_DISPLAYBAND to display the control's contents. See the MSDN article Q129860.

                  L Offline
                  L Offline
                  Larry J Siddens
                  wrote on last edited by
                  #10

                  Thats the caveat Dave, we don't know what the device is when the use uses it! What I'm currently doing is pulling each line out, scanning for font differences and using the TextOut to draw the text. Problem is that the font that shows up on the screen (fitting inside of a box) is either bigger or smaller than what was on the screen. Kind of an interesting puzzle huh? Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

                  D 1 Reply Last reply
                  0
                  • L Larry J Siddens

                    Thats the caveat Dave, we don't know what the device is when the use uses it! What I'm currently doing is pulling each line out, scanning for font differences and using the TextOut to draw the text. Problem is that the font that shows up on the screen (fitting inside of a box) is either bigger or smaller than what was on the screen. Kind of an interesting puzzle huh? Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #11

                    Ok, I'm a tad confused at this point. Are you wanting to take text from a rich edit control and send it to a printer? It sounds like you need to use GetDeviceCaps() to make sure the target device is setup like the rich edit control.

                    L 1 Reply Last reply
                    0
                    • D David Crow

                      Ok, I'm a tad confused at this point. Are you wanting to take text from a rich edit control and send it to a printer? It sounds like you need to use GetDeviceCaps() to make sure the target device is setup like the rich edit control.

                      L Offline
                      L Offline
                      Larry J Siddens
                      wrote on last edited by
                      #12

                      Now I'm confussed? :confused: How do you do that? See if the target device is set up like a rich edit? Am I getting too deep here? I wish I did know what the target device was when the users used it, but that is the requirement. Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

                      D 1 Reply Last reply
                      0
                      • L Larry J Siddens

                        Now I'm confussed? :confused: How do you do that? See if the target device is set up like a rich edit? Am I getting too deep here? I wish I did know what the target device was when the users used it, but that is the requirement. Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #13

                        You have a rich edit control on a dialog or a form-based view. Yes? What are you wanting to do with the text in the control? As I understood your earlier post, you want to take the text in the control and send it to a printer. Yes?

                        L 2 Replies Last reply
                        0
                        • D David Crow

                          You have a rich edit control on a dialog or a form-based view. Yes? What are you wanting to do with the text in the control? As I understood your earlier post, you want to take the text in the control and send it to a printer. Yes?

                          L Offline
                          L Offline
                          Larry J Siddens
                          wrote on last edited by
                          #14

                          I actually sits within an area on a scrollview. Kind of like a text box in word. Then when the time comes, draw the text to the printer or some other device. Sorry for the confustion. Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

                          1 Reply Last reply
                          0
                          • D David Crow

                            You have a rich edit control on a dialog or a form-based view. Yes? What are you wanting to do with the text in the control? As I understood your earlier post, you want to take the text in the control and send it to a printer. Yes?

                            L Offline
                            L Offline
                            Larry J Siddens
                            wrote on last edited by
                            #15

                            I want to output the text in a rich edit control (there are many on the same page) with the same format and fonts usage as in the Rich Edit control. I thought I could use the FormatRange, but since I don't know what the target device is when it is being used, I'm not sure if that would work. So, I was getting one line at a time, then spending time to scan character by character checking the fonts used. When the font changs, then I would save off the font and the text. I continue until the whole line is scanned and getting the height of the text to the baseline. Setting the output to use the base line as the y parameter and outputting it to the device. This is so ineffecient it isn't funny. Am I correct in using FormatRange? OR, could I use FormatRange along with DisplayBand to output line by line. Again, inefficient than doing the whole thing, but it would be better than doing character by character. Thanks Dave. Larry Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

                            S 1 Reply Last reply
                            0
                            • L Larry J Siddens

                              I want to output the text in a rich edit control (there are many on the same page) with the same format and fonts usage as in the Rich Edit control. I thought I could use the FormatRange, but since I don't know what the target device is when it is being used, I'm not sure if that would work. So, I was getting one line at a time, then spending time to scan character by character checking the fonts used. When the font changs, then I would save off the font and the text. I continue until the whole line is scanned and getting the height of the text to the baseline. Setting the output to use the base line as the y parameter and outputting it to the device. This is so ineffecient it isn't funny. Am I correct in using FormatRange? OR, could I use FormatRange along with DisplayBand to output line by line. Again, inefficient than doing the whole thing, but it would be better than doing character by character. Thanks Dave. Larry Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

                              S Offline
                              S Offline
                              Steve S
                              wrote on last edited by
                              #16

                              I do something very similar. For a billing application I wrote, a number of users wanted "word processing", so I use a commentary window which is a richedit. I use FormatRange to step through appropriately sized chunks of the richedit, by working out what printable space there is (in twips), and making repeated calls, to build up a list of ranges (since it could be multi-page), more efficient than scanning the control's contents for changes (although it's similar to what the control is probably doing internally). Steve S

                              L 1 Reply Last reply
                              0
                              • S Steve S

                                I do something very similar. For a billing application I wrote, a number of users wanted "word processing", so I use a commentary window which is a richedit. I use FormatRange to step through appropriately sized chunks of the richedit, by working out what printable space there is (in twips), and making repeated calls, to build up a list of ranges (since it could be multi-page), more efficient than scanning the control's contents for changes (although it's similar to what the control is probably doing internally). Steve S

                                L Offline
                                L Offline
                                Larry J Siddens
                                wrote on last edited by
                                #17

                                Did you use the SetTargetDevice to make it WYSIWYG? The problem I'm having (or maybe I'm just making it harder than it really is) is that I don't know what tht output device will be at the time they enter in the data. Thanks for the Reply and info Steve. Larry Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

                                1 Reply Last reply
                                0
                                • D David Crow

                                  What specifically is not working for you? If the control's parent is a dialog, add a control variable to the dialog's .H file, and then in the dialog's OnInitDialog() method, add: AfxInitRichEdit(); richedit.Create(...);

                                  L Offline
                                  L Offline
                                  Larry J Siddens
                                  wrote on last edited by
                                  #18

                                  I have tried using the SetTargetDevice with the width of the window (in TWIPS) and getting the printer DC. The text is coming out in the proper format (line breaks and all), but the graphics that surround that are not. As an example, I place a line just to the end of the line, then do a print preview and the text extends past this line. I can send the test code that I'm playing with so you can see what I'm seeing. I am also getting conviced to do WYSIWYG, I really do need the output device to do the formatting. With out the device, what I need to do is seeming more and more impossible without a lot of fudging! Thanks you Guys. Larry Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

                                  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