-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize attachments to allow any file type.
Fixes issue #115
- Loading branch information
Showing
9 changed files
with
260 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Forms; | ||
using System.Windows.Interop; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using Walkabout.Utilities; | ||
|
||
namespace Walkabout.Utilities | ||
{ | ||
internal class FileIcons | ||
{ | ||
private const uint SHGFI_ICON = 0x100; | ||
private const uint SHGFI_LARGEICON = 0x0; | ||
private const uint SHGFI_SMALLICON = 0x1; | ||
private const int FILE_ATTRIBUTE_NORMAL = 0x80; | ||
private const uint SHGFI_USEFILEATTRIBUTES = 0x000000010; | ||
[StructLayout(LayoutKind.Sequential)] | ||
private struct SHFILEINFO | ||
{ | ||
public IntPtr hIcon; | ||
public IntPtr iIcon; | ||
public uint dwAttributes; | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] | ||
public string szDisplayName; | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] | ||
public string szTypeName; | ||
}; | ||
|
||
[DllImport("shell32.dll")] | ||
private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags); | ||
|
||
[DllImport("User32.dll")] | ||
public static extern int DestroyIcon(IntPtr hIcon); | ||
|
||
|
||
public static ImageSource Extract(string fileName) | ||
{ | ||
var shinfo = new SHFILEINFO(); | ||
|
||
SHGetFileInfo(fileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_LARGEICON); | ||
//The icon is returned in the hIcon member of the shinfo struct | ||
var imageSource = Imaging.CreateBitmapSourceFromHIcon( | ||
shinfo.hIcon, | ||
Int32Rect.Empty, | ||
BitmapSizeOptions.FromEmptyOptions()); | ||
|
||
DestroyIcon(shinfo.hIcon); | ||
return imageSource; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.1.0.21 | ||
2.1.0.22 |
Oops, something went wrong.