[Win] Fixed MouseCursor.Default

It is now possible to switch from a custom cursor back to
MouseCursor.Default.
This commit is contained in:
thefiddler 2014-04-28 09:37:16 +02:00
parent 4f9a2f78d6
commit 509f356ed4

View file

@ -1202,6 +1202,16 @@ namespace OpenTK.Platform.Windows
set
{
if (value != cursor)
{
bool destoryOld = cursor != MouseCursor.Default;
IntPtr oldCursor = IntPtr.Zero;
if (value == MouseCursor.Default)
{
oldCursor = Functions.SetCursor(Functions.LoadCursor(CursorName.Arrow));
cursor = value;
}
else
{
var stride = value.Width *
(Bitmap.GetPixelFormatSize(System.Drawing.Imaging.PixelFormat.Format32bppArgb) / 8);
@ -1216,7 +1226,8 @@ namespace OpenTK.Platform.Windows
new IntPtr(pixels));
}
}
using (bmp)
{
var iconInfo = new IconInfo();
var bmpIcon = bmp.GetHicon();
var success = Functions.GetIconInfo(bmpIcon, out iconInfo);
@ -1233,21 +1244,21 @@ namespace OpenTK.Platform.Windows
{
// Currently using a custom cursor so destroy it
// once replaced
bool destoryOld = cursor != MouseCursor.Default;
cursor = value;
curson_handle = icon;
var oldCursor = Functions.SetCursor(icon);
oldCursor = Functions.SetCursor(icon);
}
}
}
}
if (destoryOld)
if (destoryOld && oldCursor != IntPtr.Zero)
{
Functions.DestroyIcon(oldCursor);
}
}
}
}
}
}
#endregion