GlassLib is a wrapper library for the Desktop Window Manager API and is to be used by developers which would like their applications to take advantage of .NET Framework and Windows Presentation Foundation in particular.
It can be used to control the Desktop Composition due to application requirements, create and reference Live Thumbnails of arbitrary windows, manipulate the Glass client area of windows and receive events which occur for them (Figure). Developers who target their applications for Far East users can also use the wrapper library to control the flow direction of controls and caption bar.
While the library wraps a big portion of the API exposed by DWM, the timing and performance counter part is to follow up shortly.
Documentation and a test application are provided. The usage of the wrapper library is pretty much straight-forward. Following is a list of several key facts:
Add a reference to the DwmWrapper.dll library to your project (from the Solution Explorer, select your project’s node, right click it and select Add Reference. From the new dialog box, browse the library file). Please note that the library is compiled against the .NET Framework 2.0 therefore it can only be used in projects compiled against it, or a newer version.
Include the GlassLib namespace so that the Dwm-related classes can be accessed more easily.
When used in a System.Windows.Window, override the OnSourceInitialized method and then set up the event handlers.
Per-window options can be set using the Dwm.Glass, Blur, Events, NonClientArea and Flip3D. This is available by using the indexer (default property) of these properties. The value passed to the indexer can be an IntPtr - handle to a window or a System.Windows.Media.Visual whose window handle will be manipulated. E.g:
In VB .NET: Dwm.Glass(Me).Enabled = False
In C# .NET: Dwm.Glass[this].Enabled = false;
Note: this and Me refer to the calling instance, which is a System.Windows.Window in the example.
The Dwm* structures have implicit operators. This allows for casting Windows Presentation Foundation Rect and Thickness implicitely to DwmRect and DwmMargins, respectively. For instance, the following expression will be valid:
Thickness foo = new Thickness(5, 30, 5, 20);// Assign foo to a Visual’s margin.Dwm.Glass[this].Margins = foo; // foo is implicitely casted to DwmMargins.
Stanimir Stoyanov is a programmer, Microsoft MVP, and Windows enthusiast. Read More...
He's currently working on an array of projects using Visual Studio 2010 on Windows 7.
- How the Active Directory – Data Store Really Works (Inside NTDS.dit) – Part 1
- Blocking unwanted advertisements and malware with a HOSTS file
- Multithreading with Windows Forms in C#
- Честита Коледа (и поздравления на спечелилите)!
- A simple backup solution using ImageX, a Windows Imaging tool
- Soon: MSDN Ultimate Subscriptions Giveaway
- Decoding FLAC audio files in C#
- Inline Tweet Translator
- Resizing forms while keeping aspect ratio
- Encoding uncompressed audio with FLAC in C#