473,387 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Failure to load custom cursor resource


Hi,

I am trying to load a custom cursor from my programs resources.
I have successfully included the cursor resource, and I have confirmed
that the name I am using is correct.

Below is the code I am using to try and load the cursor - which always
returns null.

I have tried using LoadImage and LoadCursor with the same result.

Can anyone see what I cant?

public static Cursor LoadCursor (string CursorName)
{
Cursor myCursor = null;
String Name;
IntPtr HCursor=IntPtr.Zero, HInst=IntPtr.Zero;

//Name = "Prologic." + CursorName + ".CUR";
Name = "ProLogic.Cursors.IRON.CUR";

HInst = Win32.GetModuleHandleW(null);

HCursor = Win32.LoadImage(HInst, Name, Win32.IMAGE_CURSOR, 0, 0,
Win32.LR_DEFAULTCOLOR | Win32.LR_DEFAULTSIZE | Win32.LR_SHARED);
//HCursor = Win32.LoadCursor (HInst, Name);
if (HCursor.ToInt32() > 0)
myCursor = new Cursor (HCursor);

return (myCursor);
}
}

/// <author>Shrijeet Nair</author>
public class Win32
{
public const uint IMAGE_BITMAP = 0;
public const uint IMAGE_ICON = 1;
public const uint IMAGE_CURSOR = 2;

public const uint LR_DEFAULTCOLOR = 0x0000;
public const uint LR_MONOCHROME = 0x0001;
public const uint LR_COLOR = 0x0002;
public const uint LR_COPYRETURNORG = 0x0004;
public const uint LR_COPYDELETEORG = 0x0008;
public const uint LR_LOADFROMFILE = 0x0010;
public const uint LR_LOADTRANSPARENT = 0x0020;
public const uint LR_DEFAULTSIZE = 0x0040;
public const uint LR_VGACOLOR = 0x0080;
public const uint LR_LOADMAP3DCOLORS = 0x1000;
public const uint LR_CREATEDIBSECTION = 0x2000;
public const uint LR_COPYFROMRESOURCE = 0x4000;
public const uint LR_SHARED = 0x8000;
[DllImport("User32.dll")]
public static extern IntPtr LoadImage(IntPtr hinst,

[MarshalAs(UnmanagedType.LPTStr)] string lpszName,
uint uType,
int cxDesired,
int cyDesired,
uint fuLoad);

[DllImport("User32.dll")]
public static extern IntPtr LoadCursor(IntPtr hinst,
[MarshalAs(UnmanagedType.LPTStr)] string lpszName);

[DllImport( "kernel32.dll" )]
public extern static IntPtr
GetModuleHandleW([MarshalAs(UnmanagedType.LPStr)] string lpModuleName );

}

Thanks for any help.

Paul
Nov 17 '05 #1
2 10578
Try something like this:
private void button1_Click(object sender, System.EventArgs e)
{
// Assumes that the assemblies default namespace is
CursorExampleXYZ and that
// the cursor file, JPGHANDX.cur, build action is set to Embedded
Resourse.
this.Cursor = new
Cursor(this.GetType().Assembly.GetManifestResource Stream(
"CursorExampleXYZ.JPGHANDX.cur"));
}

"Paul Cheetham" <PA******@dsl.pipex.com> wrote in message
news:Oj****************@TK2MSFTNGP11.phx.gbl...

Hi,

I am trying to load a custom cursor from my programs resources.
I have successfully included the cursor resource, and I have confirmed
that the name I am using is correct.

Below is the code I am using to try and load the cursor - which always
returns null.

I have tried using LoadImage and LoadCursor with the same result.

Can anyone see what I cant?

public static Cursor LoadCursor (string CursorName)
{
Cursor myCursor = null;
String Name;
IntPtr HCursor=IntPtr.Zero, HInst=IntPtr.Zero;

//Name = "Prologic." + CursorName + ".CUR";
Name = "ProLogic.Cursors.IRON.CUR";

HInst = Win32.GetModuleHandleW(null);

HCursor = Win32.LoadImage(HInst, Name, Win32.IMAGE_CURSOR, 0, 0,
Win32.LR_DEFAULTCOLOR | Win32.LR_DEFAULTSIZE | Win32.LR_SHARED);
//HCursor = Win32.LoadCursor (HInst, Name);
if (HCursor.ToInt32() > 0)
myCursor = new Cursor (HCursor);

return (myCursor);
}
}

/// <author>Shrijeet Nair</author>
public class Win32
{
public const uint IMAGE_BITMAP = 0;
public const uint IMAGE_ICON = 1;
public const uint IMAGE_CURSOR = 2;

public const uint LR_DEFAULTCOLOR = 0x0000;
public const uint LR_MONOCHROME = 0x0001;
public const uint LR_COLOR = 0x0002;
public const uint LR_COPYRETURNORG = 0x0004;
public const uint LR_COPYDELETEORG = 0x0008;
public const uint LR_LOADFROMFILE = 0x0010;
public const uint LR_LOADTRANSPARENT = 0x0020;
public const uint LR_DEFAULTSIZE = 0x0040;
public const uint LR_VGACOLOR = 0x0080;
public const uint LR_LOADMAP3DCOLORS = 0x1000;
public const uint LR_CREATEDIBSECTION = 0x2000;
public const uint LR_COPYFROMRESOURCE = 0x4000;
public const uint LR_SHARED = 0x8000;
[DllImport("User32.dll")]
public static extern IntPtr LoadImage(IntPtr hinst,

[MarshalAs(UnmanagedType.LPTStr)] string lpszName,
uint uType,
int cxDesired,
int cyDesired,
uint fuLoad);

[DllImport("User32.dll")]
public static extern IntPtr LoadCursor(IntPtr hinst,
[MarshalAs(UnmanagedType.LPTStr)] string lpszName);

[DllImport( "kernel32.dll" )]
public extern static IntPtr
GetModuleHandleW([MarshalAs(UnmanagedType.LPStr)] string lpModuleName );

}

Thanks for any help.

Paul

Nov 17 '05 #2

Hi,

Thanks for your reply.
Unfortunately that's the way I was doing it originally, but my cursor is
a colour cursor, and loading it that way creates a mono version of it,
since someone at Microsoft was a bit shortsighted when writing the
framework.
In order to get the colour cursor I need to load it from the resource
using the Win32 functions, and create an HCURSOR, which I can then use
in the cursor constructor to get the right result.

But it fails to load from the resource using the Win32 functions.
Paul
D. Yates wrote:
Try something like this:
private void button1_Click(object sender, System.EventArgs e)
{
// Assumes that the assemblies default namespace is
CursorExampleXYZ and that
// the cursor file, JPGHANDX.cur, build action is set to Embedded
Resourse.
this.Cursor = new
Cursor(this.GetType().Assembly.GetManifestResource Stream(
"CursorExampleXYZ.JPGHANDX.cur"));
}

"Paul Cheetham" <PA******@dsl.pipex.com> wrote in message
news:Oj****************@TK2MSFTNGP11.phx.gbl...
Hi,

I am trying to load a custom cursor from my programs resources.
I have successfully included the cursor resource, and I have confirmed
that the name I am using is correct.

Below is the code I am using to try and load the cursor - which always
returns null.

I have tried using LoadImage and LoadCursor with the same result.

Can anyone see what I cant?

public static Cursor LoadCursor (string CursorName)
{
Cursor myCursor = null;
String Name;
IntPtr HCursor=IntPtr.Zero, HInst=IntPtr.Zero;

//Name = "Prologic." + CursorName + ".CUR";
Name = "ProLogic.Cursors.IRON.CUR";

HInst = Win32.GetModuleHandleW(null);

HCursor = Win32.LoadImage(HInst, Name, Win32.IMAGE_CURSOR, 0, 0,
Win32.LR_DEFAULTCOLOR | Win32.LR_DEFAULTSIZE | Win32.LR_SHARED);
//HCursor = Win32.LoadCursor (HInst, Name);
if (HCursor.ToInt32() > 0)
myCursor = new Cursor (HCursor);

return (myCursor);
}
}

/// <author>Shrijeet Nair</author>
public class Win32
{
public const uint IMAGE_BITMAP = 0;
public const uint IMAGE_ICON = 1;
public const uint IMAGE_CURSOR = 2;

public const uint LR_DEFAULTCOLOR = 0x0000;
public const uint LR_MONOCHROME = 0x0001;
public const uint LR_COLOR = 0x0002;
public const uint LR_COPYRETURNORG = 0x0004;
public const uint LR_COPYDELETEORG = 0x0008;
public const uint LR_LOADFROMFILE = 0x0010;
public const uint LR_LOADTRANSPARENT = 0x0020;
public const uint LR_DEFAULTSIZE = 0x0040;
public const uint LR_VGACOLOR = 0x0080;
public const uint LR_LOADMAP3DCOLORS = 0x1000;
public const uint LR_CREATEDIBSECTION = 0x2000;
public const uint LR_COPYFROMRESOURCE = 0x4000;
public const uint LR_SHARED = 0x8000;
[DllImport("User32.dll")]
public static extern IntPtr LoadImage(IntPtr hinst,

[MarshalAs(UnmanagedType.LPTStr)] string lpszName,
uint uType,
int cxDesired,
int cyDesired,
uint fuLoad);

[DllImport("User32.dll")]
public static extern IntPtr LoadCursor(IntPtr hinst,
[MarshalAs(UnmanagedType.LPTStr)] string lpszName);

[DllImport( "kernel32.dll" )]
public extern static IntPtr
GetModuleHandleW([MarshalAs(UnmanagedType.LPStr)] string lpModuleName );

}

Thanks for any help.

Paul


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon Wigzell | last post by:
I have an image with several links in it in mapped areas. I am using a custom cursor on the page and would like to have a custom cursor appear on mouse over of the mapped links. Something like: ...
0
by: Christian H | last post by:
Hello, I've got some trouble trying to use a custom cursor. I'm trying to use ResourceManager to load the cursor from a whatever resX file I choose to have it in. It seems that the Cursor()...
0
by: bruce | last post by:
ASP.NET app running for about a year with no problem and suddenly this week it's giving error message. The same as the one decribed by another user. Even stranger is that we only have this problem...
2
by: Bubbles Van | last post by:
I'm trying to load an animated cursor resource directly from the exe file. I have added it in into the assembly and set it's build action to embedded resource. I have a function written as...
4
by: Schorschi | last post by:
I am trying to mimic the following (which works) but Use the stock GetManifestResourceStream route. For example Public Declare Unicode Function LoadCursorFromFile Lib "USER32.DLL" Alias...
10
by: technocrat | last post by:
Hi, I am trying to declare and cursor and thn load from that cursor into another table. Since I have almost 4 million records, I cant do it without the cursor which reduces the time by almost...
1
by: peteh | last post by:
Hi All; I have a 2.5mm row table (very wide columns) on an UDB v8.2.3 (DPF - 6x10) AIX box. We were doing some performance testing to determine the pros and cons of delete/insert vs load from...
4
by: bern11 | last post by:
How do you embed a custom cursor? The help says: // On the command line: // Add the following flag: // /res:CursorFileName.Cur,Namespace.CursorFileName.Cur What if you are...
0
by: pip | last post by:
I want to use load by cursor for obvious performance reasons, but following execution of a SQL script I need to check the Unix return code and either commit or rollback, is there anyway I can use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.