1

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

4

2 回答 2

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 运行时,应用程序仍显示在后台

于 2011-08-26T07:15:24.050 回答
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(根据您的要求)。副作用是您的应用程序也会从任务栏中消失。

于 2011-08-05T19:38:34.213 回答