Click here to Skip to main content
15,890,438 members
Articles / Desktop Programming / MFC
Article

CLedButton

Rate me:
Please Sign up or sign in to vote.
4.47/5 (11 votes)
3 Mar 2000 284.1K   4.9K   77   18
A button that looks like a LED.

Sample Image - CLedButton.jpg

Introduction

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: http://welcome.to/softbird for updates, other sources and more!

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

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralKingPower Pin
KingPeng25-Jun-06 1:57
KingPeng25-Jun-06 1:57 
GeneralRe: KingPower Pin
zaodt8-May-07 8:29
zaodt8-May-07 8:29 
GeneralCorrected Class Pin
Devil for ever18-May-06 9:36
Devil for ever18-May-06 9:36 
GeneralAnomally behavior with several controls Pin
Anonymous6-Mar-05 22:48
Anonymous6-Mar-05 22:48 
GeneralProblem with CFormView Pin
Seve Ho21-Jul-04 21:31
Seve Ho21-Jul-04 21:31 
QuestionHow to get Tab order and garyed status Pin
tiousi18-Dec-03 6:45
tiousi18-Dec-03 6:45 
Generaldynamically creation of CLedButton Pin
silverspoon15-Jul-02 3:15
silverspoon15-Jul-02 3:15 
GeneralLedButtons with Dialog BAr Pin
murd26-Jan-02 5:14
murd26-Jan-02 5:14 
GeneralPoor Plagiarism Pin
Bill Gates Antimatter Particle25-Nov-01 7:15
Bill Gates Antimatter Particle25-Nov-01 7:15 
This is obviously badly hacked code originating from Chris Maunders excellent CRoundbutton class. Its obviously not a bad idea and id rather see it posted than not. However 'plagiarism' is a poor form of vanity. You should have said something like 'Hi, im a total beginner and I hacked chris' code and came up with this half baked class that sort of works. Are there any real programmers out there willing to take this idea and implement it properly?'. I may have a go myself at some point, although im sure there are plenty of others who could do better than this. To get the buttons to click on and off for example, all you need is something like :

void CLedButton::OnLButtonDown(UINT nHitTest, CPoint point)
{
SetCheck(!GetCheck());
RedrawWindow();
CButton::OnLButtonDown(nHitTest, point);
}

Eek! | :eek:

While Im here ive a question for everyone :

Is there any way of accessing the dc for the default radio button itself?
I dont mean the whole button (which is easy eg letting the parent receive the WM_CTLCOLORSTATIC message). How is the white circle created and where. And can it be accessed? Can the black dot check be accessed? I want to be able to change the colour of the dot in the radio button without recourse to BS_OWNERDRAW and bitmaps. Anybody have any ideas about this?

"Life begins at 140"
GeneralRe: Poor Plagiarism Pin
Shaun Harrington21-Feb-06 13:12
Shaun Harrington21-Feb-06 13:12 
GeneralRed - Green Toggle Pin
Mark Kozel6-Nov-01 12:09
Mark Kozel6-Nov-01 12:09 
GeneralMinor alignment bug... Pin
Kevin Pinkerton6-Jun-01 6:01
Kevin Pinkerton6-Jun-01 6:01 
GeneralRe: Minor alignment bug... Pin
6-Jun-01 8:30
suss6-Jun-01 8:30 
QuestionIf I do dialog docking, how I can show LED Button and control? Pin
30-Mar-01 18:02
suss30-Mar-01 18:02 
AnswerRe: If I do dialog docking, how I can show LED Button and control? Pin
6-Jun-01 5:22
suss6-Jun-01 5:22 
Generalcledbutton Pin
Member 55024118-Jun-00 14:43
Member 55024118-Jun-00 14:43 
GeneralRe: cledbutton Pin
Benjamin Mayrargue20-Jul-00 6:53
Benjamin Mayrargue20-Jul-00 6:53 
GeneralRe: cledbutton Pin
Kevin Pinkerton6-Jun-01 3:35
Kevin Pinkerton6-Jun-01 3:35 

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

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