EarthWeb

Developer.com
CodeGuru Sites
Visual C++/MFC
.NET (C# and more)
Visual Basic

Discussion Boards
Books on .NET
Book Reviews
Newsletters (subscribe)
Newsletters (archived)

Article Sections
C++
algorithms & formulas
c++ & mfc
date & time
string
COM-based Technologies
atl & wtl
com & activex
com+
shell programming
Controls
button control
combobox
edit control
imagelist control
listbox control
listview control
menu
other controls
property sheet
rich edit control
static control
status bar
toolbar
treeview control
Data
database
miscellaneous
Frameworks
ui & printing frameworks
Graphics & Multimedia
bitmaps & palettes
directx
gdi
multimedia
opengl
Internet & Networking
ie programming
internet protocols
isapi
network protocols
Miscellaneous
miscellaneous
Visual Studio
debugging
add-ins & macros
editor tips
Windows Programming
ce
clipboard
dll
file & folder
help systems
printing
win32
system
Windows & Dialogs
console
dialog
docking window
doc/view
splitter
Interact
Newsletters
Guestbook
Recommend Us!
About Us

[Internet Jobs]
   

CComboBox with support for history


This article was contributed by Paul S. Vickery.

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.

Documentation

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

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

Downloads

Download source - 4.06 Kb

Download demo - 120 Kb

History

Date Posted: May 21, 2001

Comments:

Add Comment

internet.commerce
 Be A Commerce Partner 
 Buy Books Here  
 Double Dial-Up Speed  
 Computer Training  
 Search the Web  
 Free DNS Offer  
 Buy BSD Products  
 Find a Web Host  



EarthWeb is a service of INT Media Group, Incorporated.
Copyright 2002 INT Media Group, Incorporated. All Rights Reserved.
Feedback,   Advertising Info,   Legal NoticesLicensing, Reprints, & Permissions,   Privacy Policy.
http://www.internet.com/