Programming Tips - MFC: Use a CListBox as a visual log

Date: 2015dec9 OS: Windows Framework: MFC Keywords: CListCtrl Q. MFC: Use a CListBox as a visual 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);