C# 从任务栏隐藏外部应用程序
我浏览了很多不同的论坛,但我找不到一个方法。我希望从任务栏中隐藏外部应用程序图标,但不要最小化应用程序。我不知道从哪里开始,也不知道怎么做。任何帮助都将不胜感激 注意:隐藏外部应用程序图标,而不是我表单的图标。您可以使用该功能来完成此操作。下面是一个小示例,它将从任务栏中隐藏正在运行的“calc.exe”C# 从任务栏隐藏外部应用程序,c#,C#,我浏览了很多不同的论坛,但我找不到一个方法。我希望从任务栏中隐藏外部应用程序图标,但不要最小化应用程序。我不知道从哪里开始,也不知道怎么做。任何帮助都将不胜感激 注意:隐藏外部应用程序图标,而不是我表单的图标。您可以使用该功能来完成此操作。下面是一个小示例,它将从任务栏中隐藏正在运行的“calc.exe” using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Diagnostics;
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();
}
}
使用Newtonsoft.Json;
使用制度;
使用System.Collections.Generic;
使用系统诊断;
使用System.IO;
Net系统;
使用System.Net.Sockets;
使用系统数字;
使用System.Runtime.CompilerServices;
使用System.Runtime.InteropServices;
使用系统文本;
使用系统线程;
使用System.Threading.Tasks;
内部课程计划
{
///显示一个窗口
///
///在显示或隐藏图像时执行某些特殊效果
///窗口,使用动画窗口。
///应用程序第一次调用ShowWindow时,应使用
///WinMain函数的nCmdShow参数作为其nCmdShow参数。
///对ShowWindow的后续调用必须使用
///给定的列表,而不是WinMain函数的
///nCmdShow参数。
///如nCmdShow参数讨论中所述
///如果
///启动应用程序的程序指定启动信息
///在这种情况下,ShowWindow使用
///在STARTUPINFO结构中指定以显示窗口
///在后续调用中,应用程序必须使用nCmdShow调用ShowWindow
///设置为SW_SHOWDEFAULT以使用
///启动应用程序的程序。此行为是为
///下列情况:
///
///应用程序通过调用CreateWindow创建主窗口
///设置了WS_可见标志。
///应用程序通过调用CreateWindow创建主窗口
///清除WS_VISIBLE标志后,使用
///设置SW_显示标志以使其可见。
///
///窗口的把手。
///指定窗口的显示方式。
///此参数在应用程序第一次调用时被忽略
///ShowWindow,如果启动应用程序的程序提供
///STARTUPINFO结构。否则,第一次调用ShowWindow时,
///该值应为WinMain函数在其
///nCmdShow参数。在后续调用中,此参数可以是
///WindowsShowStyle成员。
///
///如果窗口以前可见,则返回值为非零。
///如果该窗口以前是隐藏的,则返回值为零。
///
[DllImport(“user32.dll”)]
私有静态外部bool ShowWindow(IntPtr hWnd、WindowShowStyle nCmdShow);
///枚举使用
///橱窗
私有枚举窗口显示样式:uint
{
///隐藏窗口并激活另一个窗口。
///请参阅SW_HIDE
Hide=0,
///激活并显示窗口。如果窗口最小化
///或最大化,系统将其恢复到其原始大小和
///位置。应用程序在显示时应指定此标志
///这是第一次打开窗户。
///见SW_SHOWNORMAL
ShowNormal=1,
///激活窗口并将其显示为最小化窗口。
///见SW_-Show
show=2,
///激活窗口并将其显示为最大化窗口。
///见SW_showmized
显示最大化=3,
///最大化指定的窗口。
///见SW_
最大化=3,
///显示窗口的最新大小和位置。
///该值与“ShowNormal”类似,只是窗口不可用
///活跃的。
///请参阅SW_SHOWNOACTIVATE
ShowNormalNoActivate=4,
///激活窗口并以其当前大小显示它
///和位置。
///见SW_SHOW
Show=5,
///最小化指定的窗口并激活下一个窗口
///按Z顺序排列的顶级窗口。
///见SW_
最小化=6,
///将窗口显示为最小化窗口。此值为
///与“ShowMinimized”类似,只是窗口未激活。
///见SW_showminoactive
showminoactivate=7,
///以当前大小和位置显示窗口。此
///值与“显示”类似,只是窗口未激活。
///见SW_SHOWNA
ShowNoActivate=8,
///激活并显示窗口。如果窗口
///最小化或最大化后,系统会将其恢复为原始大小
///和位置。应用程序在还原时应指定此标志
///最小化的窗口。
///参见SW_恢复
恢复=9,
///根据中指定的SW_uu值设置显示状态
///由传递给CreateProcess函数的STARTUPINFO结构
///启动应用程序的程序。
///请参阅SW_SHOWDEFAULT
ShowDefault=10,
///Windows 2000/XP:最小化窗口,即使线程
///拥有该窗口的已挂起。仅当
///从不同线程最小化窗口。
///见SW_
力最小化=11
}
私有静态void Main(字符串[]args)
{
Process[]p=Process.GetProcessesByName(“计算”);
如果(p.Length>0)
{
IntPtr hWnd=p[0]。MainWindowHandle;
ShowWindow(hWnd,WindowShowStyle.Hide);
public MyForm()
{
InitializeComponent();
this.ShowInTaskbar = false;
}