aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Engine/Misc/Tools.cs
blob: 6430084173a0a9c80bd7d76cb8eff814c642c68a (plain) (blame)
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
using System;
using System.Drawing;
using System.Runtime.InteropServices;

namespace ShiftOS.Engine.Misc
{
	/// <summary>
	///     Random class full of unassorted [but also uncategorizable] tools.
	/// </summary>
	public static class Tools
	{
		public static Random Rnd = new Random();

		[DllImport("user32.dll", CharSet = CharSet.Auto)]
		public static extern bool DestroyIcon(IntPtr handle);

		public static Icon ToIcon(this Bitmap bm)
		{
			var tempicon = Icon.FromHandle(bm.GetHicon());

			var newIcon = tempicon.Clone() as Icon;

			//for some reason this exists
			DestroyIcon(tempicon.Handle);

			return newIcon;
		}
	}
}