CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: Richedit slow

  1. #1
    Join Date
    Aug 2012
    Posts
    9

    Post Richedit slow

    HI , I m stuck fsince past month ,I m using default richeditctrl in richeditview.
    my requirement is that i want to show colored traces in every10 milliseconds.But i m struggling to do so,
    i have seen various examples and tutorials online, but can,t achieve it.

    Please help me...

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Richedit slow

    What do you mean with "colored traces"? Please elaborate or post a drawing of what you want to accomplish.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Aug 2012
    Posts
    9

    Re: Richedit slow

    i want to show formatted text with different foreground and background color for each line in a richedit view..

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Richedit slow

    And you really have to do that every 10ms? That's just too fast, and overkill anyway. 10ms is 100 FPS, that's too fast to read. You could update the text at a much lower FPS , that's more than fast enough for scrolling text.
    So, I suggest you buffer your traces and only update the richedit say every 100 ms for example (that's still 10 updates per second, more than fast enough I think). Based on the results of the 100ms update rate, you can slow it down even more, or speed it up a bit.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Richedit slow

    Quote Originally Posted by vinay kaul View Post
    my requirement is that i want to show colored traces in every10 milliseconds.
    Is this ultimately your requirement or your want?

    Besides, 10 ms is very short interval for any kind of iterative drawing in Windows, and I doubt that common controls are able to operate/react that fast. FYI, Windows workstation editions have 10 ms interval as a single dispatching time slot, and server editions have 25 ms for that. Windows is definitely not a Real Time OS.

    i have seen various examples and tutorials online, but can,t achieve it.
    How this is supposed to help us to understand your problem?
    Best regards,
    Igor

  6. #6
    Join Date
    Aug 2012
    Posts
    9

    Re: Richedit slow

    Actually the conventional way ofadding the text line-by-line on richeditctrl is very slow.

    ////////////////////////////////////////////
    GetRichEditCtrl().SetSel(nInsertionPoint, -1);

    // Set the character format
    GetRichEditCtrl().SetSelectionCharFormat(cf);

    // Replace selection.
    GetRichEditCtrl().ReplaceSel(str);
    ///////////////////////////////////////////////////////


    As i understood it can,t be as fast as 10 millisecond but ,
    please device me some way so that I can do it faster the the above method.


    Thanks in advance..

  7. #7
    Join Date
    Aug 2012
    Posts
    9

    Re: Richedit slow

    Thanks Marg,

    What i understood is that,If I can do this buffering my problem will be actully solved.
    But the question for me is ,how to buffer a richedit that is having text of various colors...
    Can I use a Cstring or any method ??

  8. #8
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Richedit slow

    CString doesn't contain any formatting.
    I don't know what kind of input you get for your traces.
    Can't you just store the input in a buffer instead of directly in the richedit?
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  9. #9
    Join Date
    Aug 2012
    Posts
    9

    Re: Richedit slow

    Marg, actually traces are generated in my application in random order, they contain date , time the data and error code etc,
    I want errors , acknowlegement and warning trace to be printed in different color, now what kind of intermediate buffer should i use that can hold the formatting ???

  10. #10
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Richedit slow

    Create a small class that contains the message itself and some enumeration that specifies whether it's a warning, info, or error.
    When a message comes in, create an instance of that class and store it in a queue.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  11. #11
    Join Date
    Aug 2012
    Posts
    9

    Re: Richedit slow

    Ya marg , I actually already stored the lines in a queue using structuresanf calling "ReplaceSel(str);" from thread, but the problem is all the lines of that buffer have
    same formatting(same color)..for all lines inside buffer ,that i called last using mfc function for richeditctrl "SetSelectionCharFormat(cf)";

  12. #12
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Richedit slow

    Richedit does extensive parsing of the input in order to draw a wide variety of different text. This processing of the 'RTF language' takes time. Making richedit unsuitable for fast trace output.
    RichEdit is also limited in what you can do, afaik, background color isn't possible.

    You will either need to create your own control that is tailored to your needs, in which case you can make it fast enough to handle 10ms response times.
    Or you could subclass another control that resembles what you need and change part of the behaviour.
    A Listbox or a listcontrol are suitable examples which you can use to do trace output. (however with the limitation that selecting items is on a row by row basis rather than a character by character basis as in a richedit.
    It is possible to make a listbox/listcontrol have each row in a color of choice, and even colorize a single row in multiple colors (with some more work).

  13. #13
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Richedit slow

    OReubens is right, you could create your own control, but even then, I don't think it makes sense to update text on the screen at 100 frames per second. That's just overkill.

    I would still try to simply store your messages in a queue and only update the RTF control 10 times per second or even less. I don't understand the difficulty with this solution. You have the message strings, you know if it's an error, info, or whatever kind of message. If you store this information in a queue, you can then every 100ms or so check the queue, and for each message there is inspect the kind of message (error, info, ...), use SetSelectionCharFormat appropriatly and then ReplaceSel.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured