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



Comments

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

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

    }


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

    Reply
  • Thanks a lot

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

    Originally posted by: sangjin

    Thanks...

    This Class is exactly the one I really needed!

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

    sigh..

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

    http://www.exontrol.com/sg.jsp?content=products/exeditors

    Regards,
    Mike

    Reply
  • 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;
    m_pNickNameBox.GetWindowText(strNickName);
    //CString strTemp="<"+strNickName+"> "+msg;
    CString strTemp=msg;
    strTemp+="\r\n";
    int len=m_pChatBox.GetWindowTextLength();
    m_pChatBox.SetSel(len,len);
    m_pChatBox.ReplaceSel(strTemp);
    }

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

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

    Reply
  • 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();
    SetSel(len,len,FALSE);
    ReplaceSel(str);

    // 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 ) );

    SetSel(0,x,TRUE);
    ReplaceSel("\r\n");
    len = GetWindowTextLength();
    SetSel(len,len,FALSE);
    }

    }

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Chuze Fitness is a fast-growing fitness chain with over 21 locations spanning California, Arizona and Colorado. Chief information and marketing officer, Kris Peterson, explains why access to fast and reliable Wi-Fi is a "must have" service at their gyms and why they switched to Ruckus Cloud Wi-Fi. Chuze Fitness needed to provide a good user experience to the hundreds of guests streaming music, podcasts and videos as they worked out. They also needed to adequately cover their sprawling 20-40,000 square foot …

  • IT is in a continual battle to simplify and "do more with the same, or less," but the continued growth of data has drastically increased the complexity and cost of deploying, managing, and processing data using traditional IT infrastructure components. One key component — enterprise storage and the underlying software that controls the storage — is fortunately evolving nearly as fast as the data is growing. This ESG Lab Review documents the results of hands-on testing of the WekaIO Matrix …

Most Popular Programming Stories

More for Developers

RSS Feeds

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