让窗口显示在所有虚拟桌面上
功能如图

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;
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性