相关疑难解决方法(0)

从桌面应用程序获取"现代"Windows应用程序的图标?

我开发了一个函数,它返回给定窗口句柄的窗口图标.看起来像这样.

private static BitmapSource GetWindowIcon(IntPtr windowHandle)
{
    var hIcon = default(IntPtr);
    hIcon = SendMessage(windowHandle, WM_GETICON, ICON_BIG, IntPtr.Zero);

    if (hIcon == IntPtr.Zero)
        hIcon = GetClassLongPtr(windowHandle, GCL_HICON);

    if (hIcon == IntPtr.Zero)
    {
        hIcon = LoadIcon(IntPtr.Zero, (IntPtr)0x7F00/*IDI_APPLICATION*/);
    }

    if (hIcon != IntPtr.Zero)
    {
        return Imaging.CreateBitmapSourceFromHIcon(hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
    } else {
        throw new InvalidOperationException("Could not load window icon.");
    }
}
Run Code Online (Sandbox Code Playgroud)

我结合使用此功能GetForegroundWindow来获取活动窗口的图标.

但是,它似乎为通用应用程序产生了相同的暗淡图标.

是否有可能以某种方式从正在运行的通用应用程序中获取平铺图像或图标?

c# wpf pinvoke icons windows-store-apps

10
推荐指数
2
解决办法
2148
查看次数

标签 统计

c# ×1

icons ×1

pinvoke ×1

windows-store-apps ×1

wpf ×1