Windows API one-day training (32) createpen Function

Source: Internet
Author: User
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}

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.