[DllImport("user32.dll")]
static extern IntPtr CreateIconFromResource(byte[] presbits, uint dwResSize, bool fIcon, uint dwVer);
<DllImport("user32.dll")> _
Private Shared Function CreateIconFromResource(presbits As Byte(), dwResSize As UInteger, fIcon As Boolean, dwVer As UInteger) As IntPtr
End Function
None.
None.
Please add some!
Please add some!
Do you know one? Please contribute it!
// this is a previouslly released item
public class AdvancedCursors
{
[DllImport("User32.dll")]
private static extern IntPtr LoadCursorFromFile(String str);
public static Cursor Create(string filename)
{
IntPtr hCursor = LoadCursorFromFile(filename);
if (!IntPtr.Zero.Equals(hCursor))
{
return new Cursor(hCursor);
}
else
{
throw new ApplicationException("Could not create cursor from file " + filename);
}
}
}
// this is my modification to the code
I have tested this methode and it works great
public class AdvancedCursorsFromEmbededResources
{
// created by Yvan Genesse November 29 2010
// in your form code
/*
try
{
// from file
//this.Cursor = AdvancedCursors.Create(Path.Combine(Application.StartupPath, "flower_anim.ani"));
// from resouces
byte[] Embeded_Cursor_Resource = Properties.Resources.flower_anim; // the animate cursor desired from a resource
this.Cursor = AdvancedCursorsFromEmbededResources_1.Create(Embeded_Cursor_Resource);
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
[DllImport("user32.dll")]
static extern IntPtr CreateIconFromResource(byte[] presbits, uint dwResSize, bool fIcon, uint dwVer);
public static Cursor Create( byte[] resource)
{
IntPtr hCursor;
//byte[] resource = Properties.Resources.flower_anim;
hCursor = CreateIconFromResource(resource, (uint)resource.Length, false, 0x00030000);
if (!IntPtr.Zero.Equals(hCursor))
{
// all is good
return new Cursor(hCursor);
}
else
{ // resource dont exist or memory error ocurred
throw new ApplicationException("Could not create cursor from resource " + resource.ToString());
}
}
}