Search code examples
c#wpfaeroflip3d

How to remove WPF application from Flip3D?


How can I make a WPF window that will never appear in the Flip3d (Winkey+Tab) dialog?


Solution

  • Here is how I do it:

    ...
    using System.Runtime.InteropServices;
    using System.Windows.Interop;
    namespace NoFlip3D
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            [DllImport("dwmapi.dll", PreserveSig = false)]
            public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
            [Flags]
            public enum DwmWindowAttribute
            {
                NCRenderingEnabled = 1,
                NCRenderingPolicy,
                TransitionsForceDisabled,
                AllowNCPaint,
                CaptionButtonBounds,
                NonClientRtlLayout,
                ForceIconicRepresentation,
                Flip3DPolicy,
                ExtendedFrameBounds,
                HasIconicBitmap,
                DisallowPeek,
                ExcludedFromPeek,
                Last
            }
    
            [Flags]
            public enum DwmNCRenderingPolicy
            {
                UseWindowStyle,
                Disabled,
                Enabled,
                Last
            }
            public MainWindow()
            {
                InitializeComponent();
            }
            public static void RemoveFromFlip3D(IntPtr Hwnd)
            {           
                int renderPolicy = (int)DwmNCRenderingPolicy.Enabled;
                DwmSetWindowAttribute(Hwnd, (int)DwmWindowAttribute.Flip3DPolicy, ref renderPolicy, sizeof(int));
            }
    
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                IntPtr AppHandle = new WindowInteropHelper(this).Handle;
                RemoveFromFlip3D(AppHandle);
            }
        }
    }
    

    It hides from Flip3D and the other ones remain as they were (alt-tab and taskbar). However, the application remains showing in background while Flip3D is running.