Windows API one-day training (33) extcreatepen Function

Source: Internet
Author: User
When you use the createpen function described above to draw a straight line greater than 1, you will find that the two ends of the straight line are all rounded corners. Sometimes you need to draw an angle, so this function will not meet your needs, in this case, you need to use another API function extcreatepen to create a suitable paint brush. The extcreatepen function can be used to create a geometric paint brush or a decorative paint brush. The decorative paint brush is used to draw some patterns. In this way, a quick algorithm is required, the display speed is much faster than that of the geometric paint brush. For example, when you are drawing a GPS map, you can use this paint brush when you need to describe the pattern, which will significantly increase the display speed.

The extcreatepen function declaration is as follows:
Wingdiapi Hpen winapi extcreatepen (_ in DWORD ipenstyle,
_ In DWORD cwidth,
_ In const logbrush * plbrush,
_ In DWORD cstyle,
_ In_ecount_opt (cstyle) const DWORD * pstyle );
IpenstyleIs the paint brush type.
CwidthIs the width of the paint brush. The width must be set to 1 when creating a decorative pen.
PlbrushIs the property of the paint brush.
CstyleIs the number of custom style arrays.
PstyleIs a custom style array.

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 logbrush Lb;
#016 lb. lbstyle = bs_solid;
#017 lb. lbcolor = RGB (0, 0, 255 );
#018 lb. lbhatch = 0;
#019
#020 // create a decorative pen.
#021 Hpen = extcreatepen (ps_cosmetic | ps_dash,
#022 1, & Lb, 0, null );
#023
#024 // set the paint brush of the current device.
#025 hgdiobj holdpen = SelectObject (HDC, Hpen );
#026
#027 // draw a straight line from (10, 10) to (100,100.
#028 ptlefttop. x = 100;
#0 29 ptlefttop. Y = 100;
#030 lineto (HDC, ptlefttop. X, ptlefttop. y );
#031
#032 // create an endpoint that is a flat brush.
#033 Hpen hpengeom = extcreatepen (ps_geometric | ps_solid |
#034 ps_endcap_flat, 16, & Lb, 0, null );
#035
#036 SelectObject (HDC, hpengeom );
#037 // draw a straight line from (100,100) to (10,100.
#038 ptlefttop. x = 10;
#039 ptlefttop. Y = 100;
#040 lineto (HDC, ptlefttop. X, ptlefttop. y );
#041
#042 // create a paint brush whose endpoint is rounded.
#043 Hpen hpengeomround = extcreatepen (ps_geometric | ps_solid |
#044 ps_endcap_round, 16, & Lb, 0, null );
#045
#046 SelectObject (HDC, hpengeomround );
#047 // draw a straight line from (10,100).
#048 ptlefttop. x = 10;
#049 ptlefttop. Y = 10;
#050 lineto (HDC, ptlefttop. X, ptlefttop. y );
#051
#052
#053 // restore the original paint brush.
#054 SelectObject (HDC, holdpen );
#055
#056 // Delete the created paint brush.
#057 deleteobject (Hpen );
#058 deleteobject (hpengeom );
#059 deleteobject (hpengeomround );
#060
#061}

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.