Skip to content

Commit

Permalink
Adding support extract icon from modern app (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
shibayan authored Jul 7, 2021
1 parent c17027c commit b851ff8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 10 additions & 0 deletions WinQuickLook/Internal/AssocHandlerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public static IList<AssocAppEntry> GetAssocAppList(string fileName)

NativeMethods.DestroyIcon(icons[0]);
}
else if (location.StartsWith("@"))
{
var iconPathBuffer = new StringBuilder(1024);

NativeMethods.SHLoadIndirectString(location, iconPathBuffer, iconPathBuffer.Capacity, IntPtr.Zero);

var iconPath = iconPathBuffer.ToString();

icon = File.Exists(iconPath) ? new BitmapImage(new Uri(iconPath)) : null;
}
else
{
icon = null;
Expand Down
10 changes: 5 additions & 5 deletions WinQuickLook/Interop/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,17 @@ public static extern void SHCreateItemFromParsingName([In, MarshalAs(UnmanagedTy
[DllImport("shlwapi.dll")]
public static extern void StrRetToBSTR([In, Out] ref STRRET pstr, [In] IntPtr pidl, [Out, MarshalAs(UnmanagedType.BStr)] out string pbstr);

[DllImport("shlwapi.dll")]
public static extern int SHLoadIndirectString([In, MarshalAs(UnmanagedType.LPWStr)] string pszSource, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszOutBuf, int cchOuutBuf, IntPtr ppvReserved);

[DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(IntPtr hwnd, IntPtr lpdwProcessId);

[DllImport("user32.dll")]
public static extern uint GetGUIThreadInfo(uint dwthreadid, ref GUITHREADINFO lpguithreadinfo);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
public static extern int GetClassName(IntPtr hWnd, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpClassName, int nMaxCount);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
Expand All @@ -74,10 +77,7 @@ public static extern void SHCreateItemFromParsingName([In, MarshalAs(UnmanagedTy
public static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WINCOMPATTRDATA data);

[DllImport("shlwapi.dll", CharSet = CharSet.Auto)]
public static extern uint AssocQueryString(ASSOCF flags, ASSOCSTR str, string pszAssoc, string pszExtra, [Out] StringBuilder pszOut, [In, Out] ref int pcchOut);

[DllImport("dwmapi.dll")]
public static extern int DwmGetColorizationColor([Out] out uint pcrColorization, [Out] out bool pfOpaqueBlend);
public static extern uint AssocQueryString(ASSOCF flags, ASSOCSTR str, string pszAssoc, string pszExtra, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder pszOut, [In, Out] ref int pcchOut);

[DllImport("dwmapi.dll")]
public static extern int DwmIsCompositionEnabled(out bool pfEnabled);
Expand Down

0 comments on commit b851ff8

Please sign in to comment.