Static LED Control

Environment: Compiled using VC6.0 Sp3 and tested using Win95/98 WinNT4.0 and Win 2000

Sometimes you find yourself needing an indicator to reflect various statuses. For example, receive and transmit on a modem. The following article is a simple LED static class.

The CLed class is a static control for a simple LED control and is derived from the CStatic class. Using a single bitmap of an LED array, the BitBlt function is used to index through the bitmap for the appropriate LED. Note that the bitmap has a mask color of RGB(255,0,255) in order to make the LED appear to be transparent.

LED Matrix
Led Matrix bitmap

The code assumes LEDs of 16 X 16 pixels, but is not limited to that. If you decide to that smaller or larger LEDs are necessary, than set the LED_SIZE to the size desired and modify the LED bitmap matrix to reflect the change.

Implementation

Using the CLed class is very simple when using the MFC Class Wizard Dialog. Within a dialog, use the following steps to add an LED.

  1. Insert a new static frame where you want the LED.
  2. Rename the static frame to somthng other than IDC_STATIC. Name it somthing like IDC_LED.
  3. Using the MFC ClassWizard, add a new member valiable for IDC_LED. The catagory should be a control and the Variable Type should be CLed. If CLed type does not show up in the Variable type dropdown, then you need to recreate the .clw file. I.E. delete the .clw file and run the Wizard Dialog again.
  4. Make sure that you include Led.h in you dlg.h file.

Also, you need to create a IDB_LEDS resource. Leds.bmp is included to help you do this. In the LedDemo project, there is also a demonstration on adding the CLed static control within a CView class.

Operations

void SetLed( int nLedColor, int nMode, int nShape );

Parameters

nLedColor - Specifies LED color. You can use the following attributes:

CLed::LED_COLOR_RED
CLed::LED_COLOR_GREEN
CLed::LED_COLOR_YELLOW
CLed::LED_COLOR_BLUE

nMode - Specifies LED mode where:

CLed::LED_ON - Turn on LED
CLed::LED_OFF - Turn off LED
CLed::LED_DISABLE - Disable LED

nShape  Specifies round or square LED where:

CLed::LED_ROUND - specifies a round LED
CLed::LED_SQUARE - specifies a square LED

Remarks
Use this method to set and display the LED to the preferred color and mode.

void Ping( DWORD dwTimeout = 1000 );

Parameters

dwTimeout - Specifies the duration that the led is on in milliseconds.

Remarks
Use this function when a short "ON" duration is needed for an LED operation. The LED will automatically turn for the duration specified and then turn off.

 

Downloads

Download demo project - 32KB
Download source - 4KB


Comments

  • There are no comments yet. Be the first to comment!

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

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: October 23, 2014 @ 12:00 p.m. ET / 9:00 a.m. PT Despite the current "virtualize everything" mentality, there are advantages to utilizing physical hardware for certain tasks. This is especially true for backups. In many cases, it is clearly in an organization's best interest to make use of physical, purpose-built backup appliances rather than relying on virtual backup software (VBA - Virtual Backup Appliances). Join us for this eSeminar to learn why physical appliances are preferable to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds