Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Drawing a Shaded Rectangle

To draw a shaded rectangle, define a TRIVERTEX array with two elements and a single GRADIENT_RECT structure. The following code example shows how to draw a shaded rectangle using the GradientFill function with the GRADIENT_FILL_RECT mode defined.



// Create an array of TRIVERTEX structures that describe 
// positional and color values for each vertex. For a rectangle, 
// only two vertices need to be defined: upper-left and lower-right. 
TRIVERTEX vertex[2] ;
vertex[0].x     = 0;
vertex[0].y     = 0;
vertex[0].Red   = 0x0000;
vertex[0].Green = 0x8000;
vertex[0].Blue  = 0x8000;
vertex[0].Alpha = 0x0000;

vertex[1].x     = 300;
vertex[1].y     = 80; 
vertex[1].Red   = 0x0000;
vertex[1].Green = 0xd000;
vertex[1].Blue  = 0xd000;
vertex[1].Alpha = 0x0000;

// Create a GRADIENT_RECT structure that 
// references the TRIVERTEX vertices. 
GRADIENT_RECT gRect;
gRect.UpperLeft  = 0;
gRect.LowerRight = 1;

// Draw a shaded rectangle. 
GradientFill(hdc, vertex, 2, &gRect, 1, GRADIENT_FILL_RECT_H);


The following image shows the drawing output of the preceding code example.

Illustration showing a rectangle with a gradient fill from dark on the left side to light on the right side

Related topics

Bitmaps Overview
Bitmap Functions
Drawing a Shaded Triangle
EMRGRADIENTFILL
GRADIENT_RECT
GradientFill
TRIVERTEX

 

 

Community Additions

Show:
© 2015 Microsoft