Mildly Hurtful Sarcasm

Meaningless ranting, just like everybody else.

Friday, February 23, 2007

Quest for a nicer desktop IV - Fuzzy shadows

So my neighbor Vincent shelled out $200 for a video card so Aero would run on his Vista, and he still has nothing good to say about it. That's one big L on his forehead. I am going to make something as nice, for free. I almost have my shadows going but made the mistake of fading out black into white. What I really need is to let the black fade out. I need to implement per pixel transparency.

Per pixel transparency turned out to be easy. I don't call SetLayeredWindowAttributes() to specify opacity. Also, instead of handing WM_PAINT messages, I call UpdateLayeredWindow() to draw the shadow window once. Opacity is specified by the colors themselves - center color 50% opacity, edge color 0%.


INT num = 1;
CClientDC dcDst(wnd);
CDC dcMem;
dcMem.CreateCompatibleDC(&dcDst);
CBitmap bm;
bm.CreateCompatibleBitmap(&dcDst, nWidth, nHeight);
dcMem.SelectObject(&bm);
Graphics graphics(dcMem.GetSafeHdc());
Color clrSurround = Color(0x0, 0x0, 0x0, 0x0);
PathGradientBrush brShadow(&path);
brShadow.SetSurroundColors(&clrSurround, &num);
brShadow.SetCenterColor(Color(0x80, 0x0, 0x0, 0x0));
REAL xScale = (nWidth - nEdgeWidth * 2) / nWidth;
REAL yScale = (nHeight - nEdgeWidth * 2) / nHeight;
brShadow.SetFocusScales(xScale, yScale);
graphics.FillPath(&brShadow, &path);
UpdateLayeredWindow(
GetSafeHwnd(), dcDst.GetSafeHdc(),
0, 0, dcMem.GetSafeHdc(),
0, RGB(0, 0, 0), blendfunction,
ULW_ALPHA);
bm.DeleteObject();



There, a translucent window with a fuzzy shadow. Who says XP can't be cool looking.

Labels:

0 Comments:

Post a Comment

<< Home