Click here to Skip to main content
Licence CPOL
First Posted 31 Mar 2008
Views 18,577
Downloads 131
Bookmarked 31 times

Burn the Edges of Your Windows to Give Them Character

By | 31 Mar 2008 | Article
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:

or even (gasp), this:

to... (drum roll please) this:

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:

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

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)

About the Author

Michael Dunn

Software Developer (Senior)
VMware
United States United States

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralNon-themed chrome PinmemberAlpha Nerd6:17 14 Jun '08  
GeneralAwww... i missed this yesterday! PinsitebuilderShog98:24 2 Apr '08  
GeneralApril Fools Pinmember.dan.g.13:07 1 Apr '08  
GeneralRe: April Fools PinmvpMichael Dunn15:01 2 Apr '08  
GeneralVery cool... PinmemberMike Doyon8:01 1 Apr '08  
GeneralRe: Very cool... PinmemberDamir Valiulin19:04 3 Apr '08  

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

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 1 Apr 2008
Article Copyright 2008 by Michael Dunn
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid