- Z Gauge Model Rail
- Workshop Projects
- Lathe Splash Guard
Mill drill light
Lathe Hand Crank
Lathe way protector
- Spray Painting Booth
- Lathe Leadscrew Hand Wheel
- Lathe Bench
- Lathe DRO and Speed Controller
- Lathe Spindle Handle
- Lathe Spindle Arbor
- Large Lathe Steady
- Injection Molding Machine
- Mill DRO
- Electronics Projects
- Garden Watering
- Contact Me
The plan is to make this into a screensaver some time. Some of the screensaver code is in place to start it, but it doesn't stop properly. If you do not exit the program properly, you will lose your windows - you'll need to log off, or restart to recover.
You can get the application here. Just run it, and a small application will appear in the top left corner of the screen.
From the Window menu, select "Collapse All" and the windows will collapse. Once your happy with the destruction, exit the "Window Demolition" application, and your windows will return.
On my desktop, the first window to be demolished is the task bar. I use auto-hide, so the effect of a 1 pixel high window collapsing isn't very effective. It does get better though.
How does it work?
There are a couple of tricky bits here.
Firstly, finding the windows. Using Windows API function EnumWindows() we are able to find all top level windows. Then for each top level window we find their children using the MFC GetWindow() and GetNextWindow() methods (which map through to the Win API functions of the same name). We get all windows in the system so we can choose which ones to destroy, and which ones not to. We are interested in all visible top level windows (except ourselves), MDI applications and MDI children. Window order is also important so we can destroy them from front to back.
The next tricky bit was how to get the contents of each window to animate the demolition. This was a bit of a fudge. The first thing we do is create our own window on top of our target window. As a side effect, our new window will contain the graphics of the target window. Here we could have just used BitBlt() to do a bitmap copy from the screen. When our window is complete, we use the Win API fuction ShowWindow( SW_HIDE ) to hide the target window. That is the dangerous bit. If the Demolition application doesn't exit properly, these windows remain active but hidden - you'll have to log off, or restart to get Windows to gracefully close the applications. The applications do not appear in the Task Manager "Applications" tab. They do appear in the "Processes" tab, but this will terminate the application without a chance of saving changes.
To animate the destruction, we define our window surface using a region. Initially, the region is just a rectangle. Then as strips disappear, the region gets bits taken off of it, allowing the windows behind to show through. We use CreateRectRgn() and CombineRgn() to build the region, then SetWindowRgn() to bind the applications display region.
The explosion effects and sound are triggered of the windows timer. This needs work. There are annoying audio pops, and the rumbling rubble sound doesn't play long enough; it's only effective on small windows.
The source is here.