Source File
The edit box is one of the commonly used controls, and it is also a complicated control with full self-implementation. In this example, a simple self-drawing of the editing box is implemented, while retaining its own powerful functions, the border, background, text color, and disabled color of the editing box are replaced.
To re-paint, we must know what to paint. By observing the default editing box, we can clearly see that the editing box has three basic parts that need to be drawn, which are 3D border, background, and text, further analysis shows that they are two parts of a basic window, namely the customer zone and non-customer zone. In this way, we will know what functions should be used to draw specific areas. As the source code is provided, we will only discuss the basic principles and technical details here, but will list them in many places.Code.
In order to draw non-customer zones, I have reloaded the onncpaint function. This function can easily remove the 3D appearance of the editing box and draw it as we want. As for the customer area, I did not reload the onpaint function to keep the edit box cursor blinking, character processing, automatic return, and other functions. That is to say, I did not redraw the customer area, but chose an alternative method.
The edit box is used to edit the text, and all we want to change is the text and background color. Through this analysis, we will know what we need to do, that is, set the text color and background color. The method I used is to overload the ctlcolor function. In the function, different colors are set based on the different States that are disabled and enabled in the edit box, which achieves the expected purpose.
Strictly speaking, I did not re-paint the edit box, but simply drew the edge, but it also achieved the expected results. Of course, there are still many unsatisfactory examples. If you have better ideas, we hope we can share them with you.