How to fix the color of a brush multiple times in GDI paint

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.