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



Comments

  • Solution: compatibility problem with Visual Studio.Net

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

    Originally posted by: BBWicked

    Hello,
    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?!

    greets
    BBWicked

    Reply
  • 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!

    Andrew

    Reply
  • 혹시 한국사람 아니슈?

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

    Originally posted by: 한국사람

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

    Reply
  • 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

    Reply
  • 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 ????

    Thx,
    Michael

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

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

    Originally posted by: Rigmania

    Hi...
    
    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?
    rig@hampia.com

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

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

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

    // TEST
    CHARRANGE l_CharRange;
    GetSel(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_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&CharFormat2);
    SendMessage(EM_SETPARAFORMAT, 0, (LPARAM)&m_ParaFormat2);

    HideSelection(TRUE, FALSE);

    }

    Reply
  • 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.

    Reply
  • ChatBox ActiveX Control

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

    Originally posted by: iBot

    Goto http://ibot.hypermart.net

    Reply
  • thanks very much

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

    Originally posted by: yeong-hwi, lee

    thanks

    Reply
  • 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?

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • The exponential growth of data, along with virtualization, is bringing a disruptive level of complexity to your IT infrastructure. Having multiple point solutions for data protection is not the answer, as it adds to the chaos and impedes on your ability to deliver consistent SLAs. Read this white paper to learn how a more holistic view of the infrastructure can help you to unify the data protection schemas by properly evaluating your business needs in order to gain a thorough understanding of the applications …

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds