A Journey 2 Eternity

Painting a Gradient back ground

Posted on: June 8, 2009

Here’s a sample which draws background of a dialog with gradient colors.

BOOL CMyDlg::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
GetClientRect(&rect);

TRIVERTEX vert[4] = {
{ rect.left, rect.top, 0xff00, 0xff00, 0xff00, 0 },
{ rect.right, rect.top, 0, 0xff00, 0xff00, 0 },
{ rect.right, rect.bottom, 0xff00, 0, 0xff00, 0 },
{ rect.left, rect.bottom, 0xff00, 0xff00, 0, 0 }
};

GRADIENT_TRIANGLE grad[2] = {
{ 0, 1, 2 },
{ 0, 2, 3 }
};

::GradientFill( pDC->m_hDC, vert, 4, grad, 2, GRADIENT_FILL_TRIANGLE );

return TRUE;
}

void CMyDlg::OnSize(UINT nType, int cx, int cy)
{
// To ensure the background of the whole dialog is re-drawn
Invalidate();
CDialog::OnSize(nType, cx, cy);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Pages

Categories

June 2009
M T W T F S S
« May   Nov »
1234567
891011121314
15161718192021
22232425262728
2930  

Blog Stats

  • 27,491 hits
%d bloggers like this: