gpt4 book ai didi

.net - 在 Windows 任务栏中对单独的进程进行分组

转载 作者:行者123 更新时间:2023-12-02 15:09:10 25 4
gpt4 key购买 nike

我有许多逻辑上相关的独立进程(但所有进程都是单独启动的 - 没有共同的“父”进程)。

是否可以使它们在 Windows 任务栏中显示为一组?

工作示例

这是一些受雷米回答启发的工作代码

using System;
using System.Runtime.InteropServices;
using System.Security;

namespace ConsoleApplication1
{
[SuppressUnmanagedCodeSecurity]
internal static class SafeNativeMethods
{
[DllImport("shell32.dll")]
public static extern int SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID);

[DllImport("kernel32.dll")]
public static extern bool AllocConsole();

[DllImport("kernel32.dll")]
public static extern bool FreeConsole();
}

internal class Program
{
public static int SetApplicationUserModelId(string appId)
{
// check for Windows 7
Version version = Environment.OSVersion.Version;
if ((version.Major > 6) || (version.Major == 6 && version.Minor >= 1))
return SafeNativeMethods.SetCurrentProcessExplicitAppUserModelID(appId);
return -1;
}

[STAThread]
public static void Main(string[] args)
{
int result = SetApplicationUserModelId("Gardiner.Sample1");

SafeNativeMethods.AllocConsole();

// Now we have a console, we can write to it
Console.Title = "Sample 1";

Console.WriteLine("Sample 1 {0}", result);
Console.ReadLine();
SafeNativeMethods.FreeConsole();
}
}
}

要使其正常工作,必须将可执行文件的“输出类型”设置为“Windows 应用程序”,并将“启动对象”配置为“ConsoleApplication1.Program”(对于上面的代码示例)。

最佳答案

是的,但仅限于 Windows 7 及更高版本。如果多个进程和窗口具有相同的 Application User Model ID,则它们会在任务栏上分组在一起。分配给他们。

关于.net - 在 Windows 任务栏中对单独的进程进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13924264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com