Dave's Brain

Browse - Programming Tips - How can I use a CListBox as a log?

Date: 2015dec9
OS: Windows
Framework: MFC
Keywords: CListCtrl

Q.  How can I use a CListBox as a log?

A.  Here is a function that adds strings, makes sure the control
doesn't get too big and scrolls to the bottom.

bool AddLog(LPCSTR s, const int max) { const bool result = m_ListBox.AddString(s) != CB_ERR; while (m_ListBox.GetCount() > max) { Delete(0); } m_ListBox.SetTopIndex(m_ListBox.GetCount() - 1); // scroll return result; } // Example const int MAX_LOG = 100; AddLog("Something happened", MAX_LOG);

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.