프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / SmartUpdate / IconManager.cs @ f65e6c02

이력 | 보기 | 이력해설 | 다운로드 (3.19 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Drawing;
6
using System.Runtime.InteropServices;
7
using System.Windows.Media;
8
using System.Windows;
9
using System.Windows.Media.Imaging;
10

    
11
public class IconManager
12
{
13
    public static ImageSource GetIcon(string path, bool smallIcon, bool isDirectory)
14
    {
15
        uint flags = SHGFI_ICON | SHGFI_USEFILEATTRIBUTES;
16
        if (smallIcon)
17
            flags |= SHGFI_SMALLICON;
18

    
19
        uint attributes = FILE_ATTRIBUTE_NORMAL;
20
        if (isDirectory)
21
            attributes |= FILE_ATTRIBUTE_DIRECTORY;
22

    
23
        SHFILEINFO shfi;
24
        if (0 != SHGetFileInfo(path, attributes, out shfi, (uint)Marshal.SizeOf(typeof(SHFILEINFO)), flags))
25
        {
26
            return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(shfi.hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
27
        }
28
        return null;
29
    }
30

    
31
    [StructLayout(LayoutKind.Sequential)]
32
    private struct SHFILEINFO
33
    {
34
        public IntPtr hIcon;
35
        public int iIcon;
36
        public uint dwAttributes;
37
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
38
        public string szDisplayName;
39
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
40
        public string szTypeName;
41
    }
42

    
43
    [DllImport("shell32")]
44
    private static extern int SHGetFileInfo(string pszPath, uint dwFileAttributes, out SHFILEINFO psfi, uint cbFileInfo, uint flags);
45

    
46
    private const uint FILE_ATTRIBUTE_READONLY = 0x00000001;
47
    private const uint FILE_ATTRIBUTE_HIDDEN = 0x00000002;
48
    private const uint FILE_ATTRIBUTE_SYSTEM = 0x00000004;
49
    private const uint FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
50
    private const uint FILE_ATTRIBUTE_ARCHIVE = 0x00000020;
51
    private const uint FILE_ATTRIBUTE_DEVICE = 0x00000040;
52
    private const uint FILE_ATTRIBUTE_NORMAL = 0x00000080;
53
    private const uint FILE_ATTRIBUTE_TEMPORARY = 0x00000100;
54
    private const uint FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200;
55
    private const uint FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400;
56
    private const uint FILE_ATTRIBUTE_COMPRESSED = 0x00000800;
57
    private const uint FILE_ATTRIBUTE_OFFLINE = 0x00001000;
58
    private const uint FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000;
59
    private const uint FILE_ATTRIBUTE_ENCRYPTED = 0x00004000;
60
    private const uint FILE_ATTRIBUTE_VIRTUAL = 0x00010000;
61

    
62
    private const uint SHGFI_ICON = 0x000000100;
63
    private const uint SHGFI_DISPLAYNAME = 0x000000200;
64
    private const uint SHGFI_TYPENAME = 0x000000400;
65
    private const uint SHGFI_ATTRIBUTES = 0x000000800;
66
    private const uint SHGFI_ICONLOCATION = 0x000001000;
67
    private const uint SHGFI_EXETYPE = 0x000002000;
68
    private const uint SHGFI_SYSICONINDEX = 0x000004000;
69
    private const uint SHGFI_LINKOVERLAY = 0x000008000;
70
    private const uint SHGFI_SELECTED = 0x000010000;
71
    private const uint SHGFI_ATTR_SPECIFIED = 0x000020000;
72
    private const uint SHGFI_LARGEICON = 0x000000000;
73
    private const uint SHGFI_SMALLICON = 0x000000001;
74
    private const uint SHGFI_OPENICON = 0x000000002;
75
    private const uint SHGFI_SHELLICONSIZE = 0x000000004;
76
    private const uint SHGFI_PIDL = 0x000000008;
77
    private const uint SHGFI_USEFILEATTRIBUTES = 0x000000010;
78
}
클립보드 이미지 추가 (최대 크기: 500 MB)