History Edit Control

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

This sample was contributed by Ravi Bhavnani.

CHistoryEdit is a CEdit derived control that lets you to display a scrolling text history, much like Dev Studio's "Output" window during a compilation. Here's an example of the control (the "History" window) being used in a dialog box.

CHistoryEdit demo

CHistoryEdit's AppendString() method appends a text string to the control and automatically scroll the most recent entry into view. Two other methods, AllowSelection() and IsSelectable() allow you to control whether the user may select text in the control.

Using CHistoryEdit in a dialog is quite simple:

  1. Include CHistoryEdit.h in your dialog class' header file.

  2. Add member variables of type CHistoryEdit for every edit control you want to subclass.

  3. Subclass the edit controls in your dialog's OnInitDialog() method.

      m_HistoryEdit.SubclassDlgItem (EDIT_HISTORY, this);

  4. Append text to the control by using AppendString().

      m_HistoryEdit.AppendString ("Compiling D:\\XDA\\Test\\Mechanic.kb...");

Download source files (2 K) CHistoryEdit.cpp, CHistoryEdit.h
Download demo project (14 K) (includes sources)

Last updated: 11 April 1998


  • How many lines can this control display?

    Posted by Legacy on 09/28/2003 12:00am

    Originally posted by: dann

    How many lines can this control display?

  • Easier Win32 Method with 6 lines of code.

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

    Originally posted by: Sean

    void AppendText (HWND hwndEditControl, char * szText)
    {//Appends text to an edit control and scrolls down.

    int iTextLength=0;

    iTextLength = SendMessage(hwndEditControl, WM_GETTEXTLENGTH , 0, 0);

    SendMessage(hwndEditControl, EM_SETSEL, iTextLength, iTextLength);

    SendMessage(hwndEditControl, EM_REPLACESEL, 0, (LPARAM)(LPCTSTR)szText);

    SendMessage(hwndEditControl, EM_SCROLL, SB_LINEDOWN, 0);


  • One question (read)

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

    Originally posted by: icewolf

    How can I check if the vertical scrollbar is at bottom? I only want it to auto scroll down if the scrollbar is on bottom. (like in mIRC)


  • Thanks a lot

    Posted by Legacy on 05/28/2002 12:00am

    Originally posted by: sangjin


    This Class is exactly the one I really needed!

  • its more trouble than its worth?

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

    Originally posted by: jon

    i cant believe how much trouble this simple little
    box has given me! its so simple but why doesnt it work?

    my latest problem is when i restore the window (after being minimized) it blows up. this is only one of the several issues with it...


  • ExEditors Library

    Posted by Legacy on 03/19/2002 12:00am

    Originally posted by: Mike Philips

    A complete collection of editors in a single file:



  • AddString() for CEdit

    Posted by Legacy on 12/15/2001 12:00am

    Originally posted by: Kim Ji Hoon

    void CTestgame01View::AddString(CString msg)
    CString strNickName;
    //CString strTemp="<"+strNickName+"> "+msg;
    CString strTemp=msg;
    int len=m_pChatBox.GetWindowTextLength();

  • Take a look at this one...

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

    Originally posted by: Decisoft

    ... it converts ALL edit controls to drop-downs with history: http://www.decisoft.com

  • 'ReplaceSel' without scrolling?

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

    Originally posted by: Tony Smith

    Can anyone help me?
    Is is possible to disable the scroll functionality in the CEdit::ReplaceSel(..) function in the same way the CEdit::SetSel(..) functions does.

  • Another version of the AppendString method

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

    Originally posted by: Larry Maser

    Here's my stab at the AppendString method, combines several of the ideas from earlier comments.

    void CHistoryEdit::AppendString
    (CString str)
    // Purpose:
    // Appends a text string to the history edit control.
    // This method appends a carriage return
    // Returns:
    // None.

    // append a carriage return

    str += "\r\n";

    // always write the line at the end

    int len = GetWindowTextLength();

    // Algorithm for determining when and how much of the most obsolete
    // text to remove. Reminds me of 1/3 1/3 1/3 rule for fuel planning in
    // a power boat: 1/3 to get there, 1/3 to get back, and 1/3 reserve.
    // Here, when 1/3 of the capacity of the edit control remains,
    // discard the most obsolete 1/3. The most current 1/3 is never
    // disturbed. GetLimitText() gets the capacity of the edit control.
    // GetWindowTextLength() gets the length of the current contents.

    if ( ( GetLimitText() * 2 / 3 ) < (UINT)GetWindowTextLength() )

    // Now make sure we discard a whole number of lines, i.e.,
    // break on a line boundary, to make the display look nice
    // should user scroll way back up to the top.

    int x = LineIndex ( LineFromChar ( GetWindowTextLength() / 2 ) );

    len = GetWindowTextLength();


  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Event Date: Tues, December 5, 2017 at 1:00 p.m. ET/10:00 a.m. PT Modernizing the enterprise data center to address raging demands for speed, performance, and capacity is a top directive for many IT organizations. While it's a known fact that upgrading to next-generation flash and solid-state drives (SSDs) can improve IT agility and application performance, the lower cost of legacy hard-disk drives (HDDs) has confined SSD use to only 10% of the data center. But that's changing. Don't guesstimate the …

  • In order for IT service providers to succeed, it's paramount that they find a competitive advantage and continually develop new ways to find additional revenue streams. IT service providers need to be able to do it all for their clients – from managing entire technology infrastructures to responding quickly to a multitude of end-user needs. With a growing number of issues to resolve and limited technicians at hand, how can IT service providers operate efficiently while providing top-notch service …

Most Popular Programming Stories

More for Developers

RSS Feeds

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