|
// ****************************************************************************
// Copyright Swordfish Computing Australia 2006 **
// http://www.swordfish.com.au/ **
// **
// Filename: Swordfish.WPF.Charts\WPFCursorFromBitmap.cs **
// Authored by: John Stewien of Swordfish Computing **
// Date: April 2006 **
// **
// - Change Log - **
//*****************************************************************************
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Swordfish.WPF.Charts
{
/// <summary>
/// This class converts a win32 bitmap to a WPF Cursor
/// </summary>
public class WPFCursorFromBitmap : SafeHandle
{
// ********************************************************************
// Methods
// ********************************************************************
#region Methods
/// <summary>
/// Creates a WPF cursor from a win32 bitmap
/// </summary>
/// <param name="cursorBitmap"></param>
/// <returns></returns>
public static System.Windows.Input.Cursor CreateCursor(System.Drawing.Bitmap cursorBitmap)
{
WPFCursorFromBitmap csh = new WPFCursorFromBitmap(cursorBitmap);
return System.Windows.Interop.CursorInteropHelper.Create(csh);
}
/// <summary>
/// Hidden contructor. Accessed only from the static method.
/// </summary>
/// <param name="cursorBitmap"></param>
protected WPFCursorFromBitmap(System.Drawing.Bitmap cursorBitmap)
: base((IntPtr)(-1), true)
{
handle = cursorBitmap.GetHicon();
}
/// <summary>
/// Releases the bitmap handle
/// </summary>
/// <returns></returns>
protected override bool ReleaseHandle()
{
bool result = DestroyIcon(handle);
handle = (IntPtr)(-1);
return result;
}
/// <summary>
/// Imported from user32.dll. Destroys an icon GDI object.
/// </summary>
/// <param name="hIcon"></param>
/// <returns></returns>
[System.Runtime.InteropServices.DllImport("user32")]
private static extern bool DestroyIcon(IntPtr hIcon);
#endregion Methods
// ********************************************************************
// Properties
// ********************************************************************
#region Properties
/// <summary>
/// Gets if the handle is valid or not
/// </summary>
public override bool IsInvalid
{
get
{
return handle == (IntPtr)(-1);
}
}
#endregion Properties
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
John graduated from the University of South Australia in 1997 with a Bachelor of Electronic Engineering Degree, and since then he has worked on hardware and software in many fields including Aerospace, Defence, and Medical giving him over 10 of years experience in C++ and C# programming. In 2009 John Started his own contracting company doing business between Taiwan and Australia.