A game framework written with osu! in mind.
at master 54 lines 1.2 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5using System.Runtime.InteropServices; 6 7namespace osu.Framework.Platform.Windows.Native 8{ 9 internal class Icon : IDisposable 10 { 11 [DllImport("user32.dll", SetLastError = true)] 12 private static extern bool DestroyIcon(IntPtr hIcon); 13 14 private bool disposed; 15 16 public IntPtr Handle { get; private set; } 17 18 public readonly int Width; 19 20 public readonly int Height; 21 22 internal Icon(IntPtr handle, int width, int height) 23 { 24 Handle = handle; 25 Width = width; 26 Height = height; 27 } 28 29 ~Icon() 30 { 31 Dispose(false); 32 } 33 34 protected virtual void Dispose(bool disposing) 35 { 36 if (disposed) 37 return; 38 39 if (Handle != IntPtr.Zero) 40 { 41 DestroyIcon(Handle); 42 Handle = IntPtr.Zero; 43 } 44 45 disposed = true; 46 } 47 48 public void Dispose() 49 { 50 Dispose(true); 51 GC.SuppressFinalize(this); 52 } 53 } 54}