Board index » delphi » Cursors in resource files

Cursors in resource files

Hi,

I'm trying to use my own mouse cursors in my app.
What I've done so far which works is:
'''''''''''''''
const
   UPARROW = 1;
   DOWNARROW = 2;

//And to load them
   Screen.Cursors[UPARROW] := LoadCursorFromFile
('pathname\UPARROW.CUR')
''''''''''''''
This works fine so "Screen.Cursor := UPARROW" will give me
the right cursor.

What I want to do is to link them to the program using
the .res file. I have inserted the cursors into the .res
file and use the following line to load them

Screen.Cursors[UPARROW]:=LoadCursor(hInstance, 'UPARROW');

but they no longer appear when I ask them to.
I'm sure it's something very simple I'm doing wrong.

Thanks in advance

noswad

* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful

 

Re:Cursors in resource files


I am beginning to suspect that either there is something I don't
understand about loading resources, or something querky about the wat
Delphi handles them.

I consistently have had problems with loading cursor resources. There
are two things that I have figured out, although these are hopefully
just a result of something I am misunderstanding:

1. I cannot store the cursor resources in the project's resource file.
If my project is named Project1, for example, I cannot store the
cursors in Project1.exe and then use them in my application. The only
way I get them to load is to store them in a spearate resource file
and then include that new resource file in my project source by
placing the following line in my my project source:

{$R *.res} //This line is already here
{$R newcursor.res} //this line is added

2. When I create a resource in the image editor distributed with
Delphi, It defaults to the name "Cursor1" for the first resource I
add. I have found that I cannot load this resource, but that if I
change the name to all capital letters (i.e. CURSOR1) I can load it.
Also, I have to name it CURSORX, where X is the appropriate number of
the cursor resource. I can not name it, for instance, MYCURSOR, or or
even CURSOR 1 with a space.

Again, I can't believe that it is really possible that Delphi can't
handle custom resource names or that it somehow fails to compile
resources in its own project file into the executable it creates, so I
must believe instead that I am doing something wrong.

I hope someone else gives you the real scoop on this, because I'd like
to know too. I hope this has at least helped get you working....

Tom

On Wed, 24 Nov 1999 04:18:52 -0800, noswad

Quote
<idawsonNOidS...@gentia.com.invalid> wrote:
>Hi,

>I'm trying to use my own mouse cursors in my app.
>What I've done so far which works is:
>'''''''''''''''
>const
>   UPARROW = 1;
>   DOWNARROW = 2;

>//And to load them
>   Screen.Cursors[UPARROW] := LoadCursorFromFile
>('pathname\UPARROW.CUR')
>''''''''''''''
>This works fine so "Screen.Cursor := UPARROW" will give me
>the right cursor.

>What I want to do is to link them to the program using
>the .res file. I have inserted the cursors into the .res
>file and use the following line to load them

>Screen.Cursors[UPARROW]:=LoadCursor(hInstance, 'UPARROW');

>but they no longer appear when I ask them to.
>I'm sure it's something very simple I'm doing wrong.

>Thanks in advance

>noswad

>* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful

Re:Cursors in resource files


Hi,

What you have described appears pretty much to be what I have implemented in
Delphi 4 and it works fine.
One thing I recollect though was having trouble saving the Resource file.
when using the image editor I found that in order to save properly I needed
to shut sown the Delphi IDE and run Image Editor separately.
I would suggest checking to see if your resources are in the file.
Hope this helps.

Julie.

Re:Cursors in resource files


Yup, That is correct
How ever, if you don't like the way the Resource editor works you can use the
command liine resource compiler and write the resource your self.., then you can name it what you like..
you still need to add it to your source like you did.., do a  BUILD ALL and you will be set..
Quote
Tom wrote:
> I am beginning to suspect that either there is something I don't
> understand about loading resources, or something querky about the wat
> Delphi handles them.

> I consistently have had problems with loading cursor resources. There
> are two things that I have figured out, although these are hopefully
> just a result of something I am misunderstanding:

> 1. I cannot store the cursor resources in the project's resource file.
> If my project is named Project1, for example, I cannot store the
> cursors in Project1.exe and then use them in my application. The only
> way I get them to load is to store them in a spearate resource file
> and then include that new resource file in my project source by
> placing the following line in my my project source:

> {$R *.res} //This line is already here
> {$R newcursor.res} //this line is added

> 2. When I create a resource in the image editor distributed with
> Delphi, It defaults to the name "Cursor1" for the first resource I
> add. I have found that I cannot load this resource, but that if I
> change the name to all capital letters (i.e. CURSOR1) I can load it.
> Also, I have to name it CURSORX, where X is the appropriate number of
> the cursor resource. I can not name it, for instance, MYCURSOR, or or
> even CURSOR 1 with a space.

> Again, I can't believe that it is really possible that Delphi can't
> handle custom resource names or that it somehow fails to compile
> resources in its own project file into the executable it creates, so I
> must believe instead that I am doing something wrong.

> I hope someone else gives you the real scoop on this, because I'd like
> to know too. I hope this has at least helped get you working....

> Tom

> On Wed, 24 Nov 1999 04:18:52 -0800, noswad
> <idawsonNOidS...@gentia.com.invalid> wrote:

> >Hi,

> >I'm trying to use my own mouse cursors in my app.
> >What I've done so far which works is:
> >'''''''''''''''
> >const
> >   UPARROW = 1;
> >   DOWNARROW = 2;

> >//And to load them
> >   Screen.Cursors[UPARROW] := LoadCursorFromFile
> >('pathname\UPARROW.CUR')
> >''''''''''''''
> >This works fine so "Screen.Cursor := UPARROW" will give me
> >the right cursor.

> >What I want to do is to link them to the program using
> >the .res file. I have inserted the cursors into the .res
> >file and use the following line to load them

> >Screen.Cursors[UPARROW]:=LoadCursor(hInstance, 'UPARROW');

> >but they no longer appear when I ask them to.
> >I'm sure it's something very simple I'm doing wrong.

> >Thanks in advance

> >noswad

> >* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful

Re:Cursors in resource files


Hi,

Thanks for your help. After a bit of experimentation I
found that the only way I could get it to work was to make
a seperate resource file just for the cursors. I called it
MouseCur.res and used {$R MouseCur.Res} to link it to the
program and it worked fine.

Strange how when I put the cursors in the apps. res file it
wouldn't work.

* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful

Re:Cursors in resource files


You should never put anything in the apps resource file. Delphi continually
overwrites this file without regard to what you put in it. This is
documented behaviour. You always need to create a separate resource file for
you cursors, bitmaps, etc.. Also, always use uppercase names as that is how
the resource load functions utilize them. I have never had a problem naming
anything in the resource file, however, you can not use spaces. Also, it is
not a good idea to overwrite the standard cursors (the ones that run from 1
to 5, I believe). I always start my own cursors at around 6 or 7.

--

Woody
(Would a fly without wings be called a walk?)

Quote
noswad <idawsonNOidS...@gentia.com.invalid> wrote in message

news:1108a870.007f1a3b@usw-ex0108-061.remarq.com...
Quote
> Hi,

> Thanks for your help. After a bit of experimentation I
> found that the only way I could get it to work was to make
> a seperate resource file just for the cursors. I called it
> MouseCur.res and used {$R MouseCur.Res} to link it to the
> program and it worked fine.

> Strange how when I put the cursors in the apps. res file it
> wouldn't work.

> * Sent from AltaVista http://www.altavista.com Where you can also find

related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is
Beautiful

Re:Cursors in resource files


Quote
In article <383c1328.44949...@news.volny.cz>, tomval...@volny.cz (Tom) writes:
>1. I cannot store the cursor resources in the project's resource file.
>If my project is named Project1, for example, I cannot store the
>cursors in Project1.exe and then use them in my application. The only
>way I get them to load is to store them in a spearate resource file
>and then include that new resource file in my project source by
>placing the following line in my my project source:

My understanding has always been that Delphi re-writes its form_name.RES file
when you save the form, from the resources it needs as defined by your
activities in the IDE. Hence if you include your additional resources in that
file then it will revert to the standard contents after the next code save.
That's why you have to give it another name.

BTW the *.RES in the {$R *.RES} means any res file having the same name as the
form, but with a .RES extension. Not any res file. So it refers to only one
file.

Alan Lloyd
alangll...@aol.com

Other Threads