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


, 3 Mar 2000
Rate this:
Please Sign up or sign in to vote.
A button that looks like a LED.

Sample Image - CLedButton.jpg


class CLedButton : public CButton (version 1.0)

This is a class which displays a LED that has 2 states: ON or OFF. The LED can have some text on its right. The LED is read-only (on user side) and cannot have focus (you should disable "tab stop" in the resource). The disabled state is not implemented: it is exactly like the enable state.

How to use CLedButton:

  1. To your dialog, add either a button, a checkbox or a radio button.
  2. Bind it to a member variable (of type Control) using Class Wizard.
  3. Then change in the header file, the class type to CLedButton.
  4. In InitDialog(), bind your bitmap resource to the button:
    m_greenLed.SetImage( IDB_LEDBUTTON_GREEN, 15 );
    //15 is the width of one image in the bitmap
  5. You can set or retrieve the state of the LED (ON or OFF) using the following member:
    m_greenLed.Depress(TRUE);  //ON  (second image in bitmap)
    m_greenLed.Depress(FALSE); //OFF (first image in bitmap)

The bitmaps are given with the source code:

  • greenButton.bmp
  • redButton.bmp

Please visit: for updates, other sources and more!

The sample project was compiled with Visual C++ 6 (MFC 4.2 ) and not tested with Unicode.


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

Benjamin Mayrargue

United States United States
No Biography provided

Comments and Discussions

GeneralKingPower PinmemberKingPeng25-Jun-06 1:57 
GeneralRe: KingPower Pinmemberzaodt8-May-07 8:29 
GeneralCorrected Class PinmemberDevil for ever18-May-06 9:36 
GeneralAnomally behavior with several controls PinsussAnonymous6-Mar-05 22:48 
GeneralProblem with CFormView PinmemberSeve Ho21-Jul-04 21:31 
QuestionHow to get Tab order and garyed status Pinmembertiousi18-Dec-03 6:45 
Generaldynamically creation of CLedButton Pinmembersilverspoon15-Jul-02 3:15 
GeneralLedButtons with Dialog BAr Pinmembermurd26-Jan-02 5:14 
GeneralPoor Plagiarism PinmemberBill Gates Antimatter Particle25-Nov-01 7:15 
GeneralRe: Poor Plagiarism PinmemberShaun Harrington21-Feb-06 13:12 
GeneralRed - Green Toggle PinmemberMarkKozel6-Nov-01 12:09 
GeneralMinor alignment bug... PinmemberKevin Pinkerton6-Jun-01 6:01 
GeneralRe: Minor alignment bug... PinmemberAnonymous6-Jun-01 8:30 
QuestionIf I do dialog docking, how I can show LED Button and control? PinmemberHeon30-Mar-01 18:02 
AnswerRe: If I do dialog docking, how I can show LED Button and control? PinmemberAnonymous6-Jun-01 5:22 
Generalcledbutton PinsussKunle Adeleye18-Jun-00 14:43 
GeneralRe: cledbutton PinsussBenjamin Mayrargue20-Jul-00 6:53 
GeneralRe: cledbutton PinmemberKevin Pinkerton6-Jun-01 3:35 

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.140827.1 | Last Updated 4 Mar 2000
Article Copyright 2000 by Benjamin Mayrargue
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid