Gold mine of Visual C++ tricks!
Archive for June 5, 2008
How to fill gradients in your dialog like InstallShield?
11343 days
![]()
Look at the dialog. What’s the first thing that come to your mind when you see this?
Yes! I can read it – the InstallShield. Its so common to our eyes, since almost all application setups comes via InstallShield. People identify installshield with its nice blue gradient in its background window. So how can we generate such nice gradient background like installShield does?
![]()
You can use the function – GradientFill(). See the code snippet to generate the InstallShield effect. Its self explanatory.
// Get the Device context.
CPaintDC dc( this );
// Get the client co-ordinates.
CRect rect;
GetClientRect( &rect );
// Two gradient points.
TRIVERTEX vert[2] = { 0 };
// Set the first vertex point at 0,0 and with blue color.
// Since the array is initialize with 0, all other
// members in struct are 0.
vert[ 0 ] .Blue = 0xff00;
// Initialize second vertex at endcorner of
// window with black color.
vert[ 1 ] .x = rect.Width();
vert[ 1 ] .y = rect.Height();
// Gradient rectangle.
GRADIENT_RECT GradientRect = { 0 };
GradientRect.UpperLeft = 0;
GradientRect.LowerRight = 1;
// Now fill the gradient.
GradientFill( dc.GetSafeHdc(),
vert, // Gradient vertices.
2, // No. of vertices.
&GradientRect, // Gradient array.
1, // No. of items in Gradient Array.
GRADIENT_FILL_RECT_V ); // Vertical Fill.
![]()
Don’t forget to add Msimg32.lib to your project settings.
![]()
Targeted Audience – Intermediate.
