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

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • On-demand Event Event Date: July 22, 2014 In this WhatWorks analysis, John Pescatore examines a use case where end users had local administrative rights on their PCs and it had gotten out of hand for this Fortune 500 Energy and Utilities company. The compelling event that prompted the company to reexamine this situation was the migration to Windows 7. In Windows XP, a custom tool that allowed users one of three levels of administrative rights to their workstations would need to be replaced during the Windows …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds