Geeks With Blogs
Prabhu Kumar a tech twaddler..
I added a little gradient fill to the main screen. And it is quite easy really. By the way, here's what my main screen looks like now, cool eh (:




Lets look at GradientFill first. The function is prototyped as:

BOOL GradientFill(HDC hdc, PTRIVERTEX pVertex, ULONG numVertex, PVOID pMesh, ULONG numMesh, ULONG mode);

The first parameter is the handle to the device context. The second parameter, pVertex, is a pointer to an array of TRIVERTEX structures. The third parameter contains the number of elements in the array pointed to by pVertex.

TRIVERTEX structure:
struct _TRIVERTEX
{
    LONG x;
    LONG y;
    COLOR16 Red;
    COLOR16 Green;
    COLOR16 Blue;
    COLOR16 Alpha;
} TRIVERTEX;

The structure defines a point x,y in the device context and its color. Alpha define the transparency of the point x,y. The points in the array should define the upper left and the lower right corners of the rectangle being filled. The fourth parameter pMesh points to a GRADIENT_RECT structure.

struct _GRADIENT_RECT
{
    ULONG topLeft;
    ULONG bottomRight;
} GRADIENT_RECT;

The GRADIENT_RECT structure specifies which entry in the array containing TRIVERTEX array is the upper left point and which is the bottom right point. The last parameter, mode, specifies whether the gradient should be filled horizontally, GRADIENT_FILL_RECT_H, or vertically GRADIENT_FILL_RECT_V.

Now to the static text control. I tried to make the control transparent but found out that it is not very straight forward. Tried to use SetBkMode(hdc, TRANSPARENT) and reurning NULL_BRUSH in response to WM_CTLCOLORSTATIC, didn't work for me. So I removed the static control and used ExtTextOut to draw the text directly on the screen.

Here is the final piece of code. All the code goes in under WM_PAINT function. And g_hImageStatic is a global which contains window handle to the static control containing the image. I store it while creating the static control in AlignComponents(), check my previous post.

TRIVERTEX vert[2];
GRADIENT_RECT gradRect;
RECT rect;
TCHAR szStrLine1[] = TEXT("TechTwaddle");
TCHAR szStrLine2[] = TEXT("Copyright (c) 2009");

hdc = BeginPaint(hWnd, &ps);

GetClientRect(hWnd, &rect);

vert[0].x = rect.left;
vert[0].y = rect.top;
vert[0].Red = 0x0000;
vert[0].Green = 0x2000;
vert[0].Blue = 0xA000;
vert[0].Alpha = 0x0000;

vert[1].x = rect.right;
vert[1].y = rect.bottom;
vert[1].Red = 0x0000;
vert[1].Green = 0x8000;
vert[1].Blue = 0xFF00;
vert[1].Alpha = 0x0000;

gradRect.UpperLeft = 0;
gradRect.LowerRight = 1;

GradientFill(hdc, vert, 2, &gradRect, 1, GRADIENT_FILL_RECT_H);

if(g_hImageStatic)
{
    GetWindowRect(g_hImageStatic, &rect);

    SetTextColor(hdc, RGB(120, 160, 130));

    SetBkMode(hdc, TRANSPARENT);
    ExtTextOut(hdc, rect.left - 23, rect.bottom - 24, 0, NULL,
        szStrLine1, _tcslen(szStrLine1), NULL);
   
    ExtTextOut(hdc, rect.left - 37, rect.bottom - 11, 0, NULL,
        szStrLine2, _tcslen(szStrLine2), NULL);
}

EndPaint(hWnd, &ps);
Posted on Wednesday, April 29, 2009 1:15 AM | Back to top


Comments on this post: Applications: That thing called Gradience

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © TechTwaddle | Powered by: GeeksWithBlogs.net