-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIcons.cs
More file actions
41 lines (36 loc) · 1.3 KB
/
Icons.cs
File metadata and controls
41 lines (36 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace PersonalFolder {
internal class Icons {
[DllImport("shell32", CharSet = CharSet.Unicode)]
private static extern int ExtractIconEx (
string lpszFile,
int nIconIndex,
IntPtr[] phIconLarge,
IntPtr[] phIconSmall,
int nIcons);
[DllImport("user32.dll", SetLastError = true)]
private static extern int DestroyIcon (IntPtr hIcon);
private static IntPtr GetHandle (string file, int index, bool isLarge) {
IntPtr[] phIconLarge = new IntPtr[1];
IntPtr[] phIconSmall = new IntPtr[1];
ExtractIconEx(file, index, phIconLarge, phIconSmall, 1);
return isLarge ? phIconLarge[0] : phIconSmall[0];
}
public static Icon GetSystemIcon (string file, int index, bool isLarge) {
try {
return Icon.FromHandle(GetHandle(file, index, isLarge));
} catch {
return null;
}
}
public static Bitmap GetSystemBitmap (string file, int index, bool isLarge) {
try {
return Bitmap.FromHicon(GetHandle(file, index, isLarge));
} catch {
return null;
}
}
}
}