如何从Flip3D中删除WPF应用程序?

时间:2011-08-03 13:57:46

标签: c# wpf aero flip3d

如何创建一个永远不会出现在Flip3d(Winkey + Tab)对话框中的WPF窗口?

2 个答案:

答案 0 :(得分:2)

我是这样做的:

...
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);
        }
    }
}

它隐藏在Flip3D中,其他的仍保持原样(alt-tab和任务栏)。 但是,当Flip3D正在运行时,应用程序仍在后台显示

答案 1 :(得分:0)

只需将主窗体的ShowInTaskbar设置为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>

请注意,它不适用于Alt + Tab,仅适用于Win + Tab(根据您的要求) 副作用是您的应用程序也将从任务栏中消失。