CComboBox with support for history | CodeGuru

CComboBox with support for history

Environment: VC6 Introduction The History Combo class CHistoryCombo is based on CComboBox, and includes support for keeping item history, including reading from and saving to the registry. It can also be used to display the contents of an existing CRecentFileList object. How to use it Using the CHistoryCombo class is very straightforward. Follow the steps […]

Written By
CodeGuru Staff
CodeGuru Staff
Oct 1, 2002
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: VC6

Introduction

The History Combo class CHistoryCombo is based on CComboBox, and includes support
for keeping item history, including reading from and saving to the registry.
It can also be used to display the contents of an existing CRecentFileList object.

How to use it

Using the CHistoryCombo class is very straightforward. Follow the steps below
to add one to an existing project.

1. After putting the source files (HistoryCombo.cpp and HistoryCombo.h) into
the directory you wish to use them from, add the files to your Visual Studio
project.

2. In the resource editor, add a combo where you wish.

3. In Class Wizard add a member variable for your combo control, selecting
"Control" from the "Category" list, and selecting "CHistoryCombo"
from the "Variable Type" list. (If CHistoryCombo does not appear in
the list, you may need to delete your class wizard file (.clw) and regenerate
it). I will assume your control variable name is m_comboHistory.

4. Add a handler for WM_INITDIALOG in your dialog class if you don’t already
have one, and add the following code to it:

m_comboHistory.LoadHistory("Settings", "HistoryCombo");

(Note: you can specify any strings you wish for the section, and key-prefix)

5. In your handler for the IDOK button, or whereever you choose, add the following:

m_comboHistory.SaveHistory();

That’s all you need to do.

Advertisement

Documentation

Each function is documented in the cpp file. Here is a list of functions
in CHistoryCombo:

CHistoryCombo(BOOL bAllowSortStyle = FALSE);
CString LoadHistory(LPCTSTR lpszSection,
                    LPCTSTR lpszKeyPrefix,
                    BOOL bSaveRestoreLastCurrent = TRUE,
                    LPCTSTR lpszKeyCurItem = NULL);
CString LoadHistory(CRecentFileList* pListMRU,
                    BOOL bSelectMostRecent = TRUE);
void SaveHistory(BOOL bAddCurrentItemtoHistory = TRUE);
int AddString(LPCTSTR lpszString);
void SetMaxHistoryItems(int nMaxItems);
void ClearHistory(BOOL bDeleteRegistryEntries = TRUE);
void StoreValue(BOOL bIgnoreIfEmpty = TRUE);

Downloads

Download source – 4.52 Kb

Download demo – 118 Kb

May 8, 2002 – Version 2

  • removed CBS_SORT on creation if specified
  • added option to allow the sort style to be set if required
  • fixed SetMaxHistoryItems, so it removes old entries from the list to
    ensure that there are no more than the maximum. Also made SaveHistory remove
    redundant profile entries above the maximum.
  • use WriteProfileString to remove profile entries rather than CRegKey.

April 12, 2001 – First Version

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.