[Lazarus] Setting a cursor from resource

Paul Ishenin webpirat at mail.ru
Wed Mar 23 12:20:52 CET 2011


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




More information about the Lazarus mailing list