1

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

Navid Rahmani
  • 7,848
  • 9
  • 39
  • 57
  • I do not believe you can. If the process is running and it has a form/window that the user can see, one would hope Microsoft wouldn't allow this, otherwise it would be to easy to write malware. – Security Hound Aug 03 '11 at 14:05
  • I believe this may be a duplicate question. That is assuming that Alt-Tab and Win-Tab use the same window styles behind the scenes. See: http://stackoverflow.com/questions/357076/best-way-to-hide-a-window-from-the-alt-tab-program-switcher – bporter Aug 03 '11 at 14:09
  • That will remove from Alt+Tab dialog but not worked for flip 3d. – Navid Rahmani Aug 03 '11 at 14:13

2 Answers2

2

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.

vhanla
  • 750
  • 5
  • 15
0

Just set ShowInTaskbar for the main form to false:

<Window x:Class="WpfNoFlip3D.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" ShowInTaskbar="False">
    <Grid>        
    </Grid>
</Window>

Be aware that it doesn't work for Alt+Tab, it is only for Win+Tab (as per your request) The side effect is that your application will also disappear from task bar.

michalczerwinski
  • 1,069
  • 9
  • 6