让窗口显示在所有虚拟桌面上
功能如图
C#代码实现如下
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); ShowInTaskbar = false; this.Loaded += MainWindow_Loaded; } private void MainWindow_Loaded(object sender, RoutedEventArgs e) { IntPtr a = new System.Windows.Interop.WindowInteropHelper(this).Handle; IntPtr hWnd = new WindowInteropHelper(this).Handle; IntPtr longhWnd = GetWindowLongPtr(hWnd, GetWindowLongFields.GWL_EXSTYLE); var re = SetWindowLongPtr(hWnd, GetWindowLongFields.GWL_EXSTYLE, new IntPtr((int)longhWnd | 0x08000000)); } [DllImport("user32.dll")] static extern int SetWindowLongPtr(IntPtr hWnd, GetWindowLongFields nIndex, IntPtr dwNewLong); [DllImport("user32.dll")] static extern IntPtr GetWindowLongPtr(IntPtr hWnd, GetWindowLongFields nIndex); private const int GWL_EXSTYLE = -20; private const int WS_EX_TOOLWINDOW = 0x00000080; // 使窗口不会在任务栏显示 private const int WS_EX_APPWINDOW = 0x00040000; // 使窗口出现在任务栏 private const int WS_EX_NOREDIRECTIONBITMAP = 0x00200000; } public enum GetWindowLongFields { /// <summary> /// 设定一个新的扩展风格 /// Retrieves the extended window styles /// </summary> GWL_EXSTYLE = -20, /// <summary> /// 设置一个新的应用程序实例句柄 /// Retrieves a handle to the application instance /// </summary> GWL_HINSTANCE = -6, /// <summary> /// 改变子窗口的父窗口 /// Retrieves a handle to the parent window, if any /// </summary> GWL_HWNDPARENT = -8, /// <summary> /// 设置一个新的窗口标识符 /// Retrieves the identifier of the window /// </summary> GWL_ID = -12, /// <summary> /// 设定一个新的窗口风格 /// Retrieves the window styles /// </summary> GWL_STYLE = -16, /// <summary> /// 设置与窗口有关的32位值。每个窗口均有一个由创建该窗口的应用程序使用的32位值 /// Retrieves the user data associated with the window. This data is intended for use by the application that created the window. Its value is initially zero /// </summary> GWL_USERDATA = -21, /// <summary> /// 为窗口设定一个新的处理函数 /// Retrieves the address of the window procedure, or a handle representing the address of the window procedure. You must use the CallWindowProc function to call the window procedure /// </summary> GWL_WNDPROC = -4, }
特别提醒一句
ShowInTaskbar = false;

浙公网安备 33010602011771号