[Lazarus] Setting a cursor from resource

classic Classic list List threaded Threaded
31 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Setting a cursor from resource

patspiper
Hi,

How can a control's cursor be set from a resource file?
The code below does not work, although the resource itself is found and
loaded.

Panel1.cursor := LoadCursor(0, 'CURSOR_NAME');

function LoadCursor(hInstance: HINST; lpCursorName: pchar): HCURSOR;
var
  ResType: TResourceType;
  ResHandle: TFPResourceHandle;
  GlobalHandle: TFPResourceHGlobal;
begin
  ResType := RT_GROUP_CURSOR;
  ResHandle := FindResource(hInstance, lpCursorName, PChar(ResType));
  if ResHandle = 0 then
    raise Exception.Create('ResName');
  GlobalHandle := LoadResource(hInstance, ResHandle);
  //LockResource(GlobalHandle);
  Result := ResHandle;
  //Result := GlobalHandle;
end;

Stephano

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

Paul Ishenin
23.03.2011 17:25, patspiper wrote:
> How can a control's cursor be set from a resource file?
> The code below does not work, although the resource itself is found
> and loaded.
>
> Panel1.cursor := LoadCursor(0, 'CURSOR_NAME');
The same way as in delphi:

const
   MyUserCursor = 1;
Screen.Cursors[MyUserCursor] := LoadCursor(HInstance, 'Cursor_Name');
Panel1.Cursor := MyUserCursor;

LoadCursor works on windows only.

To write cross platform code use:

var
   Cur: TCursorImage;
begin
   Cur := TCursorImage.Create;
   Cur.LoadFromResourceName('Cursor_Name');
   Screen.Cursors[MyUserCursor] := Cur.ReleaseHandle;
   Cur.Free;
   Panel1.Cursor := MyUserCursor;
end;

Best regards,
Paul Ishenin

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

patspiper
On 03/23/2011 01:20 PM, Paul Ishenin wrote:

> 23.03.2011 17:25, patspiper wrote:
>> How can a control's cursor be set from a resource file?
>> The code below does not work, although the resource itself is found
>> and loaded.
>>
>> Panel1.cursor := LoadCursor(0, 'CURSOR_NAME');
> The same way as in delphi:
>
> const
>   MyUserCursor = 1;
> Screen.Cursors[MyUserCursor] := LoadCursor(HInstance, 'Cursor_Name');
> Panel1.Cursor := MyUserCursor;
>
> LoadCursor works on windows only.
>
> To write cross platform code use:
>
> var
>   Cur: TCursorImage;
> begin
>   Cur := TCursorImage.Create;
>   Cur.LoadFromResourceName('Cursor_Name');
>   Screen.Cursors[MyUserCursor] := Cur.ReleaseHandle;
>   Cur.Free;
>   Panel1.Cursor := MyUserCursor;
> end;
EInvalidGraphic: Stream is not an icon type

Is the code above compatible with both RT_CURSOR and RT_GROUP_CURSOR
resources?

Thanks,
Stephano

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

Paul Ishenin
23.03.2011 18:54, patspiper wrote:
> EInvalidGraphic: Stream is not an icon type
I will do a test tomorow.
>
> Is the code above compatible with both RT_CURSOR and RT_GROUP_CURSOR
> resources?
I tested it with icons only. I see from the code that instead of
RT_CURSOR for TCursorImage it will use RT_ICON. Maybe this cause a problem.

Best regards,
Paul Ishenin

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

Paul Ishenin-2
23.03.2011 21:01, Paul Ishenin wrote:
> 23.03.2011 18:54, patspiper wrote:
>> EInvalidGraphic: Stream is not an icon type
> I will do a test tomorow.
>>
>> Is the code above compatible with both RT_CURSOR and RT_GROUP_CURSOR
>> resources?
> I tested it with icons only. I see from the code that instead of
> RT_CURSOR for TCursorImage it will use RT_ICON. Maybe this cause a problem.

Where were more problems than I expected. I hope I fixed them all in
r30006. Please test.

Best regards,
Paul Ishenin


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

patspiper
On 03/24/2011 05:38 AM, Paul Ishenin wrote:

> 23.03.2011 21:01, Paul Ishenin wrote:
>> 23.03.2011 18:54, patspiper wrote:
>>> EInvalidGraphic: Stream is not an icon type
>> I will do a test tomorow.
>>>
>>> Is the code above compatible with both RT_CURSOR and RT_GROUP_CURSOR
>>> resources?
>> I tested it with icons only. I see from the code that instead of
>> RT_CURSOR for TCursorImage it will use RT_ICON. Maybe this cause a
>> problem.
>
> Where were more problems than I expected. I hope I fixed them all in
> r30006. Please test.
updated to r30007 and while rebuilding Lazarus:Compiling resource
../units/i386-linux/lazarus.or
/home/me/lazarus/lazarus-svn/ide/lazarus.pp(135,1) Error: Error while
compiling resources

Lazarus 0.9.31 r29900M FPC 2.4.2 i386-linux-gtk 2

Thanks,
Stephano

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

Paul Ishenin-2
24.03.2011 13:55, patspiper wrote:
> updated to r30007 and while rebuilding Lazarus:Compiling resource
> ../units/i386-linux/lazarus.or
> /home/me/lazarus/lazarus-svn/ide/lazarus.pp(135,1) Error: Error while
> compiling resources
>
> Lazarus 0.9.31 r29900M FPC 2.4.2 i386-linux-gtk 2

I did not add/remove/change any resource.

Please build it from console using "make bigideclean bigide". Maybe the
error when you build from console will be explained better.

Best regards,
Paul Ishenin


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

zeljko
On Thursday 24 of March 2011 09:04:25 Paul Ishenin wrote:

> 24.03.2011 13:55, patspiper wrote:
> > updated to r30007 and while rebuilding Lazarus:Compiling resource
> > ../units/i386-linux/lazarus.or
> > /home/me/lazarus/lazarus-svn/ide/lazarus.pp(135,1) Error: Error while
> > compiling resources
> >
> > Lazarus 0.9.31 r29900M FPC 2.4.2 i386-linux-gtk 2
>
> I did not add/remove/change any resource.
>
> Please build it from console using "make bigideclean bigide". Maybe the
> error when you build from console will be explained better.

Lazarus 0.9.31 r30007M FPC 2.4.3 i386-linux-gtk 2 builds fine, also qt
version.
zeljko

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

patspiper
In reply to this post by Paul Ishenin-2
On 03/24/2011 10:04 AM, Paul Ishenin wrote:

> 24.03.2011 13:55, patspiper wrote:
>> updated to r30007 and while rebuilding Lazarus:Compiling resource
>> ../units/i386-linux/lazarus.or
>> /home/me/lazarus/lazarus-svn/ide/lazarus.pp(135,1) Error: Error while
>> compiling resources
>>
>> Lazarus 0.9.31 r29900M FPC 2.4.2 i386-linux-gtk 2
>
> I did not add/remove/change any resource.
>
> Please build it from console using "make bigideclean bigide". Maybe
> the error when you build from console will be explained better.
Maybe I did not explain my testing well:
Lazarus builds fine with the standard packages. When I installed my
packages, I got this error.
I finally found that 2 of my packages are causing this error.

How can I build the IDE with all packages from the command line? make xxx?

Stephano

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

Paul Ishenin-2
24.03.2011 15:37, patspiper wrote:
> How can I build the IDE with all packages from the command line? make xxx?

lazbuild lazarus.lpi ?

Best regards,
Paul Ishenin


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

patspiper
On 03/24/2011 10:54 AM, Paul Ishenin wrote:
> 24.03.2011 15:37, patspiper wrote:
>> How can I build the IDE with all packages from the command line? make
>> xxx?
>
> lazbuild lazarus.lpi ?
I used make ide OPT=@/path/to/your/config/idemake.cfg to build now:

Compiling lazarus.pp
Compiling resource ../units/i386-linux/lazarus.or
Error: Duplicate resource: Type = 24, Name = 1, Lang ID = 0000
lazarus.pp(135,1) Error: Error while compiling resources
lazarus.pp(135,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

So it seems there is some duplicate resource name that the package adds.
The previous Lazarus revisions maybe ignored this resource. How can we
get more info as to which resource it is?

Stephano

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

Paul Ishenin-2
24.03.2011 15:58, patspiper wrote:
> Error: Duplicate resource: Type = 24, Name = 1, Lang ID = 0000

Somewhere you add another windows manifest.

> So it seems there is some duplicate resource name that the package adds.
> The previous Lazarus revisions maybe ignored this resource. How can we
> get more info as to which resource it is?

The previous Lazarus revisions did not ignore this.

Best regards,
Paul Ishenin


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

patspiper
On 03/24/2011 11:05 AM, Paul Ishenin wrote:
> 24.03.2011 15:58, patspiper wrote:
>> Error: Duplicate resource: Type = 24, Name = 1, Lang ID = 0000
>
> Somewhere you add another windows manifest.
Can you pls give details as I have no idea about manifests (aren't they
Windows specific?)

What should I check?

Thanks
Stephano

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

Paul Ishenin-2
24.03.2011 16:17, patspiper wrote:

> Can you pls give details as I have no idea about manifests (aren't they
> Windows specific?)

They are windows specific but this is not important because FPC includes
all requested resources (no matter how windows specific they are) into
the final executable.

> What should I check?

Check that all the .res files which are involved into the IDE building
process (except lazarus.res) does not contain windows manifest resource.

Maybe you include a res file which IDE made for a project (it usually
has a manifest resource) into a package? If you made your .res files
from .rc please check them if they contain resources with type RT_MANIFEST.

Best regards,
Paul Ishenin


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

patspiper
On 03/24/2011 11:39 AM, Paul Ishenin wrote:

> 24.03.2011 16:17, patspiper wrote:
>
>> Can you pls give details as I have no idea about manifests (aren't they
>> Windows specific?)
>
> They are windows specific but this is not important because FPC
> includes all requested resources (no matter how windows specific they
> are) into the final executable.
>
>> What should I check?
>
> Check that all the .res files which are involved into the IDE building
> process (except lazarus.res) does not contain windows manifest resource.
>
> Maybe you include a res file which IDE made for a project (it usually
> has a manifest resource) into a package? If you made your .res files
> from .rc please check them if they contain resources with type
> RT_MANIFEST.
I deleted the package's files and recopied them fresh. Everything went
smooth.

Furthermore, Lazarus is now able to load cursors.

Thanks!
Stephano

>
> Best regards,
> Paul Ishenin
>
>
> --
> _______________________________________________
> Lazarus mailing list
> [hidden email]
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

zeljko
On Thursday 24 of March 2011 10:58:48 patspiper wrote:

> Furthermore, Lazarus is now able to load cursors.

Are you sure that it was impossible before ?
zeljko

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

patspiper
On 03/24/2011 12:00 PM, zeljko wrote:
> On Thursday 24 of March 2011 10:58:48 patspiper wrote:
>
>> Furthermore, Lazarus is now able to load cursors.
> Are you sure that it was impossible before ?
I used to get an exception due to the idtype being 32 instead of 1 or 2.
No idea why.

Stephano

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

Paul Ishenin-2
In reply to this post by zeljko
24.03.2011 17:00, zeljko wrote:
> On Thursday 24 of March 2011 10:58:48 patspiper wrote:
>
>> Furthermore, Lazarus is now able to load cursors.
>
> Are you sure that it was impossible before ?

We are talking about loading them from the FPC resources. From .lrs
files they worked fine before. Later I implemented loading icons from
FPC resources and expected that cursors will work too but for unknown
reason microsoft implemented them less compatible in resources than in
files.

Best regards,
Paul Ishenin


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

patspiper
On 03/24/2011 12:07 PM, Paul Ishenin wrote:

> 24.03.2011 17:00, zeljko wrote:
>> On Thursday 24 of March 2011 10:58:48 patspiper wrote:
>>
>>> Furthermore, Lazarus is now able to load cursors.
>>
>> Are you sure that it was impossible before ?
>
> We are talking about loading them from the FPC resources. From .lrs
> files they worked fine before. Later I implemented loading icons from
> FPC resources and expected that cursors will work too but for unknown
> reason microsoft implemented them less compatible in resources than in
> files.
Since you mentioned FPC resources, can palette components (IDE) have
their resources as FPC resources instead of using .lrs ones?

Stephano

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Setting a cursor from resource

Paul Ishenin-2
24.03.2011 17:16, patspiper wrote:

> Since you mentioned FPC resources, can palette components (IDE) have
> their resources as FPC resources instead of using .lrs ones?

No at the moment. Although I don't think it will be too difficult to
implement.

Best regards,
Paul Ishenin


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
12