- 1 year ago
Get Windows 10 Jump List pin button icons
To obtain the icons for the pin button in Windows 10 Jump Lists, you can use the Windows API and the Shell32.dll library. Here's an example of how you can retrieve the pin button icons using C#:
csharpusing System;
using System.Drawing;
using System.Runtime.InteropServices;
public class JumpListPinButtonIcons
{
private const int SHGFI_ICON = 0x000000100; // Get icon
private const int SHGFI_SMALLICON = 0x000000001; // Get small icon
private const int SHGFI_LARGEICON = 0x000000000; // Get large icon
[DllImport("shell32.dll")]
private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, out SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
private struct SHFILEINFO
{
public IntPtr hIcon;
public int iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
}
public static Icon GetSmallPinIcon()
{
SHFILEINFO shfi = new SHFILEINFO();
IntPtr hIcon = SHGetFileInfo("shell32.dll", 0, out shfi, (uint)Marshal.SizeOf(shfi), SHGFI_ICON | SHGFI_SMALLICON);
return Icon.FromHandle(shfi.hIcon);
}
public static Icon GetLargePinIcon()
{
SHFILEINFO shfi = new SHFILEINFO();
IntPtr hIcon = SHGetFileInfo("shell32.dll", 0, out shfi, (uint)Marshal.SizeOf(shfi), SHGFI_ICON | SHGFI_LARGEICON);
return Icon.FromHandle(shfi.hIcon);
}
public static void Main()
{
Icon smallPinIcon = GetSmallPinIcon();
Icon largePinIcon = GetLargePinIcon();
// Use the icons as needed
Console.WriteLine("Small Pin Icon Size: " + smallPinIcon.Size);
Console.WriteLine("Large Pin Icon Size: " + largePinIcon.Size);
// Remember to dispose of the icons when you're done using them
smallPinIcon.Dispose();
largePinIcon.Dispose();
}
}
In this example, the SHGetFileInfo
function from Shell32.dll is used to retrieve the small and large pin icons. The SHGFI_ICON
flag is used to request the icons, and the SHGFI_SMALLICON
and SHGFI_LARGEICON
flags are used to specify the desired icon sizes.
Note that the GetSmallPinIcon
and GetLargePinIcon
methods return System.Drawing.Icon
objects, which can be used to display or manipulate the icons in your application. Make sure to dispose of the icons properly when you're done using them to release system resources.
Remember to add a reference to System.Drawing
and import the necessary namespaces (System
, System.Drawing
, and System.Runtime.InteropServices
) in your C# code.
This example retrieves the pin icons from the shell32.dll
file, which is where the system icons are stored. You can adjust the file path or use other system files to obtain different icons if desired.