Static LED control - CDigiStatic 1.3
来源:互联网 发布:海城市教育局网通知 编辑:程序博客网 时间:2024/06/14 08:39
Overview
This article presents a CStatic
derived class for displaying numbers or text like a LED Display. Thiscontrol does not use bitmaps. Everything is drawn with lines and Bezier curves. First I made some classes to draw a character, which consists of segments that can be any closed shape, by only giving some points. The points can be connected by lines or by Bezier curves to make nice smoothened characters. The theory of fitting Bezier curves can be found inbezdist.pdf, created by Jim Fitzsimmons, in my demo project cabinet. TheCDigiStatic
resizes itself automatically, which can be experienced with the demo app, wherefore I used the resizing dialog code from Hans Bühler.
To design the characters I looked around for different styles. The best inspiration came out of my car. I used characters from the date/time/temperature display and from my RDS-radio. 14- and 7-segment displays in straight and smooth style are supported and one common character for displaying a decimal point or a colon. I changed the designs a lot to get aesthetically best results, but I didn't go crazy by changing all the points every time because I do some nifty mirroring for most of the segments. For example I only specified 5 segments for the 14 segment display.
The demo application shows all possibilities of this control.
Overview of possible Characters
These are normalized characters with all segments turned on in all styles. The coordinates of these pictures were used to find the corners and Bezier points. You can adjust the coordinates or dimensions if you like. Then you can take them over to the source the same way as I did. The height of every design is the same only the width may be different, necessary for easy scaling.
Public Functions
SetText
void SetText(LPCTSTR lpszText);
Call this function to set the text of the control. For more info seeSetDrawImmediately()
Format
![](http://www.codeproject.com/images/minus.gif)
void Format(LPCTSTR lpszFormat, ...);void Format( UINT nFormatID, ... );
Call this member function to write formatted data to a CDigiStatic
in the same way thatsprintf
formats data into a C-style character array. This function formats and stores a series of characters and values in theCDigiStatic
. Each optional argument (if any) is converted and output according to the corresponding format specification inlpszFormat
or from the string resource identified by nFormatID
.
SetColor
void SetColor(COLORREF OffColor, COLORREF OnColor);
Sets the on and off color of the segments of the CDigiStatic
control. Segments that are off will not be painted when the DS_NO_OFF
style is used.
GetOnColor
COLORREF GetOnColor() const
Call this member function to retrieve the color that is used to indicate the segment is on
GetOffColor
COLORREF GetOffColor() const
Call this member function to retrieve the color that is used to indicate the segment is off
SetDrawImmediately
void SetDrawImmediately(BOOL Enable = TRUE);
If Enable
set to TRUE
a call to SetText()
orFormat()
will redraw the window before the function returns. If Enable
set to FALSE
(the default of CDigiStatic
) the client area is marked for painting when the nextWM_PAINT
message occurs.
SetBkColor
COLORREF SetBkColor(COLORREF BackColor = BLACK);
Sets the current background color to the specified color and returns the previous background color. The value of the background color will be ignored when Transparency mode is enabled.
SetTransparent
void SetTransparent(BOOL bSet = TRUE);
Set to TRUE
only the segments will be drawn and the background will be transparent and show the window underneath it. Nice if you use a skinned window. Set toFALSE
will fill the background with the current background color.
ModifyDigiStyle
BOOL ModifyDigiStyle(DWORD dwRemove, DWORD dwAdd);
With the ModifyDigiStyle
function you can add or remove specific CDigiStatic
styles. The styles, which can be combined by using the bitwise OR ( | ) operator, are:
CDigiStatic::DS_SMOOTH // Smooth kind of characters
CDigiStatic::DS_STYLE14 // use always 14 segment display.
CDigiStatic::DS_SZ_PROP // size proportional(default)
CDigiStatic::DS_NO_OFF // Don't draw the off segments
CDigiStatic::DS_SOFT // ambient bleeding to background
How to use (in a dialog):
- Add digistatic.h, digistatic.cpp, memdc.h, curvefit.h, curvefit.cpp and rgbcolor.h to your project environment.
- Add a static control to your dialog resource.
- Change its ID to something like
IDC_LEDTEXT
, open class-wizard and assign a member variable, typecontrol (CStatic
) to it (m_LedText
for example). - Open your dialog class's header file. Add
#include "digistatic.h"
. Find the lineCStatic m_LedText
and replace theCStatic
byCDigiStatic
. - In
OnInitDialog()
you can give it some text withSetText()
, change the colors withSetColor()
or for the backgroundSetBkColor()
. Or, you can set the right style withModifyDigistyle()
. - Compile and run.
Acknowledgements
- Hans Bühler - For using his resizing software for the demo application.
- Keith Rule - For creating the memdc class for flickerfree drawing. Modified for support of transparent background
- Massimo Colurcio - HMX controls for making a skinned demo application easy.
- Daniel DeGeest - For helping me with transparency, testing and suggestions.
History
VersionComments1.0 February 2000First release version. Finally I could say goodbye to my old class with bitmaps and enjoy the new quality. This nicecontrol just had to be shared1.1 April 2001Use Caption as default text. Changed from STL to Afx templates. After a suggestion I changedSetBackColor
to SetBkColor
. I apologize for keeping this baby for myself because I wanted to add and change more1.2 May 2002Added option to draw immediately. Changed CDigiString
to CDigiStatic
because it is a derived from a Staticcontrol. After giving no problems for long time it was ready to be released again1.3 October 2002Added transparency option with help of Daniel. Introduction of 5 new characters/\[]' (suggested by daniel for using in his great Winamp plugin). Added newDS_NO_OFF
and DS_SOFT
styles to respectively not to show segments that are "off" and to remove the soft edge of a segment. Improved demo app with skin was created to show all the options. This will be the third release and I call it the "feature update"- Static LED control - CDigiStatic 1.3
- [Win32SDK基本]Static Control(2)Image Static Control
- set bitmap to static control
- Static control 透明,重影,长度问题
- chmod 777 wiringpi.ini to control LED on Linux
- Use Retation Sensor to control the brightness of LED lights
- HERO Lighting Technology Co., Ltd.—High Power LED Luminaire and LED Control System Manufacturer
- [Win32SDK基本]Static Control(1)Text Static Control 和 WM_CTLCOLORSTATIC
- led
- LED
- led
- led
- led
- LED
- led
- LED
- LED
- LED
- 栈(链式)
- 1015. 德才论 (25)
- 数据结构--希尔排序
- HDU 3394 Railway 无向图的桥与点-双连通
- 使用一个指针实现双向链表
- Static LED control - CDigiStatic 1.3
- mysql 开启远程访问
- 学习总结二十三:深入学习hbase数据库
- 新热风:美式家具
- 2014工大校赛题目以及解
- C++ 显式转换 。
- 使用Maven进行lib管理带来的问题
- 关于在android 图像开发中使用Skia引擎的注意事项
- Android_WebView_全屏