Click here to Skip to main content
Click here to Skip to main content

Hot List Control - Another Kind of List Control

, 13 May 2000
Rate this:
Please Sign up or sign in to vote.
A control for selecting items from a list, with tool tips and mouse tracking
  • Download demo project - 26 Kb
  • Download source files - 6 Kb
  • This example shows the hot list control used in a CView class. A tool tip displays information about the highlighted item. George Washington is the currently selected item, but the mouse is hovering over Martin Van Buren, and display the tool tip assigned to Martin Van Buren.

    This example shows the hot list control used in a dialog box. The selected item is Chester Arthur, but the mouse is currently highlighting Abraham Lincoln. Scroll buttons at the top an bottom of the control allow the user to scroll this list.

    Description

    CHotListCtrl is not derived from CListCtrl. CHotListCtrl mimics the behavior of the TLookOut control developed by Peter Thornqvist for Borland's Delphi. Peter described the control as being similar to a control used in Microsoft Outlook. I do not use Microsoft Outlook, so I do not know if this is true, or how similar the control is to anything in Outlook.

    The control displays a list of items. For each item, you can specify the text for the item (from a string or resource ID), the tool tip text to display when the item is highlighted, and a dwData value for the item.

    When an item is selected, a WM_HOT_LIST_CHANGED (user-defined) message is sent to the parent window. As the mouse moves over each item in the list, that item is highlighted (drawn raised). The currently selected item is drawn pressed. There are scroll buttons at the top and bottom for lists that exceed the height of the control.

    CHotListCtrl is Unicode safe (to the best of my knowledge).

    Using the Control in a View

    1. Add a CHotListCtrl member to you CView derived class.
      class CHotsView : public CView
      {
      protected: // create from serialization only
      	CHotsView();
      	DECLARE_DYNCREATE(CHotsView)
      
      // Attributes
      public:
      	CHotsDoc* GetDocument();
      
      	CHotListCtrl m_HotListCtrl; // the Hot List Control
      
      
      [snip]
    2. On CView::InitialUpdate, create the control, and populate it with the desired list items.
      void CHotsView::OnInitialUpdate() 
      {
      	CView::OnInitialUpdate();
      	
      	if (::IsWindow(m_HotListCtrl.m_hWnd) == FALSE)
      	{
      		CRect rc;
      		GetClientRect(&rc);
      
      		m_HotListCtrl.Create(WS_CHILD | WS_VISIBLE, rc, this, IDC_HOTLIST_CTRL);
      		
      		m_HotListCtrl.AddItem("George Washington", IDS_PRES1, 0);
      		m_HotListCtrl.AddItem("John Adams", IDS_PRES2, 0);
      		m_HotListCtrl.AddItem("Thomas Jefferson", IDS_PRES3, 0);
      		m_HotListCtrl.AddItem("James Madison", IDS_PRES4, 0);
      		m_HotListCtrl.AddItem("James Monroe", IDS_PRES5, 0);
      		m_HotListCtrl.AddItem("John Quincy Adams", IDS_PRES6, 0);
      		m_HotListCtrl.AddItem("Andrew Jackson", IDS_PRES7, 0);
      		m_HotListCtrl.AddItem("Martin Van Buren", IDS_PRES8, 0);
      		m_HotListCtrl.AddItem("William Henry Harrison", IDS_PRES9, 0);
      		m_HotListCtrl.AddItem("John Tyler", IDS_PRES10, 0);
      	}
      }
      
    3. Handle WM_SIZE messages in your CView derived class to reposition the control.
      void CHotsView::OnSize(UINT nType, int cx, int cy) 
      {
      	CView::OnSize(nType, cx, cy);
      	
      	if (::IsWindow(m_HotListCtrl.m_hWnd))
      	{
      		CRect rc;
      		GetClientRect(&rc);
      		m_HotListCtrl.MoveWindow(&rc, TRUE);
      
      	}
      }
      

    Using the Control in a Dialog

    There is more than one way to use a custom control in a dialog, but this is the way I chose for this example.

    1. Add a button to your dialog resource. Make it the size you desire for the control.
    2. Use ClassWizard to add to your dialog class, a CButton data member for the button. Change the CButton declaration to CHotListCtrl.
      class CTestDlg : public CDialog
      {
      // Construction
      public:
      	CTestDlg(CWnd* pParent = NULL);   // standard constructor
      
      // Dialog Data
      	//{{AFX_DATA(CTestDlg)
      	enum { IDD = IDD_TEST_DIALOG };
      	CHotListCtrl	m_HotListCtrl;
      	//}}AFX_DATA
      
      [snip]
    3. Process your WM_INITDIALOG message for the dialog. In your WM_INITDIALOG handler, call CHotListCtrl::Initialize(), and populate the control with the desired list items.
      BOOL CTestDlg::OnInitDialog() 
      {
      	CDialog::OnInitDialog();
      	
      	// very important to call initialize here!
      	m_HotListCtrl.Initialize();
      
      	CRect rc;
      
      	m_HotListCtrl.AddItem("George Washington", 0, 0);
      	m_HotListCtrl.AddItem("Thomas Jefferson", 0, 0);
      	m_HotListCtrl.AddItem("John Adams", 0, 0);
      	m_HotListCtrl.AddItem("John Tyler", 0, 0);
      	m_HotListCtrl.AddItem("Millard Fillmore", 0, 0);
      	
      	return TRUE;  // return TRUE unless you set the focus to a control
      	              // EXCEPTION: OCX Property Pages should return FALSE
      }

    Filling CHotListCtrl

    Use the following functions to fill the list control:

    void CHotListCtrl::AddItem(CString strText, UINT nToolTipID, DWORD dwData);
    void CHotListCtrl::AddItem(UINT nIDText, UINT nToolTipID, DWORD dwData);
    
    strText is the text to display for the list item.
    nIDText is the resource string identifier of the text to display for the list item
    nToolTipID is the resource string identifier of the text to display for the list item.
    dwData is the data member for the list control item.

    CHotListCtrl Notifications

    When a new list control item is selected, the control sends a WM_HOT_LIST_CHANGED (user-defined) message is sent to the parent window, with the following parameters:

    wParam is the number of the newly selected item in the list (zero-based).
    lParam is the dwData member for the newly selected item.

    Don't forget to define WM_HOT_LIST_CHANGED somewhere in your application, such as stdafx.h.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Robert Pittenger, MCPD-EAD
    President Starpoint Software Inc.
    United States United States
    Bob Pittenger is founder and President of Starpoint Software Inc. He holds a B.A. degree from Miami University, M.S. and Ph.D. degrees from Purdue University, and an MBA from Xavier University. He has been programming since 1993, starting with Windows application development in C++/MFC and moving to C# and .NET around 2005 and is a .NET Microsoft Certified Professional Developer.
     
    Bob is the author of two books:
    Billionaire: How the Ultra-Rich Built Their Fortunes Through Good and Evil and What You Can Learn from Them
    and
    Wealthonomics: The Most Important Economic and Financial Concepts that Can Make You Rich Fast.
    Visit http://www.billionairebook.net for more information.

    Comments and Discussions

     
    NewsI need it very much,but I can't dowload it. PinmemberJay Zhou17-May-06 16:45 
    GeneralSOS ,Please answer me rapidly Pinmembervahid.k1LOO3-Aug-05 11:50 
    GeneralSOS ,Please answer me rapidly Pinmembervahid.k1LOO3-Aug-05 11:43 
    GeneralNo horizontal scroll !!!!!!!!!!!!!!!!!!!!! PinmemberSuhredayan P6-Mar-04 2:19 
    GeneralRe: No horizontal scroll !!!!!!!!!!!!!!!!!!!!! PinmemberRick York15-Jul-05 14:00 
    GeneralMultiple Selections PinmemberRon16-Dec-00 2:02 
    GeneralRe: Multiple Selections Pinmembervandana.g15-Jan-04 15:13 
    GeneralGreat control; one minor issue... PinsussPaul E. Bible15-May-00 5:03 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Mobile
    Web02 | 2.8.140721.1 | Last Updated 14 May 2000
    Article Copyright 2000 by Robert Pittenger, MCPD-EAD
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Service
    Layout: fixed | fluid