Skip to main content
Email Password   helpLost your password?

Sample Image - HistoryCombo_demo.jpg

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 string you wish for the section, and key-prefix.)

  5. In your handler for the IDOK button, or wherever you choose, add the following:
    m_comboHistory.SaveHistory();

That's all you need to do.

Serialization, and using a string for storage

For examples on how to use the CArchive support, and the loading and saving from and to a string, see the demo program.

Documentation

Each function is documented in the CPP file, but 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);
virtual void Serialize(CArchive& ar);
void SaveHistory(CArchive& ar, BOOL bAddCurrentItemtoHistory = TRUE);
void LoadHistory(CArchive& ar);
CArchive& operator<<(CArchive& ar, CHistoryCombo& ob);
CArchive& operator>>(CArchive& ar, CHistoryCombo& ob);
CString SaveHistoryToText(CString& sHistory, BOOL bAddCurrentItemToHistory = 
    TRUE, LPCTSTR lpszDelims = _T("\r\n"));
void LoadHistoryFromText(LPCTSTR lpszHistory, LPCTSTR lpszLastSelected = NULL,
    LPCTSTR lpszDelims = _T("\r\n"));
int AddString(LPCTSTR lpszString);
void SetMaxHistoryItems(int nMaxItems);
void ClearHistory(BOOL bDeleteRegistryEntries = TRUE);
void StoreValue(BOOL bIgnoreIfEmpty = TRUE);
void SetAutoComplete(BOOL bAutoComplete = TRUE);
BOOL GetAutoComplete();
static void SetAutoCompleteDefault(BOOL bAutoComplete = TRUE);
static BOOL GetAutoCompleteDefault()

History

Version 3.1 - 20 Apr 2007

Version 3.0 - 22 Jun 2004

Version 2.1 - 09 Jul 2003

Version 2 - 01 May 2002

Version 1 - 12 Apr 2001

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralThanks Pin
ranu_hai
1:10 25 Feb '08  
GeneralExcellent! Pin
Steve_Harris
5:13 7 Nov '06  
GeneralRe: Excellent! Pin
Paul S. Vickery
5:51 20 Apr '07  
GeneralGood,but... Pin
Fzz
17:01 11 Oct '05  
AnswerRe: Good,but... Pin
Paul S. Vickery
5:32 17 Oct '05  
GeneralRe: Good,but... Pin
Fzz
3:52 21 Oct '05  
GeneralUNICODE support? test engine won't let you cut/paste greek into combobox Pin
Michael Shiels
16:57 8 Feb '05  
Generalmore than one comboBox in the same dialog? Pin
m3t3ora
21:07 11 Aug '03  
GeneralHow to get CHistoryCombo object in toolbar in CMainFrame? Pin
kydfru
22:49 22 Jun '03  
GeneralRe: How to get CHistoryCombo object in toolbar in CMainFrame? Pin
Paul S. Vickery
0:18 23 Jun '03  
GeneralThank you very much for your class and for your help! Pin
kydfru
0:37 23 Jun '03  
GeneralA Bug? It cann't show large text in edit box! Pin
Zhongzhu
4:17 14 Apr '03  
GeneralRe: A Bug? It cann't show large text in edit box! Pin
Paul S. Vickery
7:00 14 Apr '03  
GeneralThanks a lot! Pin
Zhongzhu
16:32 14 Apr '03  
GeneralRe: A Bug? It cann't show large text in edit box! Pin
no_reg_name
0:25 30 Jun '04  
GeneralRe: A Bug? It cann't show large text in edit box! Pin
Paul S. Vickery
1:58 2 Jul '04  
GeneralRe: A Bug? It cann't show large text in edit box! Pin
no_reg_name
0:39 5 Jul '04  
GeneralSerializing a ComboBox Pin
EPulse
22:55 26 Aug '02  
GeneralRe: Serializing a ComboBox Pin
Paul S. Vickery
1:01 28 Aug '02  
GeneralRe: Serializing a ComboBox Pin
EPulse
1:38 28 Aug '02  
GeneralRe: Serializing a ComboBox Pin
Paul S. Vickery
2:35 28 Aug '02  
GeneralRe: Serializing a ComboBox Pin
EPulse
0:12 3 Sep '02  
GeneralRe: Serializing a ComboBox Pin
Paul S. Vickery
23:38 23 Jun '04  
GeneralWeird - Notifications Pin
Uwe Keim
10:31 26 May '02  
GeneralRe: Weird - Notifications Pin
Paul S. Vickery
1:16 6 Jun '02  


Last Updated 20 Apr 2007 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009