如何使用 vc++ 为 windows 7/8 中的任何应用程序获取 appUserModelId [英] How to get appUserModelId for any app in windows 7/8 using vc++

查看:30
本文介绍了如何使用 vc++ 为 windows 7/8 中的任何应用程序获取 appUserModelId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从任何应用的跳转列表中找出最近/常用的项目.我知道我们可以使用 IApplicationDocumentLists 接口来做到这一点.但是我们需要 appUserModelId 为此.所以现在我的问题是找出任何应用程序的 appUserModelId,给定它的 exe 路径.任何帮助将不胜感激.

I want to find out recent/frequent items from jumplist of any app. I know that we can do this using IApplicationDocumentLists interface. But we need appUserModelId for that. So now my problem is to find out appUserModelId for any app, given its exe path. Any help will be highly appreciated.

推荐答案

AppUserModeIDs 不是 EXE 文件本身的一部分,因此只有 EXE 文件的路径是不够的.AppUserModeID 在 EXE 运行时分配,它们可以在进程范围或每个窗口的基础上分配.

AppUserModeIDs are not part of the EXE file itself, so it is not enough to just have the path to the EXE file. AppUserModeIDs are assigned while the EXE is running, and they can be assigned on process-wide or per-window basis.

要查询进程的显式 AppUserModeID,您必须将代码注入该进程并让它调用GetCurrentProcessExplicitAppUserModelID(),然后使用 IPC 机制将值发送回您的主应用程序.

To query a process's explicit AppUserModeID, you would have to inject code into that process and have it call GetCurrentProcessExplicitAppUserModelID(), then use an IPC mechanism to send the value back to your main app.

要查询窗口的显式 AppUserModeID,可以使用SHGetPropertyStoreForWindow() 获取窗口的 IPropertyStore 接口,然后调用 IPropertyStore.GetValue() 指定 PKEY_AppUserModel_ID 作为属性键.

To query a window's explicit AppUserModeID, you can use SHGetPropertyStoreForWindow() to get the window's IPropertyStore interface, and then call IPropertyStore.GetValue() specifying PKEY_AppUserModel_ID as the property key.

请注意,无论哪种情况,这些函数都只适用于显式 AppUserModeID.如果应用程序没有为自己分配显式 AppUserModeID,则它们不适用于由 Windows 分配的隐式 AppUserModeID.文档中明确说明了这一点:

Note that in either case, these functions only work for explicit AppUserModeIDs. They do not work for implicit AppUserModeIDs that are assigned by Windows if an app does not assign an explicit AppUserModeID for itself. This is clearly stated in the documentation:

应用程序用户模型 ID (AppUserModelID)

某些应用程序未声明明确的 AppUserModelID.它们是可选的.在这种情况下,系统会使用一系列启发式方法来分配内部 AppUserModelID.但是,避免这些计算会带来性能优势,而显式 AppUserModelID 是保证准确用户体验的唯一方法.因此,强烈建议设置显式 ID.应用程序无法检索系统分配的 AppUserModelID.

Some applications do not declare an explicit AppUserModelID. They are optional. In that case, the system uses a series of heuristics to assign an internal AppUserModelID. However, there is a performance benefit in avoiding those calculations and an explicit AppUserModelID is the only way to guarantee an exact user experience. Therefore, it is strongly recommended that an explicit ID be set. Applications cannot retrieve a system-assigned AppUserModelID.

更新:在 Windows 8 中,微软添加了一个新的 GetApplicationUserModelId() 函数:

Update: in Windows 8, Microsoft added a new GetApplicationUserModelId() function:

获取应用程序用户模型 ID 用于指定进程.

Gets the application user model ID for the specified process.

您可以使用它而不是注入代码来调用 GetCurrentProcessExplicitAppUserModelID().我还没有尝试过,但我怀疑它会返回当前的 AppUserModeID,而不管它是如何分配的(显式分配或系统分配).

You can use that instead of injecting code to call GetCurrentProcessExplicitAppUserModelID(). I have not tried it yet, but I suspect it returns the current AppUserModeID regardless of how it is assigned (explicit or system-assigned).

这篇关于如何使用 vc++ 为 windows 7/8 中的任何应用程序获取 appUserModelId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆