Recent

Author Topic: Custom cursors  (Read 1548 times)

simsee

  • Full Member
  • ***
  • Posts: 212
Custom cursors
« on: February 05, 2024, 04:49:08 pm »
I'm writing a component that needs some custom mouse cursors. I read some old posts on the subject and also studied the example present in the Lazarus installation folders, but something is not clear to me.

Assuming that the custom cursor file is called pencil.cur, using the lazres utility, I construct the resource file as follows

C:\Users\216068\Desktop\res>lazres cursors.res pencil.cur
pencil.cur ResourceName='pencil' Type=RT_GROUP_CURSOR


At this point in the unit relating to the main form of my application I add the following initialization section (see attachment for the complete project):

Code: Pascal  [Select][+][-]
  1. implementation
  2.  
  3. {$R *.lfm}
  4. //{$R *cursors.res}
  5.  
  6. { TForm1 }
  7.  
  8. initialization
  9.   Screen.Cursors[1]:=LoadCursorFromLazarusResource('pencil');
  10.   Screen.Cursor:=1;
  11. end.

Unfortunately the program it does not work, failing to find the cursor resource.

What did I do wrong? Thanks in advance.
« Last Edit: February 05, 2024, 04:55:14 pm by simsee »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Custom cursors
« Reply #1 on: February 05, 2024, 05:24:28 pm »
\lazarus\examples\cursors\project1.lpi
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   Cur: TCursorImage;
  4. begin
  5.   Cur := TCursorImage.Create;
  6.   Cur.LoadFromResourceName(HInstance, 'car');
  7.   Screen.Cursors[1] := Cur.ReleaseHandle;
  8.   Cur.Free;
  9.   Button5.Cursor := 1;
  10. end;
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

simsee

  • Full Member
  • ***
  • Posts: 212
Re: Custom cursors
« Reply #2 on: February 05, 2024, 05:37:15 pm »
As I said in my post, I know this example, but I wanted to use a different approach, more suitable for my context.

In the meantime, I solved it like this:

Code: Pascal  [Select][+][-]
  1. implementation
  2. uses
  3.   LCLIntf;
  4.  
  5. {$R *.lfm}
  6. {$R cursors.res}
  7.  
  8. { TForm1 }
  9.  
  10. procedure TForm1.Button1Click(Sender: TObject);
  11. begin
  12.   Screen.Cursor:=1;
  13. end;
  14.  
  15. { TForm1 }
  16.  
  17. initialization
  18.   Screen.Cursors[1]:=LoadCursor(HInstance, 'PENCIL');
  19. end.

Anyway, thanks for the help.
« Last Edit: February 05, 2024, 08:34:25 pm by simsee »

 

TinyPortal © 2005-2018