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: