Skip to content

Commit

Permalink
Add API to get Windows stock icons. (#8878)
Browse files Browse the repository at this point in the history
Fixes: #8802
  • Loading branch information
JeremyKuhne committed Mar 21, 2023
1 parent c06af78 commit 05914bc
Show file tree
Hide file tree
Showing 7 changed files with 634 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Shell32
{
#if NET8_0_OR_GREATER
internal const uint SHGSI_ICON = 0x000000100;

[LibraryImport(Libraries.Shell32)]
internal static partial HRESULT SHGetStockIconInfo(
uint siid,
uint uFlags,
ref SHSTOCKICONINFO psii);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal unsafe struct SHSTOCKICONINFO
{
public uint cbSize;
public nint hIcon;
public int iSysImageIndex;
public int iIcon;
public fixed char szPath[260];
}
#endif
}
}
29 changes: 12 additions & 17 deletions src/System.Drawing.Common/src/System.Drawing.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCurrent);$(NetPrevious);$(NetMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<TargetFramework />
Expand Down Expand Up @@ -210,6 +210,8 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con
<Compile Include="System\Drawing\Printing\PrintPreviewGraphics.cs" />
<Compile Include="System\Drawing\Printing\TriState.cs" />
<Compile Include="System\Drawing\ScreenDC.cs" />
<Compile Include="System\Drawing\StockIconId.cs" />
<Compile Include="System\Drawing\StockIconOptions.cs" />
<Compile Include="System\Drawing\SystemIcons.cs" />
<Compile Include="System\Drawing\ToolboxBitmapAttribute.cs" />

Expand Down Expand Up @@ -275,6 +277,7 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con
<Compile Include="Interop\Windows\Ole32\Interop.STATFLAG.cs" />
<Compile Include="Interop\Windows\Ole32\Interop.STGM.cs" />
<Compile Include="Interop\Windows\Shell32\Interop.ExtractAssociatedIcon.cs" />
<Compile Include="Interop\Windows\Shell32\Interop.SHGetStockIconInfo.cs" />
<Compile Include="Interop\Windows\User32\Interop.CopyImage.cs" />
<Compile Include="Interop\Windows\User32\Interop.CreateIconFromResourceEx.cs" />
<Compile Include="Interop\Windows\User32\Interop.DestroyIcon.cs" />
Expand All @@ -293,24 +296,18 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con
<Compile Include="Interop\Windows\Winspool\Interop.EnumPrinters.cs" />
<Compile Include="Interop\Windows\Interop.HRESULT.cs" />

<Compile Include="..\..\Common\src\LocalAppContextSwitches.Common.cs"
Link="System\LocalAppContextSwitches.Common.cs" />
<Compile Include="..\..\Common\src\ValueStringBuilder.cs"
Link="System\Text\ValueStringBuilder.cs" />
<Compile Include="..\..\Common\src\LocalAppContextSwitches.Common.cs" Link="System\LocalAppContextSwitches.Common.cs" />
<Compile Include="..\..\Common\src\ValueStringBuilder.cs" Link="System\Text\ValueStringBuilder.cs" />


<EmbeddedResource Include="Resources\System\Drawing\DefaultComponent.bmp"
LogicalName="System.Drawing.DefaultComponent.bmp" />
<EmbeddedResource Include="Resources\System\Drawing\DefaultComponent.bmp" LogicalName="System.Drawing.DefaultComponent.bmp" />
<EmbeddedResource Include="Resources\System\Drawing\Printing\PrintDocument.bmp" />
<EmbeddedResource Include="Resources\System\Drawing\ShieldIcon.ico"
LogicalName="System.Drawing.ShieldIcon.ico" />
<EmbeddedResource Include="Resources\System\Drawing\ShieldIcon.ico" LogicalName="System.Drawing.ShieldIcon.ico" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
<Compile Include="..\..\Common\src\DisableRuntimeMarshalling.cs"
Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="..\..\Common\src\HandleRefMarshaller.cs"
Link="Common\HandleRefMarshaller.cs" />
<Compile Include="..\..\Common\src\DisableRuntimeMarshalling.cs" Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="..\..\Common\src\HandleRefMarshaller.cs" Link="Common\HandleRefMarshaller.cs" />
<Compile Include="System\Drawing\GdiplusNative.cs" />
</ItemGroup>

Expand All @@ -328,10 +325,8 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<Compile Include="..\..\Common\src\RequiresUnreferencedCodeAttribute.cs"
Link="Common\RequiresUnreferencedCodeAttribute.cs" />
<Compile Include="..\..\Common\src\UnconditionalSuppressMessageAttribute.cs"
Link="Common\UnconditionalSuppressMessageAttribute.cs" />
<Compile Include="..\..\Common\src\RequiresUnreferencedCodeAttribute.cs" Link="Common\RequiresUnreferencedCodeAttribute.cs" />
<Compile Include="..\..\Common\src\UnconditionalSuppressMessageAttribute.cs" Link="Common\UnconditionalSuppressMessageAttribute.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Drawing.Drawing2D;
Expand Down
Loading

0 comments on commit 05914bc

Please sign in to comment.