forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Global.Windows.cs
67 lines (55 loc) · 2.28 KB
/
Global.Windows.cs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using Eto.Drawing;
using Eto.Wpf.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Media.Imaging;
namespace MonoGame.Tools.Pipeline
{
static partial class Global
{
[DllImport("Shell32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
private static extern int ExtractIconExW(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons);
private static void PlatformInit()
{
var file = ExtractIcon(0).ToBitmap();
var fileMissing = ExtractIcon(271).ToBitmap();
var folder = ExtractIcon(4).ToBitmap();
var folderMissing = ExtractIcon(234).ToBitmap();
_files["."] = ToEtoImage(file);
_fileMissing = ToEtoImage(fileMissing);
_folder = ToEtoImage(folder);
_folderMissing = ToEtoImage(folderMissing);
}
public static System.Drawing.Icon ExtractIcon(int number)
{
IntPtr large;
IntPtr small;
ExtractIconExW("shell32.dll", number, out large, out small, 1);
return System.Drawing.Icon.FromHandle(large);
}
private static System.Drawing.Bitmap PlatformGetFileIcon(string path)
{
return System.Drawing.Icon.ExtractAssociatedIcon(path).ToBitmap();
}
private static Bitmap ToEtoImage(System.Drawing.Bitmap bitmap)
{
var ret = new BitmapImage();
using (MemoryStream stream = new MemoryStream())
{
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Position = 0;
ret.BeginInit();
ret.DecodePixelHeight = 16;
ret.DecodePixelWidth = 16;
ret.StreamSource = stream;
ret.CacheOption = BitmapCacheOption.OnLoad;
ret.EndInit();
}
return new Bitmap(new BitmapHandler(ret));
}
}
}