CComboBoxEx with History!

Abstract

The CHistoryComboEx based on the class ( CHistoryCombo) by Paul S. Vickery, which enables you to read and save the items of a ComboBox from and to the Registry. You can use it also to display the contents of a CRecentFileList object. CHistoryComboEx has the same functions of CHistoryCombo, but instead of the function (AddString()), I have added two new implements to the function (InsertItem()).

How to use it?

  1. Copy (HistoryComboEx.cpp and HistoryComboEx.h) to the folder of your project.


  2. Click on Project\Add To Project\Files... and then select the two files of our class and insert them into your project.


  3. Add programmatically or using the "Resource Editor" an Extended ComboBox control to your dialog.


  4. Using the "Class Wizard", add a member variable of type CComboBoxEx to your Extended ComboBox control. (I'll assume that your variable name is "m_cbeCtrl")


  5. Now open the header file of your dialog-box. Firstly, add this line to the top of it:

    #include "HistoryComboEx.h"

    and then change this line:

    CComboBoxEx   m_cbeCtrl;

    to:

    CHistoryComboEx m_cbeCtrl;
  6. Add the following line to the end of your "OnInitDialog()" or "OnInitialUpdate()" function:
    m_cbeCtrl.LoadHistory("Addresses", "HistoryComboEx");

    This line will add key names "Addresses" to the default key of your application in the Registry. Note: You can change "Addresses" and "HistoryComboEx" to any other values.

  7. Add the following line to the handler, which will be running, when your application is going to be closed. (OnOK() for example!):
    m_cbeCtrl.SaveHistory();

That's all!

Functions

Here I will write a summary for the functions of CHistoryComboEx. For details please see "HistoryComboEx.cpp". Note: The documentation is the same of that one by Paul S. Vickery's "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 InsertItem(const COMBOBOXEXITEM *pCBItem)

int InsertItem(CString strItem)

void SetMaxHistoryItems(int nMaxItems);

void ClearHistory(BOOL bDeleteRegistryEntries = TRUE);

Example

The Demo shows you how to use "CHistoryComboEx" to save and load URLs.

If you have any questions or comments, please let me know!

Downloads

Download source - 49 Kb


Comments

  • could not work on Win NT 4.0

    Posted by Legacy on 10/09/2002 12:00am

    Originally posted by: Abdul

    Nice work. I have tried with Win NT 4.0 but couldnt succsed.
    Any suggestion ?
    best regards
    Abdul

    Reply
  • Fantastic Job!

    Posted by Legacy on 02/18/2002 12:00am

    Originally posted by: Trent

    Works like a charm,

    Thanks!

    Reply
  • Nice app

    Posted by Legacy on 02/09/2002 12:00am

    Originally posted by: alan

    It works really good in you demo app but when I put it in mine it doesn't work.

    Also, I've searched the registry with Regcrawler for the values it stores and can't find them anywhere. Where exactly does it store them I don't understand why can't i find them?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Managing your company's financials is the backbone of your business and is vital to the long-term health and viability of your company. To continue applying the necessary financial rigor to support rapid growth, the accounting department needs the right tools to most efficiently do their job. Read this white paper to understand the 10 essentials of a complete financial management system and how the right solution can help you keep up with the rapidly changing business world.

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds