mirror of
https://github.com/ckaczor/Common.git
synced 2026-01-13 17:22:40 -05:00
Initial work on loading icon
This commit is contained in:
@@ -118,12 +118,14 @@
|
|||||||
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="PresentationCore" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.configuration" />
|
<Reference Include="System.configuration" />
|
||||||
<Reference Include="System.Core">
|
<Reference Include="System.Core">
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.IO">
|
<Reference Include="System.IO">
|
||||||
<HintPath>packages\Microsoft.Bcl.1.1.8\lib\net40\System.IO.dll</HintPath>
|
<HintPath>packages\Microsoft.Bcl.1.1.8\lib\net40\System.IO.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
@@ -136,6 +138,7 @@
|
|||||||
<HintPath>packages\Microsoft.Bcl.1.1.8\lib\net40\System.Threading.Tasks.dll</HintPath>
|
<HintPath>packages\Microsoft.Bcl.1.1.8\lib\net40\System.Threading.Tasks.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
|
<Reference Include="System.Xaml" />
|
||||||
<Reference Include="System.XML" />
|
<Reference Include="System.XML" />
|
||||||
<Reference Include="WindowsBase" />
|
<Reference Include="WindowsBase" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -2,15 +2,44 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Interop;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
namespace Common.Internet
|
namespace Common.Internet
|
||||||
{
|
{
|
||||||
public class Browser
|
public class Browser
|
||||||
{
|
{
|
||||||
|
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
|
||||||
|
static extern uint ExtractIconEx(string szFileName, int nIconIndex, IntPtr[] phiconLarge, IntPtr[] phiconSmall, uint nIcons);
|
||||||
|
|
||||||
public string Key { get; private set; }
|
public string Key { get; private set; }
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
public string Command { get; private set; }
|
public string Command { get; private set; }
|
||||||
public string DefaultIcon { get; private set; }
|
public string DefaultIcon { get; private set; }
|
||||||
|
public ImageSource DefaultImage { get; private set; }
|
||||||
|
|
||||||
|
public void LoadImage()
|
||||||
|
{
|
||||||
|
var parts = DefaultIcon.Split(',');
|
||||||
|
var index = int.Parse(parts[1]);
|
||||||
|
|
||||||
|
var large = new IntPtr[1];
|
||||||
|
var small = new IntPtr[1];
|
||||||
|
ExtractIconEx(parts[0], index, large, small, 1);
|
||||||
|
|
||||||
|
Icon img = Icon.FromHandle(small[0]);
|
||||||
|
|
||||||
|
Bitmap bitmap = img.ToBitmap();
|
||||||
|
IntPtr hBitmap = bitmap.GetHbitmap();
|
||||||
|
|
||||||
|
ImageSource wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
|
||||||
|
|
||||||
|
DefaultImage = wpfBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
public bool SupportsPrivate()
|
public bool SupportsPrivate()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user