Painting focuses on colors and lines. Different places use different paint brushes. The above shows a straight line, which uses the device's default paint brush to draw a straight line. Now we will introduce how to create your own paint brush, such as setting the color and size of the paint brush. For example, if a Windows button is displayed in a 3D shape, a button is generated by drawing the corresponding lines with two color brushes. To create a paint brush, you must use the createpen function.
The createpen function declaration is as follows:
Wingdiapi Hpen winapi createpen (_ in int istyle, _ in int cwidth, _ in colorref color );
IstyleIs the paint brush type, such as solid line or dotted line.
CwidthIs the width of the line.
ColorIs the color of the line.
An example of calling this function is as follows:
#001 //
#002 // The output is displayed on the interface.
#003 //
#004 // Cai junsheng 2007/09/10 QQ: 9073204 Shenzhen
#005 //
#006 void ccaiwinmsg: ondraw (HDC)
#007 {
#008 // move to the specified location.
#009 point ptlefttop;
#010 ptlefttop. x = 10;
#011 ptlefttop. Y = 10;
#012 movetoex (HDC, ptlefttop. X, ptlefttop. Y, null );
#013
#014 // modify the color and width of the line.
#015 Hpen = createpen (ps_solid, 10, RGB (0,255, 0 ));
#016
#017 // set the paint brush of the current device.
#018 hgdiobj holdpen = SelectObject (HDC, Hpen );
#019
#020 // draw a straight line from (10, 10) to (100,100.
#021 ptlefttop. x = 100;
#022 ptlefttop. Y = 100;
#023 lineto (HDC, ptlefttop. X, ptlefttop. y );
#024
#025 // restore the original paint brush.
#026 SelectObject (HDC, holdpen );
#027
#028 // Delete the created paint brush.
#029 deleteobject (Hpen );
#030
#031}