Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WTL

Burn the Edges of Your Windows to Give Them Character

4.92/5 (13 votes)
31 Mar 2008CPOL2 min read 1   390  
No, that's not a typo

Contents

Introduction

Are you tired of shiny, spotless windows? Tired of all that futuristic glass? Would you rather your windows have that classic, aged, slightly-burned-around-the-edges look of old historic documents? You know, the kind that just might have a map to buried treasure written on the back? Well, the answer is here! Through the wonders of modern technology, you can go from this:

Image 1

or even (gasp), this:

Image 2

to... (drum roll please) this:

Image 3

Nicolas Cage will be plotting to steal your windows in no time.

Now you've seen what can be done by burning the edges of a plain old rectangular window. Even more amazing results can be had by starting with an oddly-shaped window region. Take, for example, this totally boring window:

Image 4

Yawn. But after just a few applications of the patented* window-burning coding-technologies, you'll arrive at this wondrous image:

Image 5

WMP 9 would be envious if it weren't end-of-lifed.

*not actually patented

Tell Me More. C'mon, Man. Spill It. How's It Done?

Every few years, a long-dormant technique is rediscovered and put to use by Microsoft Scientists. In Windows 95, it was owner-drawn menus. In Windows 98, it was FlashWindow(). In Windows XP, it was window regions. These advances even outpace our need to learn new SI prefixes as our hard drives get bigger (hot tip that'll impress the ladies: after tera- comes peta-).

Now, in the year two thousand o' eight, I have discovered...

Rotating a Region

The ExtCreateRegion() API can summon a region using nary a RGNDATA blob. Where the magic comes in is the XFORM parameter. Dust your code with the appropriately-cultivated XFORM spell component, and ExtCreateRegion() will also rotate the region.

For example, starting with an original region rgn, we can create a copy that is rotated 30 degrees with this incantation:

int degrees = 30;
float radians = degrees * 2.0f * 3.14159f / 360.0f;
XFORM xform = { cosf(radians), sinf(radians),
                -sinf(radians), cos(radians) };
RGNDATA* pData;
UINT cby;
CRgnHandle rgn = /* original region */;
CRgn newRgn;
 
  // Get the RGNDATA for the original region.
  cby = rgn.GetRegionData ( NULL, 0 );
  pData = (RGNDATA*) new BYTE[cby];
  rgn.GetRegionData ( pData, cby );
 
  // CreateFromData() calls ExtCreateRegion().
  newRgn.CreateFromData ( &xform, cby, pData );
  delete[] (BYTE*) pData;

The members of XFORM are outlined in the Tome of the Network of the Microsoft Developer. When using XFORM to perform a rotation, as we are, the first four members are set as follows:

eM11: cosine of the rotation angle
eM12: sine of the rotation angle
eM21: negative of the sine of the rotation angle
eM22: cosine of the rotation angle

To achieve burnination, simply apply a rotation to your window region repeatedly, as often as desired. Let the round-off errors do the rest!

Conclusion

Happy 92nd day of the year! (or 91st in non-leap years!)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)