/// <summary>
/// Gets the icon associated with the specified window
/// </summary>
/// <param name="winHandle">window handle</param>
/// <returns>the icon, null if it can't find one</returns>
public static Icon GetAppIcon(IntPtr winHandle)
{
Log.Debug("hWnd=" + winHandle);
IntPtr hIcon = User32Interop.SendMessage(winHandle, WM_GETICON, ICON_BIG, 0);
if (hIcon == IntPtr.Zero)
{
hIcon = User32Interop.SendMessage(winHandle, WM_GETICON, ICON_SMALL, 0);
if (hIcon == IntPtr.Zero)
{
hIcon = User32Interop.SendMessage(winHandle, WM_GETICON, ICON_SMALL2, 0);
if (hIcon == IntPtr.Zero)
{
hIcon = getClassLongPtr(winHandle, GCL_HICON);
if (hIcon == IntPtr.Zero)
{
hIcon = getClassLongPtr(winHandle, GCL_HICONSM);
if (hIcon == IntPtr.Zero)
{
return(null);
}
}
}
}
}
Icon icon = null;
if (hIcon != IntPtr.Zero)
{
icon = Icon.FromHandle(hIcon);
}
return(icon);
}