从没有任务栏按钮的c++启动c#应用程序
lauch c# app from c++ without taskbar button
我正在寻找一种从c++应用程序启动c#应用程序的方法,在我选择显示之前,不显示c#应用的任务栏按钮。
我有一个类可以隐藏和显示任务栏按钮,但在启动c#应用程序时,任务栏按钮会短暂显示。
有没有一种方法可以在操作系统不创建任务栏按钮的情况下启动c#应用程序,同时允许我稍后显示任务栏按钮?
这是我目前用来隐藏和显示任务栏按钮的代码。
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
class Program
{
static void Main()
{
var tb = new Taskbar();
tb.DeleteTab();
bool hidden = true;
while (true)
{
Console.WriteLine("Press any key to toggle taskbar button");
Console.ReadKey();
Console.Clear();
if (hidden)
tb.AddTab();
else
tb.DeleteTab();
hidden = !hidden;
}
}
}
class Taskbar
{
public void AddTab()
{
GetTaskbarList().AddTab(GetMainWindowHandle());
}
public void DeleteTab()
{
GetTaskbarList().DeleteTab(GetMainWindowHandle());
}
ITaskbarList GetTaskbarList()
{
var taskbarList = (ITaskbarList)new CoTaskbarList();
taskbarList.HrInit();
return taskbarList;
}
IntPtr GetMainWindowHandle()
{
return Process.GetCurrentProcess().MainWindowHandle;
}
[ComImport]
[Guid("56fdf344-fd6d-11d0-958a-006097c9a090")]
class CoTaskbarList
{
}
[ComImport,
Guid("56fdf342-fd6d-11d0-958a-006097c9a090"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface ITaskbarList
{
/// <summary>
/// Initializes the taskbar list object. This method must be called before any other ITaskbarList methods can be called.
/// </summary>
void HrInit();
/// <summary>
/// Adds an item to the taskbar.
/// </summary>
/// <param name="hWnd">A handle to the window to be added to the taskbar.</param>
void AddTab([In] IntPtr hWnd);
/// <summary>
/// Deletes an item from the taskbar.
/// </summary>
/// <param name="hWnd">A handle to the window to be deleted from the taskbar.</param>
void DeleteTab([In] IntPtr hWnd);
/// <summary>
/// Activates an item on the taskbar. The window is not actually activated; the window's item on the taskbar is merely displayed as active.
/// </summary>
/// <param name="hWnd">A handle to the window on the taskbar to be displayed as active.</param>
void ActivateTab([In] IntPtr hWnd);
/// <summary>
/// Marks a taskbar item as active but does not visually activate it.
/// </summary>
/// <param name="hWnd">A handle to the window to be marked as active.</param>
void SetActiveAlt([In] IntPtr hWnd);
}
}
设置ShowInTaskbar
(WinForms或WPF)属性。
最初将其设置为false
,应用程序将不会出现。
当您希望应用程序显示在任务栏中时,将其设置为true
。
使用:
this.ShowInTaskbar = false;
在Form
的构造函数中(或者在设计器中设置它,如果可能的话)应该确保最初没有创建任务栏按钮。我认为您应该仍然能够在必要时创建一个。
相关文章:
- 如何创建一个空的全局类并在启动时实例化它
- 即使我读取了所有内容,在FIFO上打开的QSocketNotifier也会一直启动
- 使用 std::string () const 函数启动线程或未来
- 如何修复valgrind启动时的致命错误(与libc6-dbg和libc6-dbg:i386连接)
- 将向量作为类>(值)<向量启动和向量<类>[值]有什么区别
- 如何创建线程序列以按照启动顺序执行任务?
- WINAPI 注册应用程序重新启动时不清除打开的套接字
- 在挂钩启动新线程时解除挂钩进程
- 程序无法启动,因为缺少 libmpc-3.dll
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- QSerialPort 在应用程序启动之前正在使用中
- 无法在 Arch Linux 中启动虚幻引擎 4
- C++关于指针和使用函数将它们启动到堆的行为究竟是什么?
- 如何使用 ctypes 停止和重新启动从 Python 运行的C++代码
- 程序在使用 system() 启动另一个可执行文件时停止
- Qt 和 Android - 如何使用 Qandroidjniobject 启动相机
- Q没有管理权限的 exe 无法启动维护工具
- 启动类函数作为失去引用的线程
- 如何使用C++确定应用程序是否已在窗口中启动?
- 在没有管理员权限的情况下,在 c++ 中以编程方式将程序添加到启动