从任务栏隐藏外部应用程序

2023-11-25

我浏览了许多不同的论坛,但找不到方法。我希望从任务栏隐藏外部应用程序图标,但不最小化应用程序。我不知道从哪里开始,也不知道如何去做。任何帮助将不胜感激。

NOTE隐藏外部应用程序图标,而不是我的表单的图标。


您可以使用橱窗展示功能。这是一个小示例,它将隐藏任务栏中正在运行的“calc.exe”。

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

internal class Program
{
    /// <summary>Shows a Window</summary>
    /// <remarks>
    /// <para>To perform certain special effects when showing or hiding a 
    /// window, use AnimateWindow.</para>
    ///<para>The first time an application calls ShowWindow, it should use 
    ///the WinMain function's nCmdShow parameter as its nCmdShow parameter. 
    ///Subsequent calls to ShowWindow must use one of the values in the 
    ///given list, instead of the one specified by the WinMain function's 
    ///nCmdShow parameter.</para>
    ///<para>As noted in the discussion of the nCmdShow parameter, the 
    ///nCmdShow value is ignored in the first call to ShowWindow if the 
    ///program that launched the application specifies startup information 
    ///in the structure. In this case, ShowWindow uses the information 
    ///specified in the STARTUPINFO structure to show the window. On 
    ///subsequent calls, the application must call ShowWindow with nCmdShow 
    ///set to SW_SHOWDEFAULT to use the startup information provided by the 
    ///program that launched the application. This behavior is designed for 
    ///the following situations: </para>
    ///<list type="">
    ///    <item>Applications create their main window by calling CreateWindow 
    ///    with the WS_VISIBLE flag set. </item>
    ///    <item>Applications create their main window by calling CreateWindow 
    ///    with the WS_VISIBLE flag cleared, and later call ShowWindow with the 
    ///    SW_SHOW flag set to make it visible.</item>
    ///</list></remarks>
    /// <param name="hWnd">Handle to the window.</param>
    /// <param name="nCmdShow">Specifies how the window is to be shown. 
    /// This parameter is ignored the first time an application calls 
    /// ShowWindow, if the program that launched the application provides a 
    /// STARTUPINFO structure. Otherwise, the first time ShowWindow is called, 
    /// the value should be the value obtained by the WinMain function in its 
    /// nCmdShow parameter. In subsequent calls, this parameter can be one of 
    /// the WindowShowStyle members.</param>
    /// <returns>
    /// If the window was previously visible, the return value is nonzero. 
    /// If the window was previously hidden, the return value is zero.
    /// </returns>
    [DllImport("user32.dll")]
    private static extern bool ShowWindow(IntPtr hWnd, WindowShowStyle nCmdShow);

    /// <summary>Enumeration of the different ways of showing a window using 
    /// ShowWindow</summary>
    private enum WindowShowStyle : uint
    {
        /// <summary>Hides the window and activates another window.</summary>
        /// <remarks>See SW_HIDE</remarks>
        Hide = 0,
        /// <summary>Activates and displays a window. If the window is minimized 
        /// or maximized, the system restores it to its original size and 
        /// position. An application should specify this flag when displaying 
        /// the window for the first time.</summary>
        /// <remarks>See SW_SHOWNORMAL</remarks>
        ShowNormal = 1,
        /// <summary>Activates the window and displays it as a minimized window.</summary>
        /// <remarks>See SW_SHOWMINIMIZED</remarks>
        ShowMinimized = 2,
        /// <summary>Activates the window and displays it as a maximized window.</summary>
        /// <remarks>See SW_SHOWMAXIMIZED</remarks>
        ShowMaximized = 3,
        /// <summary>Maximizes the specified window.</summary>
        /// <remarks>See SW_MAXIMIZE</remarks>
        Maximize = 3,
        /// <summary>Displays a window in its most recent size and position. 
        /// This value is similar to "ShowNormal", except the window is not 
        /// actived.</summary>
        /// <remarks>See SW_SHOWNOACTIVATE</remarks>
        ShowNormalNoActivate = 4,
        /// <summary>Activates the window and displays it in its current size 
        /// and position.</summary>
        /// <remarks>See SW_SHOW</remarks>
        Show = 5,
        /// <summary>Minimizes the specified window and activates the next 
        /// top-level window in the Z order.</summary>
        /// <remarks>See SW_MINIMIZE</remarks>
        Minimize = 6,
        /// <summary>Displays the window as a minimized window. This value is 
        /// similar to "ShowMinimized", except the window is not activated.</summary>
        /// <remarks>See SW_SHOWMINNOACTIVE</remarks>
        ShowMinNoActivate = 7,
        /// <summary>Displays the window in its current size and position. This 
        /// value is similar to "Show", except the window is not activated.</summary>
        /// <remarks>See SW_SHOWNA</remarks>
        ShowNoActivate = 8,
        /// <summary>Activates and displays the window. If the window is 
        /// minimized or maximized, the system restores it to its original size 
        /// and position. An application should specify this flag when restoring 
        /// a minimized window.</summary>
        /// <remarks>See SW_RESTORE</remarks>
        Restore = 9,
        /// <summary>Sets the show state based on the SW_ value specified in the 
        /// STARTUPINFO structure passed to the CreateProcess function by the 
        /// program that started the application.</summary>
        /// <remarks>See SW_SHOWDEFAULT</remarks>
        ShowDefault = 10,
        /// <summary>Windows 2000/XP: Minimizes a window, even if the thread 
        /// that owns the window is hung. This flag should only be used when 
        /// minimizing windows from a different thread.</summary>
        /// <remarks>See SW_FORCEMINIMIZE</remarks>
        ForceMinimized = 11
    }


    private static void Main(string[] args)
    {
        Process[] p = Process.GetProcessesByName("calc"); 

        if(p.Length > 0)
        {
            IntPtr hWnd = p[0].MainWindowHandle;

            ShowWindow(hWnd, WindowShowStyle.Hide);
        }

        Console.ReadLine();
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从任务栏隐藏外部应用程序 的相关文章

随机推荐

  • 如何从一条管道中排放另一条管道中的水?

    我需要以编程方式从另一个管道中排出管道 这DataflowPipelineJob类没有drain方法实施 可以打电话吗drain使用 Java API 的管道 能够使用以下代码启动排水 spawn child pipe DataflowPi
  • 终端中带有块字符的文本进度条[关闭]

    Closed 这个问题需要多问focused 目前不接受答案 我编写了一个简单的控制台应用程序 用于使用 ftplib 从 FTP 服务器上传和下载文件 我希望该应用程序向用户显示其下载 上传进度的一些可视化 每次下载数据块时 我希望它提供
  • IIS 7.5 中的 ASP.NET MVC3

    你好 我想在 Windows Server 2008 R2 SP1 中发布 MVC 3 站点 我安装了 MVC 3 和 MVC 2 当我创建 MVC 2 站点时 它工作正常 但 MVC 3 站点无法工作 我首先安装了 MVC 3 当该站点无
  • ASP Net Core Linux ERR_CONNECTION_REFUSED

    我正在测试将网络核心应用程序部署到运行 Ubuntu 18 04 和 Nginx 1 14 的 Digitalocean Droplet 为了进行测试 我使用 dotnet new 中提供的模板 The 点网新网 and dotnet新mv
  • 如何写入/传输到 V4L2loopback 模块创建的虚拟网络摄像头?

    我编写了一个应用程序 它从网络摄像头读取数据并在 Linux 上使用 OpenCV 处理帧 现在我想将应用程序的输出通过管道传输到由 V4L2loopback 模块创建的虚拟网络摄像头 以便其他应用程序能够读取它 我使用 C 编写了该应用程
  • 如何用 Javascript 替换整个 HTML 内容?

    我尝试使用 html html this responseText 它替换了内容 但不替换 head 和 body 标签 例如 如果我想替换此内容 h1 This is a Heading h1 然后我在检查器中检查 HTML 结构 结果如
  • 在顶部插入时,双端队列是否提供 O(1) 复杂度

    我正要过去thispost 并指出 deque 在顶部和底部提供高效的插入 但是这post这里指出除后面之外的双端队列的时间复杂度是 O n 我认为如果双端队列具有有效的顶部和底部插入 它将具有 O 1 而向量应该仅在底部插入具有 O 1
  • ReferenceError:未定义 privateSpecialRepair

    我在哨兵上收到此错误 我不知道下一个 路由器如何或为什么将用户重定向到同一页面 它发生在某些浏览器上 并且在某些浏览器上工作得很好 Tags routing instrumentation next router 操作 页面加载 看起来这与
  • Xcode 4 外部构建项目和调试

    我已经设置了一个基于 makefile 的项目 可以在多个平台上构建我的代码 在我的 Mac 上 我想使用 Xcode 进行调试 我已将 Xcode 设置为外部构建项目 我可以从 Xcode 中运行该应用程序 输出显示在 Xcode 中 如
  • 我应该如何组织我的 OCaml 项目?

    我知道这个问题很普遍 我什至不知道如何更好地问 我没有太多的经验C我只是希望我能在 OCaml 中做与 Java 类似的事情 例如 在Java 我通常创建一个项目 使用Eclipse或其他 IDE 那么我有一个src文件夹和一个bin文件夹
  • JTable 列跨越

    我正在尝试做一个JTable有可用的列跨度 具体来说 我希望嵌套一个JTable在另一个里面JTable 当用户单击查看嵌套表时 它应该展开以下推下面的行并填充空白空间 这与您在 MS Access 中看到的类似 您可以在其中嵌套表 单击行
  • JavaScript 中的全局变量和“window.variable”有什么区别?

    我正在读骨干网 js文档 并且我看到很多将属性分配给window object window something whatever 调用此代码与仅分配变量并创建全局变量有什么区别 如下所示 something whatever 我假设存在某
  • 将多级 JSON 菜单转换为多级 JSX/HTML 菜单

    我在用智能菜单创建一个下拉菜单 但是 我想动态创建菜单 React 应用程序将向 API 服务器查询 JSON 代码 并据此构建菜单 我正在尝试找出一种将 JSON 代码转换为 HTML JSX 代码的方法 从 API 检索到的 JSON
  • OpenCV 输入数组/输出数组

    我刚刚编译了 OpenCV 2 3 的最新版本 他们决定将所有 Matrix 输入 输出更改为 InputArray OutputArray 这让一切都变得混乱 在 OpenCV 2 2 下运行良好的同一段代码现在毫无价值 我可以接受两种解
  • 创建maven项目

    如何在 Eclipse 中创建一个简单的 Maven 项目 每次创建项目时都会出现错误 错误 描述 资源路径 位置类型 CoreException Could 不计算构建计划 插件 org apache maven plugins mave
  • CSRF 令牌与 Laravel sainttum 和 Angular http 不匹配

    我一直在尝试实现 Laravel Sanctum 但即使我遵循了 Laravel Sanctum 文档中所述的所有内容 我也遇到了 CSRF 令牌不匹配 错误 cors php配置文件 paths gt api login logout s
  • 显示不同时区的时间

    有没有一种优雅的方式来显示另一个时区的当前时间 我想要一些具有以下一般精神的东西 cur
  • 如何扩展 Array 类并保留其实现

    我想向 Array 类添加一些函数 我不想将它们作为类外部的函数 因为理想情况下在键入时可以发现它们 跟随物体 这是我到目前为止所拥有的 export class List
  • RDLC - 在VS2010中添加数据源

    问候 我有一个 RDLC 文件 并且想向其中添加数据源 尽管到目前为止还没有任何运气 数据源是我自己编写的自定义类 只是补充一下 我们一直这样做 我们最近转换为 VS2010 RDLC 格式 这导致了一些问题 但我们对实现进行了一些更改 解
  • 从任务栏隐藏外部应用程序

    我浏览了许多不同的论坛 但找不到方法 我希望从任务栏隐藏外部应用程序图标 但不最小化应用程序 我不知道从哪里开始 也不知道如何去做 任何帮助将不胜感激 NOTE隐藏外部应用程序图标 而不是我的表单的图标 您可以使用橱窗展示功能 这是一个小示