1

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?

Christian Rondeau
  • 4,143
  • 5
  • 28
  • 46

1 Answers1

1

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 (e.g. 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.

Community
  • 1
  • 1
  • Thanks! As for the AUMID ID, where can I find that? On the AppListEntry object? – Mathias Lykkegaard Lorenzen May 23 '18 at 19:08
  • Also, when I call `FindPackageForUser(string.Empty, process.MainModule.ModuleName)` it returns `null`. Any ideas on how to solve that? – Mathias Lykkegaard Lorenzen May 24 '18 at 16:26
  • process.MainModule.ModuleName = C# System.Diagnostics.Process.MainModule.ModuleName, the C# equivalent of GetModuleFileName. You're calling FindPackageForUser with that as the packageFullName (should fail due to E_INVALIDARG but may merely not find matches and return an empty list). [AppListEntry](https://learn.microsoft.com/en-us/uwp/api/Windows.ApplicationModel.Core.AppListEntry) gained a AppUserModelId property in 1709 making it easier to distinguish amongst multiple apps in a package, if you don't need to run on older Windows. – Howard Kapustein Aug 15 '19 at 04:40