wpf 更改 Win7 任务栏中显示的应用程序名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12711899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 05:37:46  来源:igfitidea点击:

Change application name shown in Win7 taskbar

c#wpfprismtaskbar

提问by Mohit Vashistha

I want to change the application name that shows up in windows 7 taskbar context menu.

我想更改显示在 Windows 7 任务栏上下文菜单中的应用程序名称。

enter image description here

在此处输入图片说明

My applicaiton currently shows my application name. I want to change it to something like microsoft product does

我的应用程序当前显示我的应用程序名称。我想把它改成像微软产品那样的东西

enter image description here

在此处输入图片说明

My application uses Prism framework and the application name I want to show will be decided on type of module. So I want to set the application name dynamically.

我的应用程序使用 Prism 框架,我想显示的应用程序名称将取决于模块的类型。所以我想动态设置应用程序名称。

回答by David Heffernan

You are seeing vshost32.exebecause you are running under the debugger. That's just the name of the host process used by the debugger and you cannot change that. Well, I suppose you could but it's not what you want to do. You want to change the name used by your executable.

您之所以看到,vshost32.exe是因为您正在调试器下运行。这只是调试器使用的主机进程的名称,您无法更改它。好吧,我想你可以,但这不是你想做的。您想更改可执行文件使用的名称。

When you run without debugging, as your users will, the application name displayed on the taskbar app popup is determined by the assembly name specified in the Application page of the project config. So, just change that to whatever you want and there's nothing more to do.

当您在没有调试的情况下运行时,就像您的用户一样,任务栏应用程序弹出窗口上显示的应用程序名称由项目配置的“应用程序”页面中指定的程序集名称决定。因此,只需将其更改为您想要的任何内容即可,无需再做任何事情。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by Erre Efe

With managed apps you set that property via the Windows API Code Pack Library, you can use the AppIDproperty that is part of the Taskbarobject, which you can find in the Microsoft.WindowsAPICodePack.Shell.Taskbarnamespace. Using that property you can set and get the application ID of a given application.

对于托管应用程序,您通过 Windows API 代码包库设置该属性,您可以使用AppID作为Taskbar对象一部分的属性,您可以在Microsoft.WindowsAPICodePack.Shell.Taskbar命名空间中找到该属性。使用该属性,您可以设置和获取给定应用程序的应用程序 ID。

You can also set it manually (if not using the pack). Just set the name setting with it's id:

您也可以手动设置(如果不使用包)。只需使用它的 id 设置名称设置:

void SetAppID(HWND hWnd, int iAppID)
{
    IPropertyStore *pps;
    HRESULT hr = SHGetPropertyStoreForWindow(hWnd, IID_PPV_ARGS(&pps));
    if (SUCCEEDED(hr))
    {
        PROPVARIANT pv;
        if (iAppID >= 0)
        {
            hr = InitPropVariantFromString(c_rgszAppID[iAppID], &pv);
        }
        else
        {
            PropVariantInit(&pv);
        }
        if (SUCCEEDED(hr))
        {
            hr = pps->SetValue(PKEY_AppUserModel_ID, pv);
            PropVariantClear(&pv);
        }
        pps->Release();
    }
}

And then calling it like:

然后像这样调用它:

private static void SetWindowAppId(string appId)
{
    Microsoft.WindowsAPICodePack.Shell.ShellNativeMethods.SetWindowAppId
        (OwnerHandle, "the name you want to display here");
}

See herefor a full example.

有关完整示例,请参见此处