viksoe.dk

LED control

LED control


This article was submitted .


This is a LED control. I never quite understood why they are so popular, because there can't possibly be that many applications where they are needed. But, nevertheless, a WTL LED control was suggested by a site reader.

The control displays digits and a number of commonly used glyphs (colon, comma, etc.). The size of the text is governed by the height of the control, but can be refined by increasing the margins around the text.

The LED control supports the custom draw service, which gives the ability to customize the appearance of the LED text. When a control provides this service, it sends the NM_CUSTOMDRAW message at specific times during drawing operations. The lParam parameter of the NM_CUSTOMDRAW message is a pointer to an NMLEDCUSTOMDRAW structure, which contains the information that is necessary to draw the customized text. It is possible to use the WTL CCustomDraw class to catch these messages. There is also a number of settings in the custom draw structure that can be changed during the OnPrePaint phase. If you wish to paint your own LED segments, use the OnItemPrePaint phase to custom draw each character.

How to use it

To use it, place a label (STATIC) control on your dialog.
Add a member variable to your dialog implementation file...
CLedCtrl m_ctrlLED
In the OnInitDialog() event handler, add the following lines:
LRESULT OnInitDialog(UINT /*uMsg*/, 
                     WPARAM /*wParam*/, 
                     LPARAM /*lParam*/, 
                     BOOL& /*bHandled*/)
{
  ...
  m_ctrlLED.SubclassWindow(GetDlgItem(IDC_LED1));
  m_ctrlLED.SetWindowText("0123456789");
  ...
}

The control does not support the Win32 GetWindowText() API.

Source Code Dependencies

Microsoft Visual C++ 6.0
Microsoft WTL 7.0 Library

Download Files

DownloadSource Code (4 Kb)

To the top