Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-03

Setting a cursor from resource

31 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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

Reply by email

Paul Ishenin
to patspiper
patspiper wrote 5 lines
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

Reply by email

patspiper
to Paul Ishenin
Paul Ishenin wrote 26 lines
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

Reply by email

Paul Ishenin
to patspiper
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

Reply by email

Paul Ishenin
to Paul Ishenin
Paul Ishenin wrote 8 lines
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

Reply by email

patspiper
to Paul Ishenin
Paul Ishenin wrote 13 lines
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

Reply by email

Paul Ishenin
to patspiper
patspiper wrote 6 lines
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

Reply by email

zeljko
to Paul Ishenin
Paul Ishenin wrote 12 lines
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

Reply by email

patspiper
to Paul Ishenin: I did not add/remove/change any resource. Please build it from console using "make…
Paul Ishenin wrote 12 lines
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

Reply by email

patspiper
to Paul Ishenin
Paul Ishenin wrote 5 lines
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 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

Reply by email

Paul Ishenin
to patspiper
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

Reply by email

patspiper
to Paul Ishenin
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

Reply by email

Paul Ishenin
to patspiper
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

Reply by email

patspiper
to Paul Ishenin
Paul Ishenin wrote 18 lines
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

Show quoted text 11 lines
Best regards, Paul Ishenin -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

patspiper
to zeljko
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

Reply by email

Paul Ishenin
to zeljko: Are you sure that it was impossible before ? zeljko
zeljko wrote 5 lines
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

Reply by email

patspiper
to Paul Ishenin
Paul Ishenin wrote 12 lines
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

Reply by email

Paul Ishenin
to patspiper
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

Reply by email

patspiper
to Paul Ishenin
Paul Ishenin wrote 7 lines
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.

Feature request added on the bug tracker (#18980)? ;-)

Stephano

Reply by email

Zaher Dirkey
to Paul Ishenin: No at the moment. Although I don't think it will be too difficult to implement. Paul…
Paul Ishenin wrote 14 lines
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 Is it possible to add the image inside the unit without to convert it to

laz/fpc resource? (i mean in the feature)

Thanks

Zaher Dirkey -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110324/e2d836fc/attachment.html>

Reply by email

patspiper
to Zaher Dirkey
Zaher Dirkey wrote 21 lines
On Thu, Mar 24, 2011 at 12:24 PM, Paul Ishenin < <mailto:>> wrote: 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 Is it possible to add the image inside the unit without to convert it to laz/fpc resource? (i mean in the feature

You can add the contents of a lrs file in the initialization section of a unit. After all, {$I *.lrs} just includes the lrs file.

Stephano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110324/357af834/attachment.html>

Reply by email

patspiper
to Zaher Dirkey
Zaher Dirkey wrote 9 lines
2011/3/24 patspiper < <mailto:>> You can add the contents of a lrs file How without using a converter (image -> lrs) I like to have this, in unit that register my controls {$r 'myimage.png'}

$R needs res files whereas Lazarus understands lrs files. In your case, you can just load the image at runtime:
Image1.Picture.Bitmap.LoadFromFile(myimage.png)

Stephano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110324/8b48592a/attachment.html>

Reply by email

Zaher Dirkey
to patspiper

2011/3/24 patspiper

Show quoted text 17 lines
On 03/24/2011 01:05 PM, Zaher Dirkey wrote: 2011/3/24 patspiper > You can add the contents of a lrs file How without using a converter (image -> lrs) I like to have this, in unit that register my controls {$r 'myimage.png'} $R needs res files whereas Lazarus understands lrs files. In your case, you can just load the image at runtime: Image1.Picture.Bitmap.LoadFromFile(myimage.png)

look at {$R *.lfm} it is text file loaded as FPC resouce, i do not know how it is happened, BTW loading in runtime not good idea for Component Packages icons.

Best Regards

Zaher Dirkey -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110324/570abb37/attachment.html>

Reply by email

Paul Ishenin
to patspiper: Feature request added on the bug tracker (#18980)? ;-) Stephano

24.03.2011 17:45, patspiper ?????:

Show quoted text 7 lines
>> 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. Feature request added on the bug tracker (#18980)? ;-)

Implemented in r30011.

Best regards,
Paul Ishenin

Reply by email

patspiper
to Paul Ishenin
Paul Ishenin wrote 10 lines
24.03.2011 17:45, patspiper ?????: >>> 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. > Feature request added on the bug tracker (#18980)? > ;-) Implemented in r30011.

Works great!

Thanks,
Stephano

Reply by email

Zaher Dirkey
to patspiper
patspiper wrote 20 lines
On 03/25/2011 09:34 AM, Paul Ishenin wrote: > 24.03.2011 17:45, patspiper ?????: > >> 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. >>> >> Feature request added on the bug tracker (#18980)? >> ;-) >> > > Implemented in r30011. > Works great!

Can you make example how it work for you, i still not understand the issue.

Thanks in advance.

Zaher Dirkey -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110326/05c91552/attachment-0001.html>

Reply by email

Mattias Gaertner
to Zaher Dirkey
Show quoted text 23 lines
On Fri, Mar 25, 2011 at 10:59 AM, patspiper wrote: > On 03/25/2011 09:34 AM, Paul Ishenin wrote: > >> 24.03.2011 17:45, patspiper ?????: >> >>> 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. >>>> >>> Feature request added on the bug tracker (#18980)? >>> ;-) >>> >> >> Implemented in r30011. >> > Works great! > > Can you make example how it work for you, i still not understand the issue.

And please document it here:

http://wiki.lazarus.freepascal.org/Lazarus_Packages#Add_a_component_icon

Mattias

Reply by email

patspiper
to Mattias Gaertner
Mattias Gaertner wrote 27 lines
On Sat, 26 Mar 2011 21:21:28 +0200 Zaher Dirkey wrote: > On Fri, Mar 25, 2011 at 10:59 AM, patspiper wrote: > >> On 03/25/2011 09:34 AM, Paul Ishenin wrote: >> >>> 24.03.2011 17:45, patspiper ?????: >>> >>>> 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. >>>>> >>>> Feature request added on the bug tracker (#18980)? >>>> ;-) >>>> >>> Implemented in r30011. >>> >> Works great! >> >> > Can you make example how it work for you, i still not understand the issue. And please document it here: http://wiki.lazarus.freepascal.org/Lazarus_Packages#Add_a_component_icon

Done.

What I am not sure of is how PNG's can be used that way. Can PNG's be included in .res/dcr files?

Can the new method be integrated in the New Component window, the same as the lrs one?

Stephano

Reply by email