Disappointments with DWM

| | Comments (1)

DWM is a great new Vista technology that allows you to create live thumbnails of application windows (among other things). If you use Vista, you've probably noticed DWM in action with the task bar:

DWM in action, with Windows Media Player

These thumbnails are a live view of what's happening in the window, and are quite a neat way to visually see what's happening "behind the scenes" so to speak. However, they have some very unfortunate drawbacks which are really annoying.

For starters -- you can only display a thumbnail for a top-level window. This totally destroys them for the use I had in mind, as for other great places to use this. The task bar is nothing more than a fancy name for a tab panel, and so it stands to reason that most places you'd use a tab panel would be a great place to use DWM thumbnails. For instance, in the REALbasic IDE, I was going to have a thumbnail appear when you hover the mouse over a tab in the tabs bar. This way you get a more visual understanding of what's being edited in a particular tab. But since it requires a top-level window to work... that's just not going to happen.

Now... I do not understand why this limitation is required. It seems like a fairly contrived limitation. However, I also have only a cursory understanding of how the thumbnails work internally -- so it could be that there's a valid reason for the limitation. It's just unfortunate, because it totally killed a really fun feature for the IDE.

And, just in case you want to use thumbnails in your own applications -- here's another tidbit of information. DWM will only work with a *visible* window. If the window is minimized, then DWM will cache the previous contents of the window and display that. It's interesting to note though, that if DWM doesn't have the opportunity to cache the window's image, you get a stock "blank" window thumbnail. This is the same thumbnail you will get if the window the window is outright hidden. However, if the window is simply off-screen, then it will display just fine (but it will also show up in the Alt+Tab list and accept focus/input, so it's not very hidden!).

Regardless, I've got some rudimentary DWM support in REALbasic code. It's nothing too fancy, but it gets the job done.


Structure DwmThumbnailProperties
flags as Integer
destination as Rect
source as Rect
opacity as UInt8
visible as Integer
sourceClientAreaOnly as Integer
End Structure

Structure Rect
left as Integer
top as Integer
right as Integer
bottom as Integer
End Structure

Soft Declare Function DwmRegisterThumbnail Lib "DwmApi" ( dest as Integer, source as Integer, ByRef id as Integer ) as Integer
Soft Declare Function DwmUpdateThumbnailProperties Lib "DwmApi" ( id as Integer, ByRef properties as DwmThumbnailProperties ) as Integer
Soft Declare Sub DwmUnregisterThumbnail Lib "DwmApi" ( id as Integer )

dim id as Integer

if DwmRegisterThumbnail( self.Handle, sourceWindow.Handle, id ) = 0 then
dim properties as DwmThumbnailProperties

properties.flags = &h8 + &h1 + &h4 + &h10
properties.destination.top = 22
properties.destination.right = self.Width
properties.destination.bottom = 22 + self.Height
properties.opacity = 255
properties.visible = 1
properties.sourceClientAreaOnly = 0
call DwmUpdateThumbnailProperties( id, properties )
end if


Of course, this code doesn't clean up the thumbnail ID (once you unregister the thumbnail, the live view is destroyed), nor does it contain much of any error checking, comments, etc. But it gives you a reasonable idea of how things work -- the basic idea is that you register a source window handle, and a target window destination. The source window's contents will be automatically drawn into the destination window once you call DwmUpdateThumbnailProperties (which tells the window manager where and how you want the thumbnail drawn).

Enjoy!

1 Comments

Hi Aaron,

Very cool example.

I was trying to figure out how I could use the same DwmApi to control how a application works when in Flip 3D.

I found a site that showed an example in c#
http://www.codeguru.com/csharp/csharp/cs_misc/userinterface/print.php/c14775

I'm not the best with declares in REALbasic. This is what I've got but its not working:

download link for REALbasic file:
http://www.sendspace.com/file/4gkp9g

DWMWA_FLIP3D_POLICY = 8; // The attribute

// Flip 3D policies
enum Flip3DPolicy

Default,
ExcludeBelow,
ExcludeAbove

//code
Dim m As MemoryBlock
Dim sz As Integer
Dim r As Integer
Soft Declare Function DwmSetWindowAttribute Lib "DwmApi" ( hwnd as Integer, attr As Integer, ByRef attrValue as Integer, attrSize as Integer ) As Integer
m = NewMemoryBlock(4)
m.Int32Value(0) = Int32(Flip3DPolicy.ExcludeAbove)
sz = m.Size
r = DwmSetWindowAttribute(Window1.Handle, DWMWA_FLIP3D_POLICY, m.Int32Value(0), sz)

Thanks for any suggestions.

Best Regards,
Bryan

Leave a comment

Disclaimer

I'm currently an employee of REAL Software. My blog is mine. The opinions represented in this blog are mine as well and may not represent my employer's opinions. All original material is copyrighted and property of the author.

REALbasic® is a registered trademark of REAL Software, Inc. REAL SQL Server™ and Lingua™ are pending trademarks of REAL Software, Inc. All rights reserved.