(In the process of industrial control program development, VC is often used as the development platform. The core of the communication process with peripheral devices such as PLC usually involves analog communication and digital communication with these peripheral devices, and the current node/point status is collected. In the process of software development of the host computer, many methods can be used to indicate the status of these collected points, such as 1, 0, etc. If we choose an LED that can dynamically change color to display digital nodes/points, use a digital clock to display If the analog quantity is used, the program will be better in terms of humanized interface. The following program briefly introduces a method of inheriting the cstatic class to implement an LED control to dynamically display the digital signal collected by the peripheral device.
text
The digital node/point signal is nothing more than a signal of 0 or 1 that we use the serial port or other communication ports to communicate with external devices, and parses the communication protocol into a signal of 0 or 1. More conditions are no conditions. In the usual industrial control In the program, we usually like to use red to indicate the status, that is, 1, green for no status, that is, 0, yellow for invalid status, we can define it as 2 here. Then, if we think about the extensibility of the program's controls, we can Define multiple background colors. In this control, we define 4 colors, RED, GREEN, YELLOW, BLUE, if we need more, we can define them flexibly.
typedefenumtagItemCOLOR{RED,GREEN,BLUE,YELLOW};
At the same time, let's define the background display mode of the control. The usual LEDs are displayed as circles, but the LEDs of some controls are squares, so we also think about defining them.
#defineID_SHAPE_ROUND3001
#defineID_SHAPE_SQUARE3002
First, inherit a new class named CStateLedCtrl, inherit CStatic, and map the message WM_PAINT. We will make the scene here, which can be easily implemented.
voidCStateLedCtrl::OnPaint()
{
CPaintDCdc(this);//devicecontextforpainting
//TODO:Addyourmessagehandlercodehere
//DonotcallCStatic::OnPaint()forpaintingmessages
//GettheDeviceContext
//Gettherectangleofthewindowwherewearegoingtodraw
CRectrcClient;)