RichEditCtrl used in chatting

I wanted an editbox that can be used in chatting.
Every chat message was inserted after the last message, user name and message is distincted with another color and message has to have readonly attribute.
After all, If the message is full of the edit box, the view is autoscrolled upward.
To Use the CDalsuRichEdit...

  1. Copy "DalsuRichEdit.h", "DalsuRichEdit.cpp" in your work directory
  2. Add your project these two files
  3. Add a member data ex:m_pDalRich or m_pDalRich
  4. Create the CDalRichEdit's Window with suitable style
The Description of member functions
  1. AddName(CString &strName, COLORREF &crColor);
    Specify the User Name and its color

  2. AddText(CString &strTextIn, COLORREF &crColor);
    Specify text string and its color
    Don't forget! There are "\r\n" characters on the tail of this string.

  3. AddMsg(CString &strMsg, COLORREF &crColor, BOOL bUnderLine, BOOL bBold);
    It's general system message. ex:A User joined this room...
    In the same manner, there are "\r\n" characters on the tail of this string.
and I thank for Zafir Anjum, Tom Moor, Steve Dunn, Juraj Rojko 's codes...

Download demo project - 37 KB

Date Posted: 01/14/99


  • Solution: compatibility problem with Visual Studio.Net

    Posted by Legacy on 04/08/2003 12:00am

    Originally posted by: BBWicked

    beforehand please excuse my english and faults in my statements, because i normaly don�t talk english (i�m from germany) and i�m a beginner in programmming!

    I noticed that the chat programm made faults, when running on a Visual Stuio.Net compiler(but not on a Visual Studio 6.0 compiler), it coloured letters he schouldn�t do!
    I think the problem were the extensions of the "\n" at the strings which should be written into the richeditbox, because the function GetWindowTextLength couldn�t count them right.
    The reason for it might be the handling of ANSI and UNICODE of this function (in VS.Net).
    So my solution was to use the GetTextLengthEx function instead of the GetWindowTextLength function!
    Here is a sample code:

    int iTotalTextLength = GetTextLengthEx(GTL_DEFAULT,CP_ACP);

    I Hope I could help anybody out there?!


  • Small improvement to technique (also fixes bug)

    Posted by Legacy on 03/12/2003 12:00am

    Originally posted by: Andrew Newton

    A small problem arises from the current technqiue:

    1. Select the text at the end of the control
    2. Replace the selection
    3. Select the new text
    4. Set the format of the selection

    The text sometimes gets the wrong formatting, by picking up the formatting of the previous line. I found it better to do the following:

    1. Select the text at the end of the control
    2. Set the new format for the the selection
    3. Replace the selection

    Heres the code i use:

    int before = rich->GetTextLength();

    rich->SetSel( before, before );
    rich->SetSelectionCharFormat( format );
    rich->ReplaceSel( str );

    Nice and simple!


  • 혹시 한국사람 아니슈?

    Posted by Legacy on 02/02/2003 12:00am

    Originally posted by: 한국사람

    컨트롤 이름이 달수RichEdit 이길래...
    아무래도 한국사람같은데... 반갑소.
    달수씨, 반가워요.

  • Event notifiaction for rich edit control

    Posted by Legacy on 12/17/2002 12:00am

    Originally posted by: pooja

    I am not able to recieve event notfication for events
    Anyone help me ot with the same

  • Missing context menu when right clicking on the control !!!

    Posted by Legacy on 11/24/2002 12:00am

    Originally posted by: Michael Kuelshammer

    I want to get the normal context menu for the CRichEditCtrl, with copy and paste and so on, any solution for it, how to get it ????


  • I got AddText().. in Richedit2.0

    Posted by Legacy on 07/10/2002 12:00am

    Originally posted by: Rigmania

    I modified this class to use RichEdit 2.0
    but when I use RichEdit 2.0,
    it's trouble at AddText().

    can you help me?

    void CRichEditEx::AddText(LPCTSTR szTextIn, CHARFORMAT2 &CharFormat2)
    const int iTotalTextLength = GetWindowTextLength();
    SetSel(iTotalTextLength, iTotalTextLength);

    const int iStartPos = iTotalTextLength;
    const int iEndPos = GetWindowTextLength();

    // select inserted text
    SetSel(iStartPos, iEndPos);

    // TEST
    CHARRANGE l_CharRange;

    // Here is confuse... but why?
    // Is't different (iStartPos, iEndPos) from l_CharRange
    // when I use RichEdit2.0 .
    // But if I use Richedit 1.0, it works!

    SendMessage(EM_SETPARAFORMAT, 0, (LPARAM)&m_ParaFormat2);

    HideSelection(TRUE, FALSE);


  • has trouble with UNICODE

    Posted by Legacy on 06/07/2002 12:00am

    Originally posted by: Tomas Bobovsky

    I've created it as richeditctrl version 2 to work with unicode. Generally it does its job but the colors start to get out sync. I'm trying to fix it, if anyone has a solution, please email me.

  • ChatBox ActiveX Control

    Posted by Legacy on 02/20/2002 12:00am

    Originally posted by: iBot


  • thanks very much

    Posted by Legacy on 08/30/2001 12:00am

    Originally posted by: yeong-hwi, lee


  • Scrolling problem under win98

    Posted by Legacy on 05/09/2001 12:00am

    Originally posted by: Klymer

    Well this is a really nice class
    only one thing appears strange: the scrolling behaviour with win 98. Can you give me some hint how to fix that?

  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Complex hybrid environments can make it difficult to track interdependencies, increasing the risk of disrupting critical business services. In this white paper by EMA, you'll learn how application discovery and dependency mapping can help you: Meet granular targets for availability, cost, and time-to-revenue for cloud services. Accelerate mean time to repair (MTTR) while communicating better with stakeholders. Manage even the most complex hybrid environments more efficiently and effectively Understand the …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date