📜 ⬆️ ⬇️

Windows 7 & DWN: Did you know that not all windows must obey Flip3D and Aero Peek

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

Aero Peek Flip3D

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 .
  1. 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:

  1. public partial class FormSample: Form
  2. {
  3. [DllImport ( "dwmapi.dll" , PreserveSig = false )]
  4. public static extern bool DwmIsCompositionEnabled ();
  5. public FormSample ()
  6. {
  7. Initializecomponent ();
  8. if (Environment.OSVersion.Version.Major <6)
  9. {
  10. // dwm not working, old version of windows
  11. }
  12. else if (! DwmIsCompositionEnabled ())
  13. {
  14. // Aero Glass and Aero 3D are disabled (not supported)
  15. }
  16. else
  17. {
  18. // Aero Glass and Aero 3D work
  19. }
  20. }
  21. }
* 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:

  1. public partial class FormSample: Form
  2. {
  3. [Flags]
  4. public enum DwmWindowAttribute
  5. {
  6. ExcludedFromPeek = 12
  7. }
  8. [DllImport ( "dwmapi.dll" , PreserveSig = false )]
  9. public static extern int DwmSetWindowAttribute ( IntPtr hwnd, int attr, ref int attrValue, int attrSize);
  10. public static void RemoveFromAeroPeek ( IntPtr hwnd)
  11. {
  12. int attrValue = 1; // TRUE
  13. DwmSetWindowAttribute (hwnd, ( int ) DwmWindowAttribute.ExcludedFromPeek, ref attrValue, sizeof ( int ));
  14. }
  15. public FormSample ()
  16. {
  17. Initializecomponent ();
  18. // Make Visible With Aero Peek
  19. RemoveFromAeroPeek (Handle);
  20. }
  21. }
* 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):

Remove Aero Peek Result

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 .

  1. public partial class FormSample: Form
  2. {
  3. [Flags]
  4. public enum DwmWindowAttribute
  5. {
  6. Flip3DPolicy = 8
  7. }
  8. // Flip 3D policies
  9. public enum Flip3DPolicy
  10. {
  11. Default = 0,
  12. ExcludeBelow
  13. ExcludeAbove
  14. }
  15. [DllImport ( "dwmapi.dll" , PreserveSig = false )]
  16. public static extern int DwmSetWindowAttribute ( IntPtr hwnd, int attr, ref int attrValue, int attrSize);
  17. public static void SetFlip3DPolicy ( IntPtr hwnd)
  18. {
  19. int attrValue = ( int ) Flip3DPolicy.ExcludeBelow;
  20. DwmSetWindowAttribute (hwnd, ( int ) DwmWindowAttribute.Flip3DPolicy, ref attrValue, sizeof ( int ));
  21. }
  22. public FormSample ()
  23. {
  24. Initializecomponent ();
  25. SetFlip3DPolicy (Handle);
  26. }
  27. }
* This source code was highlighted with Source Code Highlighter .


The result is as follows:

Set 3DFlip Policy Result

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

Progg it

Source: https://habr.com/ru/post/71609/


All Articles