What
Old Fashioned Fun runs in the tray and gives the windows on your desktop gravity. If you pull a window up it will fall back down. Windows will also stack on top of other windows. You can throw windows by dragging them quickly and letting go. Windows will bounce off the taskbar, and be repelled by the sides of the screen.
Why
A demo of C# interacting with the Windows API. A simple physics demo. And because it's fun.
How
Periodically a a list of windows handles is queried from the system. The top of each window is treated like a shelf where other windows can sit. The dimensions of the desktop are also queried so that forces can be applied to windows that are off the screen. Here is some sample code below:
// enumerate open windows by registering a call back to OnEnumWindow
public Win32.EnumWindowsProc EnumWindow;
EnumWindow = new Win32.EnumWindowsProc(OnEnumWindow);
Win32.EnumWindows(EnumWindow, IntPtr.Zero);
// get the position of the top of the taskbar
Abd = new Win32.APPBARDATA();
Win32.SHAppBarMessage(Win32.ABM_GETTASKBARPOS, ref Abd);
TaskbarTop = Abd.rc.Top;
// get the desktop dimensions
Desktop = new Win32.RECT();
Win32.GetWindowRect(Win32.GetDesktopWindow(), ref Desktop);