windows - C++ Windows32 GDI Fill Triangle -
the standard way of fillrect in gdi
rectangle(hdc, x_, y_, x_ + width_, y_ + height_); but how fill triangle ? how approach without using other resources ?
use polygon function, uses current brush fill polygon.  following example draws triangle outlined in red , filled blue:
#include <windows.h> #include <windowsx.h>  ...  hpen hpen = createpen(ps_solid, 2, rgb(255, 0, 0)); hpen holdpen = selectpen(hdc, hpen);  hbrush hbrush = createsolidbrush(rgb(0, 0, 255)); hbrush holdbrush = selectbrush(hdc, hbrush);  point vertices[] = { {200, 100}, {300, 300}, {100, 300} }; polygon(hdc, vertices, sizeof(vertices) / sizeof(vertices[0]));  selectbrush(hdc, holdbrush); deleteobject(hbrush);  selectpen(hdc, holdpen); deleteobject(hpen); the result looks this:

Comments
Post a Comment