Tweak DWM from your programs, Part 1
0 Comments Published July 21st, 2008 in Programming, Windows Vista
With Windows Vista, Microsoft introduced a whole new window manager which provides a better experience to the user and an independent graphics surface to us developers by taking advantage of graphics acceleration hardware (your graphics card or integrated GPU).
In a three-part blog post, I will show you how to use a wrapper around the Desktop Window Manager Application Programming Interface in order to control its state, change colorization, or change the rendering policy of windows from your Windows Forms and .NET 3 Presentation Foundation programs.
Getting Started
Windows Forms and Windows Presentation Foundation will be referred to in these posts as WF and WPF respectively.
The code you will need can be downloaded from here and is written in C# (as are the code samples in this post). That being said, you can use it in projects of any other .NET language — you can include the compiled libraries as references. Otherwise (if you code in C#), you also have the option to include the files in your project and not distribute a separate library. The solution is for use in Visual Studio 2005 but is also compatible with version 2008.
The whole framework is located under the
GlassLib namespace and is the source to three main types of projects:
DwmWrapper is a .NET wrapper around the DWM API, which can be compiled in the following flavors:
- No dependency on WF or WPF. It can be used to avoid DLL clutter when coding command-line applications to manipulate the DWM.
- Solely WF or WPF
- Both for mixed-framework projects.
GlassLib is a WF-powered layer above
DwmWrapper and provides a set of classes, including the
GlassBar control for use in your forms
The Test Projects you can use to try the various features that the two other projects have. They will be used here ad hoc.
In this first part, we will explore the architecture of the wrapper, its core functionality and application in Windows Forms programs.
Microsoft provides an API for DWM in the equivocal DwmApi library. Encapsulating it for easier use in .NET programs is the wrapper’s main purpose.
Since all necessary classes are located under the
GlassLib namespace, in order to avoid writing it every time, I would suggest that you insert it in your C# or VB code file’s “imports” or, if you are working exclusively with VB, in your project’s “Imported Namespaces” list in order to avoid doing the first as well.
The most important class is
Dwm and can be used to control virtually any aspect of DWM as long as the public API allows it. The various features are available via the following properties of
Dwm:
Using the Wrapper
Note that DWM is only available on Windows Vista, so I would suggest that you select how to handle the wrapper’s behavior on earlier operating systems. Otherwise, exceptions will be raised which you will have to catch.
The first option is to limit the exceptions the wrapper will raise by setting
Dwm.ThrowExceptionTypes to one of the available
DwmExceptionTypes
Raising no exception will most likely suit your needs best so adjust this property before you make any other changes to DWM, preferably at program startup or in the form’s constructor.
Dwm.ThrowExceptionTypes = DwmExceptionTypes.None;
Now you can make any changes you want to your form’s state in the DWM, for example enable Glass–it is as easy as writing
Dwm.Glass[this] = new DwmMargins(100, 4, 8, 20);
where this is the instance of the form (you can replace this with any other form instance you would like) and the margins are defined as left-right-top-bottom. You can use
DwmMargins.EntireWindow instead to extend glass in the whole window client area, like Mobility Center does in Windows Vista.
Restoring the default borders is done by calling the
Restore method.
Dwm.Glass[this].Restore();
Receiving notifications on the global DWM state or on your forms’ is important in order to know how you should handle painting backgrounds or the non-client area. You can choose to get notified when the Aero Glass colorization is changed or DWM starts up or shuts down. In GlassLib this is straightforward: each form that you wish to be notification-aware, GlassLib will include in its list and you have to attach your handlers to the colorization, composition, non-client rendering or window-maximized changes.
Dwm.Events[this].AddHandlers(); // Notifying GlassLib…
// Add our handlers
Dwm.Events[this].CompositionChanged += new DwmEventHandler(OnCompositionChanged);
Dwm.Events[this].ColorizationChanged += new DwmEventHandler(OnColorizationChanged);
…
private void OnCompositionChanged(object sender, DwmEventArgs e)
{
// Update the UI on composition change (extend glass if DWM is enabled, otherwise restore)
if (Dwm.Glass[this].Enabled)
Dwm.Glass[this].Margins = new DwmMargins(100, 4, 8, 20);
else
Dwm.Glass[this].Restore();
}
private void OnColorizationChanged(object sender, DwmEventArgs e)
{
MessageBox.Show(e.Colorization.ToString());
}
Although the public DWM API does not make it easy for one to change the colorization programmatically, DwmWrapper exposes this functionality through the
Dwm.Colorization property. Controlling the Desktop Window Manager is also as easy as setting
Dwm.Composition.Enabled to the desired value, either true or false. Other useful “one-liners” include invoking Windows Flip and Flip 3D:
Dwm.Flip3D.EnterAltTab(); and
Dwm.Flip3D.Enter();, respectively.
You can tinker with the full GlassLib source code and the included test projects to see how all of the aforementioned features work in a real environment. In the next part I am going to cover the more advanced functionality of the wrapper, the Windows Forms test app and how it manages DWM thumbnails.
If you have any comments, questions, wishes or just an opinion, feel free to post it here.
You are free to use GlassLib in your freeware programs, but please at least acknowledge it in your release notes/about dialog/website. In case your program is commercial/shareware, I would appreciate it if you could contact me beforehand. Thanks.
Windows Vista Language Packs Released
0 Comments Published October 24th, 2007 in Microsoft, Windows VistaYesterday Microsoft released the whole series of language packs (34), including Arabic, Greek and Bulgarian. The latter will be useful to fellow Bulgarians running Windows Vista Ultimate or Enterprise–they are the only editions of Windows with support of language packs.
There were some critic reactions to Windows Vista Ultimate Extras as a service because the team could not provide Windows DreamScene and all of the language packs besides other extras on time, although this was paid for by Ultimate users. However, the team is again up and running and I congratulate them on the job well done.

Windows Sidebar Styler, v2.0.6
13 Comments Published August 16th, 2007 in Programming, Windows VistaI have recently worked on Windows Sidebar Styler and version 2.0.6 is now available.
Among the improvements is instant application of styles as well as the resizable Windows Sidebar feature. The latter is especially useful when Windows Sidebar is docked on the left. Added are more localizations and Alky for Applications is supported for use in Windows XP or Server 2003.
The new version can be downloaded here.
If you are interested in localizing Windows Sidebar Styler in your native language, or just want to suggest a feature for the next version, please do not hesitate to contact me.
Fine-Grained Password Policy Tool
1 Comment Published July 23rd, 2007 in Betas, Windows Longhorn, ProgrammingChristoffer Andersson–an MVP in Active Directory and a very good friend of mine–recently released the first beta of his Fine-Grained Password Policy Tool. If you are an IT planner or analyst or simply experimenting with the new features of Windows Server 2008 in terms of domain-wise security, you will like to deploy the application. It includes Management Console and PowerShell snap-ins which create and manage Fine Grain Password Policies with complex properties as provided by the latest Server OS.
Binaries: FGPP Beta 1_2228-20070706.0 32-bit, 64-bit
Documents: Original blog post, Quick Start Guide, Overview of Fine-Grained Password Policies
Notes: Contributors to the development of FGPP include Björn Österman and myself.
Microsoft is currently running a few campaigns for their partners, one of which is Windows Vista Partner Odyssey. It aims to bridge partners who have developed for the new platform or simply leveraged its power for their business. If you are one of those you can enter now — you stand a fair chance of being selected as a Windows Vista Adventurer and sent a bag full of survivor tools (in fact, it is rather nice). Microsoft will also award 5 exciting adventures to one of these partners each month.
I am glad that Microsoft selected Windows Sidebar Styler to highlight AeroXperience. You can read our case study on the Partner Profiles page by searching for AeroXperience.
New Release of Windows Sidebar Styler
19 Comments Published January 25th, 2007 in Betas, Programming, WinFX, Windows VistaAn updated version of Windows Sidebar Styler (v2.0.5) has been made available. Please check the previous post for download links as well as updated documentation.
Additions include support for Gadget resource localization, translations of the application UI, as well as fixed issues with VAIO. If you are interested in helping localize Windows Sidebar Styler in your native language, please do not hesitate to contact me.
Windows Sidebar Styler
86 Comments Published January 17th, 2007 in Betas, Programming, WinFX, Windows Vista| A new version of Windows Sidebar Styler available. Click here for more information. |
Windows Sidebar Styler is an application which takes advantage of various technologies introduced in Windows Vista in order to provide extensions to the existing functionality of Windows Sidebar.
Custom styles allow users to customize the appearance of Windows Sidebar so that it fits the style of other UI elements, such as the Aero Glass colorization or an actual third party theme. Designers could save their visual styles for Sidebar so that other Windows users could apply them. Designers would not necessarily create these files on Windows Vista - Sidebar Styler is backward-compatible with legacy operating systems as well.
Gadgets - these mini applications which are managed by Windows Sidebar can now take full advantage of Windows Presentation Foundation - a powerful managed code-oriented framework for presenting rich visual compositions such as vector graphics, 3D drawing, animations and more. In addition to that, it could be used in conjunction with the Communication Foundation in order for the Gadgets to connect to services and provide frequently updated information.
Using compiled class libraries also helps protect the intellectual property of developers because the actual source code is not distributed.
The tight integration with the core of Windows Sidebar allows the application to extend the current set of features of Windows Sidebar by allowing users to customize its appearance and by providing a more powerful framework for building Gadgets and visualizing information.
Designed for Microsoft Windows Vista. Written in C#, C++ and Managed C++. Compatible with Project “VAIO.”
Binaries: 32-bit, 64-bit v2.0.5/Jan 26th, 2007
Documents: Release Notes, A Guide to Writing WPF Gadgets, WPF Gadget Development Files
Notes: Sample gadgets and styles are included in the installation. The 3D CD Button and Chromeless Clock gadgets are designed by Nathan Dunlap. Debug builds are available upon request.
I have recently updated the content of the Applications and Code and Project and Researches sections.
More specifically, updated is the Desktop and Preview Pane Aurora page, which now covers the development since early conceptual art, through various milestones, up to present day Windows Vista builds.
Added is a page describing ClockLock, a Windows application and service combo which I helped develop. Its primary aim is to let home computer users limit others’ computer activity based on a given time span. It is particularly helpful when restricting children’s computer usage at night.
I am already working on a new and better version of Windows Sidebar Styler. It implements a more sophisticated method of loading styles in memory, instead of modifying resources on disk which makes the solution relatively clean, unlike the previous version. This also guarantees that the application will work seamlessly with future builds, as well. I plan to add more features, including resizing for Windows Sidebar.
Windows Sidebar Styler (for build 5342+)
6 Comments Published April 19th, 2006 in Programming, Windows VistaWindows Vista Build 5342.2 to be released today!
2 Comments Published March 24th, 2006 in Windows VistaAccording to Utakz, Microsoft is going to release build 5342.2 of Windows Vista today. Information about this particular build appeared on the Internet via Paul Thurrott’s Windows SuperSite earlier this month.
This release is to be from the base winmain branch, and not an Idx (Internal Development Workstation/Server). Because of the fact that this is supposed to be a refresh build, there will most-likely be only bug fixes.
No screenshots or actual bits have been posted yet, but we all shall see in a few hours time.
Search
About
Stanimir Stoyanov is a programmer, software beta tester, and Windows enthusiast. Read More...
Currently, he is administering AeroXperience and coding using Visual Studio 2008 on Windows Vista. He is looking forward to testing Windows 7 soon.
Latest
- Tweak DWM from your programs, Part 1
- Windows Vista Language Packs Released
- Windows Sidebar Styler, v2.0.6
- Fine-Grained Password Policy Tool
- Microsoft Partner Campaign
- New Release of Windows Sidebar Styler
- Windows Sidebar Styler
- Content updates.
- Windows Sidebar Styler (for build 5342+)
- Windows Vista Build 5342.2 to be released today!
Related
- #DevBeta
- AeroXperience
- Andre Da Costa
- Benjamin Staneck
- Bruno Silva
- Channel9
- Dean Wronowski
- James Proud
- Jose Francisco's XP Source
- Karl Wagner
- Kristan Kenney
- laraAJ
- Lukas Mergenthaler
- Michael Frank
- Nexus
- obsethryl's lab
- Olcay Buyan
- Rafael Rivera
- Sam Haghgoo
- Sean O'Sullivan
- Spencer
- Steven Troughton-Smith
- Utaks
- Victor Mach
- Zack Whittaker









