aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Engine/Tools.cs
blob: 792ccefe8a50d469e9789ea4a94669df2c065e06 (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
30
31
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;

namespace ShiftOS.Engine
{
	/// <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 extern static bool DestroyIcon(IntPtr handle);

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

			Icon newIcon = tempicon.Clone() as Icon;

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

			return newIcon;
		}
	}
}