我开发了一个函数,它返回给定窗口句柄的窗口图标.看起来像这样.
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来获取活动窗口的图标.
但是,它似乎为通用应用程序产生了相同的暗淡图标.
是否有可能以某种方式从正在运行的通用应用程序中获取平铺图像或图标?