下面看两个示例,演示了如何使用GradientFill()
其实很简单,参数一为每个顶点的位置、色彩定义,参数二为要使用的顶点数目,第三个参数为这些顶点如何绘制,第四个参数为绘制的次数,第五个参数为绘制模式
如:vert,4,&gTRi,3,GRADIENT_FILL_TRIANGLE
(1)绘制模式为:三角形GRADIENT_FILL_TRIANGLE
(2)绘制的顶点数为4,就是说有4个顶点,这4个顶点的位置、色彩定义见第一个示例
(3)然后就是绘制的次数为3次,分别为gTRi[0]、gTRi[1]、gTRi[2],
而每一次给出三个顶点,绘制成三角形。三个顶点的顺序似乎不重要。
第一个:
CDCHandle dc(hDC);
TRIVERTEX vert [4] ;
GRADIENT_TRIANGLE gTRi[4];
vert [0] .x = 0;
vert [0] .y = 0;
vert [0] .Red = 0x0000;
vert [0] .Green = 0x0000;
vert [0] .Blue = 0x0000;
vert [0] .Alpha = 0x0000;
vert [1] .x = 350;
vert [1] .y = 0;
vert [1] .Red = 0x0000;
vert [1] .Green = 0x0000;
vert [1] .Blue = 0xff00;
vert [1] .Alpha = 0x0000;
vert [2] .x = 350;
vert [2] .y = 350;
vert [2] .Red = 0x0000;
vert [2] .Green = 0x0000;
vert [2] .Blue = 0xff00;
vert [2] .Alpha = 0x0000;
vert [3] .x = 0;
vert [3] .y = 350;
vert [3] .Red = 0xff00;
vert [3] .Green = 0xff00;
vert [3] .Blue = 0xff00;
vert [3] .Alpha = 0x0000;
gTRi[0].Vertex1 = 1;
gTRi[0].Vertex2 = 3;
gTRi[0].Vertex3 = 0;
gTRi[1].Vertex1 = 0;
gTRi[1].Vertex2 = 2;
gTRi[1].Vertex3 = 3;
gTRi[2].Vertex1 = 1;
gTRi[2].Vertex2 = 3;
gTRi[2].Vertex3 = 2;
gTRi[3].Vertex1 = 0;
gTRi[3].Vertex2 = 2;
gTRi[3].Vertex3 = 1;
dc.GradientFill(vert,4,&gTRi,4,GRADIENT_FILL_TRIANGLE);
第二个:
if ( IsVertical() )
{
TRIVERTEX tv[] = { { rect.left, rect.top, 0xff00 },
{ rect.left + m_cxyHeader, rect.bottom, 0, 0xff00 } };
GRADIENT_RECT gr = { 0, 1 };
dc.GradientFill ( tv, 2, &gr, 1, GRADIENT_FILL_RECT_V );
}
else
{
TRIVERTEX tv[] = { { rect.left, rect.top, 0xff00 },
{ rect.right, rect.top + m_cxyHeader, 0, 0xff00 } };
GRADIENT_RECT gr = { 0, 1 };
dc.GradientFill ( tv, 2, &gr, 1, GRADIENT_FILL_RECT_H );
rect.bottom = rect.top + m_cxyHeader;
// draw title only for horizontal pane container
dc.SaveDC();
dc.SetTextColor ( RGB(255,255,255) );
dc.SetBkMode ( TRANSPARENT );
dc.SelectFont ( GetTitleFont() );
rect.left += m_cxyTextOffset;
rect.right -= m_cxyTextOffset;
if ( m_tb.m_hWnd != NULL )
rect.right -= m_cxToolBar;
dc.DrawText ( m_szTitle, -1, &rect,
DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS );
dc.RestoreDC(-1);
}