Experience in using the GDI polygon filling function

Source: Internet
Author: User

Author: Zhu Jincan

Source: http://blog.csdn.net/clever101


Recently, using GDI, we found that its polygon (HDC, APT, icount) function will plot the polygon boundary. The Code is as follows:

Case wm_paint: <br/>{< br/> HDC = beginpaint (hwnd, & PS); <br/> logbrush log_brush; <br/> log_brush.lbcolor = RGB (255, 0, 0); <br/> log_brush.lbstyle = bs_solid; <br/> hbrush hnewbrush =: createbrushindirect (& log_brush); <br/> hbrush holdbrush = selectbrush (HDC, hnewbrush ); <br/> point PT [4]; <br/> PT [0]. X = 10; <br/> PT [0]. y = 10; <br/> PT [1]. X = 10; <br/> PT [1]. y = 100; <br/> PT [2]. X = 100; <br/> PT [2]. y = 100; <br/> PT [3]. X = 100; <br/> PT [3]. y = 10; <br/> polygon (HDC, PT, 4); <br/> log_brush.lbcolor = RGB (0,255, 0); <br/> hbrush hnewbrush2 = :: createbrushindirect (& log_brush); <br/> selectbrush (HDC, hnewbrush2); <br/> PT [0]. X + = 90; <br/> PT [0]. y = 10; <br/> PT [1]. X + = 90; <br/> PT [1]. y = 100; <br/> PT [2]. X + = 90; <br/> PT [2]. y = 100; <br/> PT [3]. X + = 90; <br/> PT [3]. y = 10; <br/> polygon (HDC, PT, 4); <br/>


As follows:



It can be seen that the boundary of the polygon is drawn using a black line. Obviously, this is drawn using the default paint brush. However, in some cases, you do not need to draw borders. In this case, we need to create a new paint brush in the same color as the paint brush and select DC to replace the system default paint brush. Modify the above Code as follows:


Case wm_paint: <br/>{< br/> HDC = beginpaint (hwnd, & PS); <br/> logbrush log_brush; <br/> log_brush.lbcolor = RGB (255, 0, 0); <br/> log_brush.lbstyle = bs_solid; <br/> hbrush hnewbrush =: createbrushindirect (& log_brush); <br/> hbrush holdbrush = selectbrush (HDC, hnewbrush ); <br/> logpen log_pen; <br/> log_pen.lopncolor = RGB (255, 0); <br/> log_pen.lopnstyle = ps_solid; <br/> log_pen.lopnwidth.x = 1; <br/> Hpen hnewpen =: createpenindirect (& log_pen); <br/> Hpen holdpen = selectpen (HDC, hnewpen); <br/> point PT [4]; <br/> PT [0]. X = 10; <br/> PT [0]. y = 10; <br/> PT [1]. X = 10; <br/> PT [1]. y = 100; <br/> PT [2]. X = 100; <br/> PT [2]. y = 100; <br/> PT [3]. X = 100; <br/> PT [3]. y = 10; <br/> polygon (HDC, PT, 4); <br/> log_brush.lbcolor = RGB (0,255, 0); <br/> hbrush hnewbrush2 = :: createbrushindirect (& log_brush); <br/> selectbrush (HDC, hnewbrush2); <br/> log_pen.lopncolor = RGB (0,255, 0); <br/> Hpen hnewpen2 = :: createpenindirect (& log_pen); <br/> selectpen (HDC, hnewpen2); <br/> PT [0]. X + = 90; <br/> PT [0]. y = 10; <br/> PT [1]. X + = 90; <br/> PT [1]. y = 100; <br/> PT [2]. X + = 90; <br/> PT [2]. y = 100; <br/> PT [3]. X + = 90; <br/> PT [3]. y = 10; <br/> polygon (HDC, PT, 4); <br/> selectbrush (HDC, holdbrush); <br/> selectpen (HDC, hnewpen ); <br/> endpaint (hwnd, & PS); <br/> return 0; <br/>}< br/>


As follows:









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.