简体   繁体   English

如何将我的应用程序与 Windows 7 任务栏上的固定程序相关联?

[英]How do I associate my application with a pinned program on the Windows 7 taskbar?

We have an application, let's call it MyApp .我们有一个应用程序,我们称之为MyApp On installation, we create a desktop icon for MyApp, which basically calls MyLauncher.exe /launch MyApp.exe .在安装时,我们为 MyApp 创建一个桌面图标,它基本上调用MyLauncher.exe /launch MyApp.exe MyLauncher does some useful stuff (check for updates, etc.), and then starts MyApp. MyLauncher 会做一些有用的事情(检查更新等),然后启动 MyApp。

桌面上的 MyApp

A user with Windows 7 might want to pin it to the task bar (ie, right mouse button on the desktop icon, "Pin to Taskbar"):使用 Windows 7 的用户可能希望将其固定到任务栏(即桌面图标上的鼠标右键,“固定到任务栏”):

任务栏上的 MyApp

However, since the shortcut points to MyLauncher, the following happens when the user starts the application (either with the desktop icon or the taskbar icon): MyLauncher does its stuff, and, afterwards, it starts MyApp.但是,由于快捷方式指向 MyLauncher,因此当用户启动应用程序(使用桌面图标或任务栏图标)时会发生以下情况:MyLauncher 执行其操作,然后启动 MyApp。 On the taskbar, the result is as follows:在任务栏上,结果如下:

MyApp 在任务栏上两次

I understand why this happens.我明白为什么会发生这种情况。 Since MyLauncher starts MyApp, the Windows 7 taskbar sees them as two different applications.由于 MyLauncher 启动 MyApp,Windows 7 任务栏将它们视为两个不同的应用程序。

Obviously, my question is: As the developer of MyLauncher and MyApp, can I do something about this?显然,我的问题是:作为 MyLauncher 和 MyApp 的开发者,我可以为此做些什么吗? I'd like the Windows 7 taskbar to "associate" all instances of MyApp.exe with the shortcut starting MyLauncher.exe /lauch MyApp.exe .我希望 Windows 7 任务栏将MyApp.exe所有实例与启动MyLauncher.exe /lauch MyApp.exe的快捷方式“关联”。

Try playing around with the "App Ids" See here for more info: http://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx尝试使用“应用程序 ID” 请参阅此处了解更多信息: http : //msdn.microsoft.com/en-us/library/windows/desktop/dd378459( v=vs.85) .aspx

"Application User Model IDs (AppUserModelIDs) are used extensively by the taskbar in Windows 7 and later systems to associate processes, files, and windows with a particular application. In some cases, it is sufficient to rely on the internal AppUserModelID assigned to a process by the system. However, an application that owns multiple processes or an application that is running in a host process might need to explicitly identify itself so that it can group its otherwise disparate windows under a single taskbar button and control the contents of that application's Jump List ." “应用程序用户模型 ID (AppUserModelIDs) 被 Windows 7 和更高版本系统中的任务栏广泛使用,以将进程、文件和窗口与特定应用程序相关联。在某些情况下,依赖分配给进程的内部 AppUserModelID 就足够了但是,拥有多个进程的应用程序或在主机进程中运行的应用程序可能需要明确标识自己,以便它可以将其不同的窗口分组到单个任务栏按钮下,并控制该应用程序跳转的内容清单。”

It was already mentioned to set the Application user Model ID.已经提到设置应用程序用户模型 ID。 How this is done could be easily seen in this post: How to group different apps in Windows task bar?在这篇文章中可以很容易地看到这是如何完成的:如何在 Windows 任务栏中对不同的应用程序进行分组?

But then you still have the problem that when the Application is pinned, it will not pin the Launcher.但是你仍然有问题,当应用程序被固定时,它不会固定启动器。 But there is also a solution for this, that the Launcher is pinned instead: Pinning to the taskbar a "chained process"但也有一个解决方案,即固定启动器:将一个“链式进程”固定到任务栏

One thing you can do is not show the task-bar icon for the application at all.您可以做的一件事就是根本不显示应用程序的任务栏图标。 In WPF it's as simple as a property setting:在 WPF 中,它就像属性设置一样简单:

ShowInTaskbar="False"

The problem with this approach is that it will reduce usability because the user can no longer tell when the application is running or easily bring it to the forefront when it gets lost behind other windows.这种方法的问题在于它会降低可用性,因为用户无法再知道应用程序何时运行,或者当它丢失在其他窗口后面时很容易将其带到最前面。 In order to alleviate some of these concerns, you can create a notify icon for this application which would enable some of these functions and also give the user some feedback as to the application's current state.为了减轻其中的一些顾虑,您可以为此应用程序创建一个通知图标,它可以启用其中的一些功能,并为用户提供有关应用程序当前状态的一些反馈。 (Running, not running, etc..) (运行,不运行等。)

This msdn resource has a good code sample on how to create notify icons in windows forms. 这个 msdn 资源有一个关于如何在 Windows 窗体中创建通知图标的很好的代码示例。 You can use the same method for WPF applications as well.您也可以对 WPF 应用程序使用相同的方法。

在此处输入图片说明

SMALL TIP: Notify icons are 16x16 pixels.小提示:通知图标为 16x16 像素。 Try to find a vector version of the icon prior to resizing as this will give you crisper results because you tend to lose a lot of detail at that size.尝试在调整大小之前找到图标的矢量版本,因为这会给您带来更清晰的结果,因为在该尺寸下您往往会丢失很多细节。

Some user interaction with the notify-icon can include:一些用户与通知图标的交互可以包括:

  • Double-Click > Brings the application to the front双击 > 将应用程序置于最前面
  • Right-Click > Brings up a context menu with some choices.右键单击 > 显示带有一些选项的上下文菜单。 (IE Bring to front, close, etc...) (IE 带到前面、关闭等...)
  • Mouse-Over > Brings up a tool-tip with some information regarding the application.鼠标悬停 > 显示包含有关应用程序的一些信息的工具提示。

1) 1)
This is more of an architectural question / problem - that's a bit of an unusual design for such purposes,这更像是一个架构问题/问题 - 出于此类目的,这是一个不寻常的设计,
ie if an updater (I'm guessing you have more but to start w/ that) is required that's usually checked within the app - then if update is deemed you start an outside process and update the app etc.即,如果需要更新程序(我猜你有更多但要开始),通常在应用程序中检查 - 那么如果更新被视为你启动一个外部进程并更新应用程序等。
Launcher (as described) would make sense if you are launching many different things or you have a generic solution or in more complex cases - eg you have a 'host process' that loads dll-s, services etc.如果您要启动许多不同的东西,或者您有通用解决方案或更复杂的情况,启动器(如所述)会很有意义 - 例如,您有一个加载 dll-s、服务等的“主机进程”。
So basically you're running into problems because of a bit unfortunate design, decision - unless you have something that warrants that sufficiently.所以基本上你会因为一些不幸的设计和决定而遇到问题 - 除非你有足够的理由。
But having you said that you didn't wish to redesign...但是你说你不想重新设计......
2) 2)
You could still do a 'trick' with launcher - and make kind of a simple work around...你仍然可以用启动器做一个“把戏”——然后做一个简单的工作......

  • Launch the 'MyApp -argument:check' first (and have icon on desktop belong to it, not the launcher), and have an argument 'fork' on startup and if 'check' do a small 'shim' code which lauches the 'MyLauncher',首先启动'MyApp -argument:check'(桌面上的图标属于它,而不是启动器),并在启动时有一个参数'fork',如果'check'做一个小的'shim'代码来启动'我的启动器',
  • get the launcher to do what it's supposed to be doing - you can even close the main MyApp after launching,让启动器做它应该做的事情——你甚至可以在启动后关闭主 MyApp,
  • when launcher is done it launches the MyApp again (or more complex to close if left only if update is needed etc. - but the previous is easier), and use some other argument or don't use any (depends on what you want etc.),当启动器完成后,它会再次启动 MyApp(或者更复杂的关闭如果只在需要更新时才离开等等 - 但前一个更容易),并使用其他一些参数或不使用任何参数(取决于你想要什么等) .),
  • You're doing some process double redirection of a sort - start app => launcher => app again,您正在执行某种流程双重重定向 - 再次启动应用程序 => 启动器 => 应用程序,
  • you should have no problems with the icons this way,这样你的图标应该没有问题,
  • with all this you should be careful about supplying proper manifests to either app (most often the launcher which needs to update, more permissions) if an 'admin' mode is required, but I guess you have that already,有了所有这些,如果需要“管理员”模式,您应该小心为任一应用程序(通常是需要更新的启动器,更多权限)提供适当的清单,但我想您已经拥有了,

that might do the trick, haven't tried but I don't see why it shouldn't - and you can keep the existing architecture in place etc.这可能会奏效,还没有尝试过,但我不明白为什么不应该这样做 - 您可以保留现有架构等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM