First create a Brush object:
CPen Gpen;
Gpen.createpen (Ps_solid, 1, RGB (120,120,130));//brush with a certain grayscale
cpen* Poldpen = Pdc->selectobject (&gpen);
The brush cannot be modified once it has been created. So to modify the color of the brush to use the DeleteObject function to delete it?, and then create a new brush.
The following is a brush that is modified to red:
Gpen.deleteobject ();
Gpen.createpen (ps_solid,1, RGB (255, 0, 0));
Poldpen = Pdc->selectobject (&gpen);
The last sentence above must be added. Otherwise the newly created brush color will not change.
This is written in a single document program, before the origin of the PDC. As follows:
chelloworddoc* PDoc = GetDocument ();
Assert_valid (PDOC);
if (!pdoc)
Return
cdc* PDC = GetDC ();
Analyze CreatePen functions
Hpen CreatePen (int npenstyle, int nwidth, COLORREF crcolor);
? Parameters:
Npenstyle:---Long, specifies the brush style, which can be one of the following constants
Ps_solid: The brush draws a solid line
Ps_dash: The brush draws a dashed line (nwidth must be no greater than 1)
Ps_dot: The brush draws a point line (nwidth must be no greater than 1)
Ps_dashdot Brush Draws a dash (nwidth must be no more than 1)
Ps_dashdotdot Brush Draws a point-dot-dash (nwidth must not be greater than 1)
Ps_null brushes cannot draw
Ps_insideframe the line width expands inward when the enclosing object frame is generated by an ellipse, rectangle, rounded rectangle, pie chart, and chord. Jitter processing if the exact RGB color specified does not exist
nwidth ---Long, the width of the brush in logical units
crcolor ---Long, the RGB color of the brush
Note : Once the brush is created no longer requires a brush, remember to delete it with the DeleteObject function.
How to fix the color of a brush multiple times in GDI paint