You probably know that in Vista and Windows 7 there is a function
Flip3D , and in Windows 7 also
Aero Peek .

But you probably do not know that you can force your window (application) not to obey the rules for all windows in these Windows features. To do this, study the
Desktop Window Manager API .
')
So where to start? As always, if we write an application on .net (WinForms or WPF), we need to import the necessary methods. It is worth noting that in the case of WinForms it is very easy to get the HWND windows, for this you have the
Form :: Handle property, in the case of WPF you can use the
WindowInteropHelper class, so you can write the HWND of the main window like this:
IntPtr hwnd = new WindowInteropHelper(Application.Current.MainWindow).Handle; * This source code was highlighted with Source Code Highlighter .
IntPtr hwnd = new WindowInteropHelper(Application.Current.MainWindow).Handle; * This source code was highlighted with Source Code Highlighter .
IntPtr hwnd = new WindowInteropHelper(Application.Current.MainWindow).Handle; * This source code was highlighted with Source Code Highlighter .
We now return to the necessary functions. The first function that you should pay attention to is
DwmIsCompositionEnabled , it allows us to determine whether Aero Glass is enabled on the computer:
- public partial class FormSample: Form
- {
- [DllImport ( "dwmapi.dll" , PreserveSig = false )]
- public static extern bool DwmIsCompositionEnabled ();
- public FormSample ()
- {
- Initializecomponent ();
- if (Environment.OSVersion.Version.Major <6)
- {
- // dwm not working, old version of windows
- }
- else if (! DwmIsCompositionEnabled ())
- {
- // Aero Glass and Aero 3D are disabled (not supported)
- }
- else
- {
- // Aero Glass and Aero 3D work
- }
- }
- }
* This source code was highlighted with Source Code Highlighter .
Great, now we know when we can “play” with Dwm, the next function that will help us work with Dwn is the
DwmSetWindowAttribute . This is the main function with which we can manage our window and tell the system how to display it.
For example, the first action. The task, we want to make such an application, which is displayed even when the user turns on Aero Peek mode (an action similar to a gadget). Imagine a lot of running windows on your monitor, you are too lazy to search for a necessary window using WinKey + Tab, and you want to see the necessary windows using WinKey + Space - this can be a regular messenger, and some profiler with which you monitor work of something, well, much more. So, for example, here in this article “
Joel 'Jaykul' Bennett - Fun with PInvoke and Aero Peek “ describes how you can do this with the popular messenger Miranda (this article interested Dwn and what possibilities it still provides). True, this article uses the DwmNCRenderingPolicy flags, which are actually suitable for setting values ​​when using the DWMWA_NCRENDERING_POLICY flag, and not DWMWA_EXCLUDED_FROM_PEEK. For the usual form, you can do this:
- public partial class FormSample: Form
- {
- [Flags]
- public enum DwmWindowAttribute
- {
- ExcludedFromPeek = 12
- }
- [DllImport ( "dwmapi.dll" , PreserveSig = false )]
- public static extern int DwmSetWindowAttribute ( IntPtr hwnd, int attr, ref int attrValue, int attrSize);
- public static void RemoveFromAeroPeek ( IntPtr hwnd)
- {
- int attrValue = 1; // TRUE
- DwmSetWindowAttribute (hwnd, ( int ) DwmWindowAttribute.ExcludedFromPeek, ref attrValue, sizeof ( int ));
- }
- public FormSample ()
- {
- Initializecomponent ();
- // Make Visible With Aero Peek
- RemoveFromAeroPeek (Handle);
- }
- }
* This source code was highlighted with Source Code Highlighter .
The result will be as follows (this is to make it more understandable about what I generally write):

You can also force your window not to obey the rules of Aero 3D (this is when using WinKey + Tab to switch between windows). For this you need to consider the attribute
DWMWA_FLIP3D_POLICY , for it you can set the values ​​“Normal behavior”, “Show on top 3D”, “Show on 3D”, although it worked for me either “normal behavior” or “show on 3D”, it didn't work on top .
- public partial class FormSample: Form
- {
- [Flags]
- public enum DwmWindowAttribute
- {
- Flip3DPolicy = 8
- }
- // Flip 3D policies
- public enum Flip3DPolicy
- {
- Default = 0,
- ExcludeBelow
- ExcludeAbove
- }
- [DllImport ( "dwmapi.dll" , PreserveSig = false )]
- public static extern int DwmSetWindowAttribute ( IntPtr hwnd, int attr, ref int attrValue, int attrSize);
- public static void SetFlip3DPolicy ( IntPtr hwnd)
- {
- int attrValue = ( int ) Flip3DPolicy.ExcludeBelow;
- DwmSetWindowAttribute (hwnd, ( int ) DwmWindowAttribute.Flip3DPolicy, ref attrValue, sizeof ( int ));
- }
- public FormSample ()
- {
- Initializecomponent ();
- SetFlip3DPolicy (Handle);
- }
- }
* This source code was highlighted with Source Code Highlighter .
The result is as follows:

How to use it is harder to imagine. Well ... my business is to tell :) Good luck!
