Click here to Skip to main content
15,881,173 members
Articles / Desktop Programming / WTL
Article

Burn the Edges of Your Windows to Give Them Character

Rate me:
Please Sign up or sign in to vote.
4.92/5 (13 votes)
31 Mar 2008CPOL2 min read 38K   388   35   6
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)


Written By
Software Developer (Senior) VMware
United States United States
Michael lives in sunny Mountain View, California. He started programming with an Apple //e in 4th grade, graduated from UCLA with a math degree in 1994, and immediately landed a job as a QA engineer at Symantec, working on the Norton AntiVirus team. He pretty much taught himself Windows and MFC programming, and in 1999 he designed and coded a new interface for Norton AntiVirus 2000.
Mike has been a a developer at Napster and at his own lil' startup, Zabersoft, a development company he co-founded with offices in Los Angeles and Odense, Denmark. Mike is now a senior engineer at VMware.

He also enjoys his hobbies of playing pinball, bike riding, photography, and Domion on Friday nights (current favorite combo: Village + double Pirate Ship). He would get his own snooker table too if they weren't so darn big! He is also sad that he's forgotten the languages he's studied: French, Mandarin Chinese, and Japanese.

Mike was a VC MVP from 2005 to 2009.

Comments and Discussions

 
GeneralNon-themed chrome Pin
The Cake of Deceit14-Jun-08 6:17
The Cake of Deceit14-Jun-08 6:17 
GeneralAwww... i missed this yesterday! Pin
Shog92-Apr-08 8:24
sitebuilderShog92-Apr-08 8:24 
GeneralApril Fools Pin
.dan.g.1-Apr-08 13:07
professional.dan.g.1-Apr-08 13:07 
GeneralRe: April Fools Pin
Michael Dunn2-Apr-08 15:01
sitebuilderMichael Dunn2-Apr-08 15:01 
GeneralVery cool... Pin
Mike Doyon1-Apr-08 8:01
Mike Doyon1-Apr-08 8:01 
GeneralRe: Very cool... Pin
Damir Valiulin3-Apr-08 19:04
Damir Valiulin3-Apr-08 19:04 
Mike Doyon wrote:
I'm not sure where or why I would use such functionality, but it is very cool!


What he said! Smile | :)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.