§ ¶Abusing a composited desktop
Here's a stupid Windows trick to abuse the Desktop Window Manager.
Basically, the idea is to try to get a translucent window that doesn't have a hit testing area, i.e. it's invisible to the mouse. This creates an overlay on screen that displays something but doesn't occupy space on screen. Traditionally, support in Windows hasn't been very good for this, because the only way to get translucency was to use a layered window -- which interacted very badly with Direct3D rendering in XP -- and because WS_EX_TRANSPARENT worked poorly or not at all across threads. In Windows 7 with the DWM, however:

...you get a translucent no-hit window that actually works. No more having to fish the VS2005's Find and Replace window out from under the video player.
There isn't an easy way to do this without code, but if you're curious, here's a tiny command line program to toggle this on a running instance Media Player Classic - Home Cinema: transplayer.zip. I haven't tried it with the original MPC but it might work if the window class is the same. Again, you need at least Windows Vista for this, as it's highly likely not to work at all on XP. Also, you may have to turn off VSync tracking on the renderer as I think that reacted badly once the window became layered.
I haven't done any real testing on this, and if you rely on it in production software you'll probably get lampooned on The Old New Thing about five years from now, but it's neat when it works.
Comments
Comments posted:
Nice idea! I solved this problem by moving the video to my second monitor.
tobi - 24 04 11 - 21:51
Isn't the classic (and basic) theme still rendered without the DWM? If so, don't you have the sme rendering architecture there as always, except maybe for Vista-related changes? But I guess the DWM is not involved at all unless you're using Aero.
Joey - 24 04 11 - 21:59
No second monitor on a laptop.
It might be incorrect to say that the DWM is involved here, since at least composition is not required -- this works even if Aero is disabled. The rendering architecture is substantially different than XP due to the WDDM driver model, though. A lot of the badness associated with Direct3D not behaving with layered windows and second monitors on XP was associated with the mismatch between the 2D and 3D rendering paths being different -- specifically, cases where GDI would try to do a software rendering operation and the driver might or might not try to hack around it to avoid the stall. With WDDM, however, everything is going through the 3D driver and so things run a lot more smoothly.
The one downer about this is that the API doesn't give you control over the blending mode, as I would have preferred a color multiply instead of a constant lerp. The only other blending mode that you can do this way that I know of is an add, by extending the blur into the client area and then putting an alpha channel on your Direct3D backbuffer of constant 0. I wonder if there's a way to do this through the undocumented MIL APIs.
Phaeron - 24 04 11 - 22:19
There has been a program around for ages called Glass2k. I had limited success with it on XP, but works rather well on Windows 7.
It basically allows you to set a windows transparency on a per-application basis - and remembers it so when you close and re-open the app again, the transparency is automatically re-applied. It also has keyboard short-cuts to set transparency on the current focused window. Oh, and its freeware.
I didn't write and I don't have any direct association with the author - it's just one of the useful utilities that I now use constantly.
MarC - 25 04 11 - 09:59
That's awesome! (Tried on the old normal MPC version I use 6.4.9 - and works just fine on Win7).
Nic - 02 05 11 - 08:03
http://support.microsoft.com/kb/937106/e.. "Performance is poor in a WPF-based application in which you have enabled layered windows in Windows XP or in Windows Server 2003" states that: "In DirectX 9.0c, the IDirect3DSurface9::GetDC method does not support transparency effects that use an alpha channel. Therefore, graphics that a WPF-based application renders are not hardware-accelerated. Instead, the application renders graphics at the software level. In this situation, the application performs poorly and uses a high proportion of CPU time."
I'm not a graphics programmer, but doesnt this sound related? Is it simply the fact that XP transparency is never hardware accelerated? Although, with Winamp 2.9x and MilkDrop or AVS visualizations, you can "Enable overlay" and it does show the visualization at high framerate all over the screen, but that's not really the same as transparency..
Syclone0044 (link) - 22 06 11 - 16:40
Transparency can and often is accelerated on XP -- the video driver can accelerate AlphaBlend(). The problem is that Direct3D9 doesn't really integrate with GDI rendering, so when you mix layered windows with D3D rendering, the D3D present bypasses the layered compositing and the two fight over the display.
The hotfix you linked to is interesting. As far as I've known, GetDC() was always a bad idea on any DirectX surface as it gave you GDI software rendering. This hotfix applies to the user-space D3D9 DLL, though, and I wonder if they changed that
The overlay transparency you are referring to is different. It's much the same idea, but it's a separate hardware plane instead of software compositing. They also can't alpha blend, as the transparency is only by colorkeying (cutout). Hardware overlays are powerful, but have such a tremendous number of bugs in both Windows and the video drivers that I've stopped using them by default.
Phaeron - 22 06 11 - 17:49
Comment form
Please keep comments on-topic for this entry. If you have unrelated comments about VirtualDub, the forum is a better place to post them.