led数字显示程序!编写一个可用于工控数字量节点显示的LED类 作者 戚高
Tags:
led数字显示程序
| 时间: 2010:7:26 21:24:32
m_BrushDark.CreateSolidBrush(RGB(0,255,0));
// Get the rectangle of the window where we are going to draw
dc.LineTo(rcClient.right,rcClient.bottom);
// Draw the light gray lines
// I'm creating a light shade of red here for displaying the bright
// If the round shape has been selected for the control
CPaintDC dc(thellos); // device context for painting
m_BrushBright.CreateSolidBrush(RGB(0,250,0));
// see the effect on the LED control
m_PenBright.CreatePen(0, 1, RGB(250,0,0));
m_PenDark.CreatePen(0, 1, RGB(0,125,0));
m_BrushBright.CreateSolidBrush(RGB(0,0,250));
// Draw a thellon light gray coloured circle
// Do not call CStatic::OnPaint() for painting messages
Pen.CreatePen(0,2,RGB(128,128,128));
dc.SelectObject(&Pen);
详细施用要领可以参考步伐挪用掩饰Demo.演习成效如次:
if(m_BrushDark.m_hObject!=灭茬)
// so that it doesnt throw an assertion
m_BrushDark.CreateSolidBrush(RGB(0,0,150));
dc.Arc(rcClient,ptStart,ptEnd);
m_PenDark.CreatePen(0,1,RGB(0,0,150));
{
m_PenBright.DeleteObject();
dc.MoveTo(ptStart);
#define ID_SHAPE_SQUARE 3002
{
if(m_PenBright.m_hObject!=灭茬)
m_PenDark.CreatePen(0, 1, RGB(125,0,0));
Pen.CreatePen(0,1,RGB(255,255,255));
2007年11月10日
{
{
{
dc.SelectObject(&Pen);
typedef enum tagItemCOLOR{RED, GREEN, BLUE, YELLOW};
dc.LineTo(rcClient.left,rcClient.top);
m_BrushBright.DeleteObject();
// If the pen has been selected already, then we have to delete it
CPen Pen;
dc.LineTo(rcClient.right,rcClient.top);
// Draw a whellote arc at the bottom
SetLED(UINT nIDShape)
Pen.CreatePen(0,1,RGB(128,128,128));
// If the user has selected YELLOW as the color of the LED
数码量节点旌旗灯号无非就是咱们哄骗串口或另外通信端口与外部装备通信,路程经过过程通信以及谈剖析成为的0或1的旌旗灯号,更多的状况就是一种无状况.在凡似的工业节制步伐中,咱们一般喜欢用红色来暗示有状况,即1,绿色彩为无状况,即0,黄色为失效状况,咱们这搭可以界说为2.那末,要是思量到步伐的控件的扩大性,咱们可以界说多个配景色彩.这个控件内里咱们界说4种色彩,RED, GREEN, YELLOW, BLUE,要是需要更多咱们可以矫捷界说.
}
CPoint ptStart,ptEnd;
dc.SelectObject(&Pen);
}
// TODO: Add your message handler code here
Pen.DeleteObject();
先容
// The arc function is just to add a 三度空间 effect for the control
m_PenDark.CreatePen(0,1,RGB(150,150,0));
if(m_BrushBright.m_hObject!=灭茬)
在工业节制步伐研发历程中许多选用VC作为研发平台,在与PLC等外围装备通信历程中心一般城市有关到与她们这些个外围装备的摹拟量通信以及数码量通信,收罗时下节点状况.在举行上位机软体研发历程中可以用许多要领来暗示这些个收罗的点的状况,好比1,0等.要是咱们接纳1个可以兴许动态转变色彩的LED来预示数码量节点,用一种数码钟来预示摹拟量的话步伐在人道化接口方面将会比力好.底下的步伐简略的先容一种用担当cstatic类的要领来使成为事实1个LED控件来动态预示外围装备收罗到的数码量旌旗灯号.
if(m_nShape==ID_SHAPE_ROUND)
dc.SelectObject(&m_PenBright);
Pen.CreatePen(0,1,RGB(192,192,192));
CPen Pen;
// Draw the dark gray lines
// If the user has selected GREEN as the color of the LED
{
dc.Ellipse(rcClient);
Pen.DeleteObject();
else if(m_nShape==ID_SHAPE_SQUARE)
dc.SelectObject(&m_BrushBright);
dc.MoveTo(rcClient.right,rcClient.top);
Pen.DeleteObject();
dc.Ellipse(rcClient);
// LED. You can change the values to any colour that you want
// Here i'm creating a dark shade of red. You can play with the values to
}
ptStart = CPoint(rcClient.Width()/2,rcClient.bottom);
QQ:5516853
// Get the Device Context
m_PenBright.CreatePen(0,1,RGB(255,255 ,0));
// If you have decided that your LED is going to look square in shape, then
dc.FillRect(rcClient,&m_BrushCurrent);
GetClientRect(&rcClient);
}
// Draw the actual colour of the LED
// The code below gives a 三度空间 look to the control. It does nothellong more
// If the user has selected BLUE as the color of the LED
m_BrushCurrent.m_hObject = m_BrushBright.m_hObject;
dc.SelectObject(&Pen);
dc.SelectObject(&Pen);
dc.LineTo(rcClient.left,rcClient.bottom);
else if(m_itemColor == GREEN)
正文
else
// Draw the actual rectangle
m_BrushDark.DeleteObject();
dc.SelectObject(&Brush);
m_PenDark.DeleteObject();
同时咱们界说一下控件的配景预示标准样式,一般的LED咱们预示为圆圈儿,可是有些控件的LED为方形,咱们也思量举行界说.
SetSwitchState(tagItemCOLOR itemColor)
// Draw the actual ellipse
// Draw a thellock dark gray coloured circle
m_PenBright.CreatePen(0, 1, RGB(0,250,0));
}
}
if(m_PenDark.m_hObject!=灭茬)
CRect rcClient;
void CStateLedCtrl::OnPaint()
m_PenBright.CreatePen(0,1,RGB(0,0,250));
控件供给二个简略的配备布置配景外形以及色彩的接口.
if(m_itemColor == RED)
ptEnd = CPoint(rcClient.right,rcClient.top);
Brush.CreateSolidBrush(RGB(255,255,255));
CBrush Brush;
dc.MoveTo(rcClient.left,rcClient.bottom);
该Led控件只是简略的摹拟演习了一下控件的编著要领以及步调,此中因为时间瓜葛代码的封装还不是很流利,读者可以按照本身的需要举行须要的修改.但愿可以兴许对于追求这个方面控件或编程要领的人有帮忙.要是有啥子疑难题目请接洽我:
起首担当1个新类定名为CStateLedCtrl担当CStatic,照射动静WM_PAINT,咱们将在这搭举行配景的绘制就能够简略的使成为事实了.
m_BrushDark.CreateSolidBrush(RGB(150,150,0));
m_BrushBright.CreateSolidBrush(RGB(255,255,0));
dc.Ellipse(rcClient.left+10,rcClient.top+10,rcClie nt.left+12,rcClient.top+12);
#define ID_SHAPE_ROUND 3001
else if(m_itemColor == YELLOW)
}
Pen.CreatePen(0,1,RGB(192,192,192));
m_BrushBright.CreateSolidBrush(RGB(250,0,0));
dc.Ellipse(rcClient);
m_BrushDark.CreateSolidBrush(RGB(255,0,0));
{