简体   繁体   中英

How to get the Windows Store App icon from a hWnd?

I currently use the WM_GETICON message in a C# Windows application to get the icon associated with a hWnd , but it won't get me the icon for ApplicationFrameHost (Windows Store Apps) processes (which makes sense, since it hides the actual application).

Here is the code I currently use, which works for "normal" apps:

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);

public static IntPtr GetAppIcon(IntPtr hwnd)
{
    var iconHandle = SendMessage(hwnd, WM_GETICON, ICON_BIG, 0);
    if (iconHandle == IntPtr.Zero)
        iconHandle = SendMessage(hwnd, WM_GETICON, ICON_SMALL, 0);
    if (iconHandle == IntPtr.Zero)
        iconHandle = SendMessage(hwnd, WM_GETICON, ICON_SMALL2, 0);
        return iconHandle;
}

Getting the ApplicationFrameHost.exe icon won't help me here. It seems there is such an icon though, since a) I can see it in the task bar, and b) I can also see it in Task Manager.

How can I get this icon?

There's no good answer today.

You need to determine the application's identity. See your other post for more details => How to get the "Application Name" from hWnd for Windows 10 Store Apps (eg Edge)

Once you have that you can use PackageManager.FindPackage(pkgfullname) to get a Windows.ApplicationModel.Package and then use Package.GetAppListEntriesAsync to get a list of AppListEntry objects, 1 per application in the package. For each, use its .DisplayInfo.DisplayName, .Description and .GetLogo().

https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.package.getapplistentriesasync.aspx

Caveat: This poses problems for Multi-Application Packages (MAPs), as you'll have multiple applications in the package. You cannot directly query for the AppListEntry for an application, and you can't tell the application identity of an AppListEntry. You'll know the process has AUMID=1, but GetAppListEntriesAsync() could return a list of 4 values and you won't be able to determine which one you're looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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