views:

293

answers:

2

I'd like to play animations on the Windows desktop without relying on 3rd-party products such as StarDock DeskScapes or Windows DreamScene. What APIs should I look into?

+1  A: 

I've never done this, but here's the approach I'd take.

  1. Inject a dll into explorer via SetWindowsHookEx.
  2. Grab a handle by using GetDesktopWindow.
  3. Subclass the Desktop using GetWindowLongPtr & SetWindowLongPtr.
  4. Do all your fancy rendering in the new WndProc you've hooked up.

Be aware that breaking the Desktop window will probably lock up your machine, as all its decedent windows (read: every window for that User) will likely be adversely affected.

Also, given the um rich compatibility history of Windows, be on the lookout for dummies meant to absorb abuse. In particular, I wouldn't be at all surprised if GetDesktopWindow does not in fact return the Desktop window you're looking for. You might have to do some digging with Spy++ or the like, basically.

Kevin Montrose
I did what you suggested a few years ago in Windows XP and it failed miserably. The problem was that if you dragged a Window back and forth (fast) on top of the desktop it would repaint underneath the Window using a solid gray background, then a second later it would redraw using the desktop wallpaper. You would end up with very visible "tearing". StarDock DeskScapes claims to run on Windows XP so I wonder how they did it. Is there a better program than Spy++ for this kind of job?
Gili
Tearing is an artifact of your WndProc implementation. Consider double-buffering, and techniques for speeding up the actual BitBlt() to the screen. Vista(+) with composition enabled may go a long way to killing tearing in this scenario as well.
Kevin Montrose
I think this case is different. When you drag a window over the desktop it first repaints it using the solid color, then it paints the wallpaper on top of it. I tried suppressing the 1st paint (solid color) but it seems to be hard-coded into the desktop process, hence the tearing.
Gili
I'm fairly certain the Desktop window is not rendered using any special methods. Note that the background color is controllable (for any window class) using GCLP_HBRBACKGROUND and SetClassLongPtr; consider using the hollow brush to further mitigate tearing.
Kevin Montrose
+1  A: 

Hi Gili, you can read this thread... http://www.gamedev.net/community/forums/topic.asp?topic_id=113986

it is long, but in it, is a discussion of writing to the desktop...

hope this helps...

~Bolt

Boltimuss
Very interesting thread. Ironically the first time I tried to implement this was also around 2002. Small world :) I've revisited the problem on and off since then but I've never figured it out. Do you happen to have any sample source-code I could work with? The links in the discussion seem to be broken after all these years.
Gili
unfortunately, I did notice that the link was broken. I don't have the source code at all ... It was my hope that at least some of the conversation my stimulate your thinking. You could possibly post to the thread and revive it.
Boltimuss
No worried, I found it at http://www.gameprog.it/pub/lang/ccpp/tuts/AndreasJonsson/ -- It has some quirks but is goes further than anything I've ever done. Thanks a lot Bolt, you've solved a problem that's been bothering me for a very long time now!
Gili
Glad to help out :)
Boltimuss