After using some annoying trial software that overlayed some text onto the desktop, I thought it would be interesting to make a fake desktop that would float below all windows (and the taskbar) but remain in front of the wallpaper. I wanted this to run with no input from the user, and work alongside anything that changed the desktop background. After a bit of mucking around with some Windows API goodness, I ended up with this:
[DllImport("user32", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
protected static extern IntPtr GetWindow(IntPtr hwnd, int wFlag);
public enum GWL
{
ExStyle = -20
}
public enum WS_EX
{
Transparent = 0x20,
Layered = 0x80000
}
public enum LWA
{
ColorKey = 0x1,
Alpha = 0x2
}
[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
public static extern int GetWIndowLong(IntPtr hWnd, GWL nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
public static extern int SetWindowLong(IntPtr hWnd, GWL nIndex, int dwNewLong);
[DllImport("user32.dll", EntryPoint = "SetLayeredWindowAttributes")]
public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, int crKey, byte alpha, LWA dwFlags);
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
int wl = GetWIndowLong(this.Handle, GWL.ExStyle);
wl = wl | 0x80000 | 0x20;
SetWindowLong(this.Handle, GWL.ExStyle, wl);
}
This ended up working much better than I expected it to, and has made the cut into my startup folder.