473,722 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Ze ro;

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

HInst = Win32.GetModule HandleW(null);

HCursor = Win32.LoadImage (HInst, Name, Win32.IMAGE_CUR SOR, 0, 0,
Win32.LR_DEFAUL TCOLOR | Win32.LR_DEFAUL TSIZE | Win32.LR_SHARED );
//HCursor = Win32.LoadCurso r (HInst, Name);
if (HCursor.ToInt3 2() > 0)
myCursor = new Cursor (HCursor);

return (myCursor);
}
}

/// <author>Shrijee t 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_COPYRETURNOR G = 0x0004;
public const uint LR_COPYDELETEOR G = 0x0008;
public const uint LR_LOADFROMFILE = 0x0010;
public const uint LR_LOADTRANSPAR ENT = 0x0020;
public const uint LR_DEFAULTSIZE = 0x0040;
public const uint LR_VGACOLOR = 0x0080;
public const uint LR_LOADMAP3DCOL ORS = 0x1000;
public const uint LR_CREATEDIBSEC TION = 0x2000;
public const uint LR_COPYFROMRESO URCE = 0x4000;
public const uint LR_SHARED = 0x8000;
[DllImport("User 32.dll")]
public static extern IntPtr LoadImage(IntPt r hinst,

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

[DllImport("User 32.dll")]
public static extern IntPtr LoadCursor(IntP tr hinst,
[MarshalAs(Unman agedType.LPTStr )] string lpszName);

[DllImport( "kernel32.d ll" )]
public extern static IntPtr
GetModuleHandle W([MarshalAs(Unman agedType.LPStr)] string lpModuleName );

}

Thanks for any help.

Paul
Nov 17 '05 #1
2 10596
Try something like this:
private void button1_Click(o bject sender, System.EventArg s e)
{
// Assumes that the assemblies default namespace is
CursorExampleXY Z and that
// the cursor file, JPGHANDX.cur, build action is set to Embedded
Resourse.
this.Cursor = new
Cursor(this.Get Type().Assembly .GetManifestRes ourceStream(
"CursorExampleX YZ.JPGHANDX.cur "));
}

"Paul Cheetham" <PA******@dsl.p ipex.com> wrote in message
news:Oj******** ********@TK2MSF TNGP11.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.Ze ro;

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

HInst = Win32.GetModule HandleW(null);

HCursor = Win32.LoadImage (HInst, Name, Win32.IMAGE_CUR SOR, 0, 0,
Win32.LR_DEFAUL TCOLOR | Win32.LR_DEFAUL TSIZE | Win32.LR_SHARED );
//HCursor = Win32.LoadCurso r (HInst, Name);
if (HCursor.ToInt3 2() > 0)
myCursor = new Cursor (HCursor);

return (myCursor);
}
}

/// <author>Shrijee t 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_COPYRETURNOR G = 0x0004;
public const uint LR_COPYDELETEOR G = 0x0008;
public const uint LR_LOADFROMFILE = 0x0010;
public const uint LR_LOADTRANSPAR ENT = 0x0020;
public const uint LR_DEFAULTSIZE = 0x0040;
public const uint LR_VGACOLOR = 0x0080;
public const uint LR_LOADMAP3DCOL ORS = 0x1000;
public const uint LR_CREATEDIBSEC TION = 0x2000;
public const uint LR_COPYFROMRESO URCE = 0x4000;
public const uint LR_SHARED = 0x8000;
[DllImport("User 32.dll")]
public static extern IntPtr LoadImage(IntPt r hinst,

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

[DllImport("User 32.dll")]
public static extern IntPtr LoadCursor(IntP tr hinst,
[MarshalAs(Unman agedType.LPTStr )] string lpszName);

[DllImport( "kernel32.d ll" )]
public extern static IntPtr
GetModuleHandle W([MarshalAs(Unman agedType.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(o bject sender, System.EventArg s e)
{
// Assumes that the assemblies default namespace is
CursorExampleXY Z and that
// the cursor file, JPGHANDX.cur, build action is set to Embedded
Resourse.
this.Cursor = new
Cursor(this.Get Type().Assembly .GetManifestRes ourceStream(
"CursorExampleX YZ.JPGHANDX.cur "));
}

"Paul Cheetham" <PA******@dsl.p ipex.com> wrote in message
news:Oj******** ********@TK2MSF TNGP11.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.Ze ro;

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

HInst = Win32.GetModule HandleW(null);

HCursor = Win32.LoadImage (HInst, Name, Win32.IMAGE_CUR SOR, 0, 0,
Win32.LR_DEFA ULTCOLOR | Win32.LR_DEFAUL TSIZE | Win32.LR_SHARED );
//HCursor = Win32.LoadCurso r (HInst, Name);
if (HCursor.ToInt3 2() > 0)
myCursor = new Cursor (HCursor);

return (myCursor);
}
}

/// <author>Shrijee t 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_COPYRETURNOR G = 0x0004;
public const uint LR_COPYDELETEOR G = 0x0008;
public const uint LR_LOADFROMFILE = 0x0010;
public const uint LR_LOADTRANSPAR ENT = 0x0020;
public const uint LR_DEFAULTSIZE = 0x0040;
public const uint LR_VGACOLOR = 0x0080;
public const uint LR_LOADMAP3DCOL ORS = 0x1000;
public const uint LR_CREATEDIBSEC TION = 0x2000;
public const uint LR_COPYFROMRESO URCE = 0x4000;
public const uint LR_SHARED = 0x8000;
[DllImport("User 32.dll")]
public static extern IntPtr LoadImage(IntPt r hinst,

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

[DllImport("User 32.dll")]
public static extern IntPtr LoadCursor(IntP tr hinst,
[MarshalAs(Unman agedType.LPTStr )] string lpszName);

[DllImport( "kernel32.d ll" )]
public extern static IntPtr
GetModuleHand leW([MarshalAs(Unman agedType.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
6905
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: This works for the body, font or img tag: <body style="cursor: url('cursor2.cur')"> <font style="cursor: url('cursor1.cur')">Text</font> <img style="cursor: url('cursor1.cur')" src="...etc...">
0
1443
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() constructor expects a Stream. What I get from Resourcemanager.GetObject() is an Object. Does anyone know how to convert the Object to a byte Stream so that I can load the cursor?
0
1779
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 from some web clients (desktop browser, IE) , some other people do not have problems at all from theirs desktop. =============================== I am getting the following message when I try to access the asp.dotnet pages of our website.
2
3893
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 follows: Private Function GetResCursor(ByVal strIdentifier As String) As Cursor Return New Cursor(.GetExecutingAssembly().GetManifestResourceStream(strIdenti fier))
4
2812
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 "LoadCursorFromFileW" (ByVal thePath As String) As IntPtr Dim theCursor As Cursor
10
10891
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/10th. I tried to create a sql statement for "load from cursor cur insert into table name" using java stored procedure, but this isnt recognised by sql since load isnt a sql keyword. So whats the solution to this. I have to do it programatically...
1
5145
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 cursor operations in our ETL architecture (data warehouse extract/transform/load). We expected load from cursor to be substantially faster, but found that the delete/insert took 2 minutes and the load from cursor took 5 minutes.
4
3539
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 compiling with the IDE? I don't see a 'command line options' field anywhere...???
0
1748
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 load by cursor? I'm running the SQL from a shell script calling with commit hold db2 -t +c -f sqlscript.sql then reading the unix return code and issuing either commit or rollback, but in the event of a failure condition in load by cursor it issues...
0
8863
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.