CbuttonListBox, a ListBox Populated with LED Buttons

Environment: Developed and tested on Win2000 using VC6

Recently, I needed to present a user interface incorporating a large number of buttons. Each button caused an activity to start and would run for an indeterminate length of time. I wanted to indicate this activity and associate it with the button that started it.

I came up with CbuttonList, a list box populated with buttons containing a flashing LED to show activity (an example of Monte Variakojis' excellent CLed class). CbuttonListBox is a simple example of sub classing of CButton and ClistBox. It is easy to implement; just follow these steps:

  1. Copy the LED bitmap into the res directory of your project.
  2. Copy CLed.cpp and .h, CbuttonListBox.cpp and .h, CledButton.cpp and .h files into your project directory and add them to your project through the IDE.
  3. Add a Bitmap resource to the project and name it IDB_LEDS.
  4. Place a list box on your dialog and alter its properties as below:
    1. Selection - Single
    2. Owner Draw - Fixed
    3. Check Notify
    4. Check Vertical Scroll Bar
    5. Check No Integral Height
  5. Add a member variable for the ListBox and change its type to CbuttonListBox in the header (having added the #include "ButtonListBox.h" in your Dialog header).
  6. In the OnInitDialog method of the dialog, you can add your buttons to the list, passing a String to be the buttons text.
  7.   m_ButtonListBox.AddItem("Test 1");
    There is a #define in CbuttonListBox.h that controls the number of buttons placed in the ListBox. This may need to be altered based on the size of your ListBox on your dialog.
      #define NUMBER_OF_BUTTONS_IN_LIST_VIEW 10    // 10 buttons
    When a button is clicked, a message is posted to the CbuttonListBox class with the Buttons this pointer as an lParam. This allows the click to be associated with a particular button. Code must be added to the PreTranslateMessage(MSG* pMsg) method in the CbuttonListBox class to handle these events.

Thats It! I hope this is of some use to you. Feel free to use these classes any way you like. Any comments or improvements would be appreciated.

Downloads

Download demo project - 38 Kb
Download source code - 9 Kb


Comments

  • I have a problem about "Afxtempl.h"

    Posted by Legacy on 07/01/2003 12:00am

    Originally posted by: Tony Hong

    Thanks your source code...

    but i don't know "Afxtempl.h"

    I will wait your answer..

    Reply
  • I have done some thing similar

    Posted by Legacy on 04/30/2003 12:00am

    Originally posted by: Dr.Sai

    Good work I have done some thing similar I will post it one day.

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • With the average hard drive now averaging one terabyte in size, the fallout from the explosion of user-created data has become an overwhelming volume of potential evidence that law-enforcement and corporate investigators spend countless hours examining. Join Us and SANS' Rob Lee for our 45-minute webinar, A Triage and Collection Strategy for Time-Sensitive Investigations, will demonstrate how to: Identify the folders and files that often contain key insights Reduce the time spent sifting through content by …

Most Popular Programming Stories

More for Developers

RSS Feeds