[solved] Mouse cursor - Custom / loading lazarus / 39-Graphics ---------------------------------------------------------------------- vlado · 2011-10-05 10:17 Hi, is there a simple way to load cursor from a 32px image or from a file? If yes, how? Thanks in advance! ---------------------------------------------------------------------- User137 · 2011-10-05 10:32 Google finds this: http://delphi.about.com/od/adptips2005/qt/bmp2cur.htm ---------------------------------------------------------------------- vlado · 2011-10-06 14:50 @ User137: Gettin' an error: "Main.pas(1459,62) Error: Incompatible type for arg no. 1: Got "ICONINFO", expected "PICONINFO"" on this: Code: [Select] Screen.Cursors[crMyCursor] := CreateIconIndirect(iconInfo); Any idea how to implement PICONINFO? ---------------------------------------------------------------------- felipemdc · 2011-10-06 15:11 Don't use this pre-historical windows-only stuff. Lazarus has TCursorImage in the unit Graphics: Code: [Select]  { TCursorImage }   TCursorImage = class(TCustomIcon)   private     function GetHotSpot: TPoint;     function GetCursorHandle: HCURSOR;     procedure SetCursorHandle(AValue: HCURSOR);   protected     procedure HandleNeeded; override;     class function GetDefaultSize: TSize; override;     class function GetStreamSignature: Cardinal; override;     class function GetSharedImageClass: TSharedRasterImageClass; override;     class function GetTypeID: Word; override;   public     class function GetFileExtensions: string; override;     function GetResourceType: TResourceType; override;     procedure LoadFromResourceHandle(Instance: THandle; ResHandle: TFPResourceHandle); override;     function LazarusResourceTypeValid(const ResourceType: string): boolean; override;     function ReleaseHandle: HCURSOR;     property HotSpot: TPoint read GetHotSpot;     property Handle: HCURSOR read GetCursorHandle write SetCursorHandle;   end; ---------------------------------------------------------------------- typo · 2011-10-06 16:07 How to use it? ---------------------------------------------------------------------- fabienwang · 2011-10-06 16:33 Screen.Cursors[1] := LoadCursorFromLazarusResource('myresource'); Form1.Cursor := 1; bottom of your class: initialization {$I myresource.lrs}   end. how to create myresource and put a cursor in it? use lazres tool (provided with lazarus in tools folder IIRC but not compiled) then you will do: lazres myresource.lrs yourcursor.cur PS: this code is from CPickSniff2: http://cpicksniff2.svn.sourceforge. net/viewvc/cpicksniff2/ufrmmain.pas?revision=10&view=markup ---------------------------------------------------------------------- typo · 2011-10-06 18:58 My error messages: Code: [Select]myresource.lrs(1,17) Error: Identifier not found "LazarusResources" myresource.lrs(65,3) Error: Type conflict between set elements ---------------------------------------------------------------------- fabienwang · 2011-10-08 14:40 Quote from: typo on October 06, 2011, 08:58:17 pmMy error messages: Code: [Select]myresource.lrs(1,17) Error: Identifier not found "LazarusResources" myresource.lrs(65,3) Error: Type conflict between set elements Do you have LResources in the uses section? if not, add it. ---------------------------------------------------------------------- typo · 2011-10-08 15:28 Solved, thanks. ---------------------------------------------------------------------- vlado · 2011-10-10 05:01 Compiles with LResources unit, but in the program's OnMouseEnter event there is an error: 'Resource: "myresource" not found.' (it's OnMouseEnter event because i've put there loading cursor from resource.) ---------------------------------------------------------------------- fabienwang · 2011-10-10 08:48 @vlado, you need to create a new resource file called myresource.lrs and with the tool provided in lazarus\tools\ called lazres, you can add any icon/image or any other file, into a resource file. Thoses files will be integrated in the resource file and therefore, your application won't need anymore the external files, only the resource. ---------------------------------------------------------------------- vlado · 2011-10-10 09:19 @FabienWang, thanks, I've done that (can attach myresource.lrs file if needed), and even "myresource.lrs" file contains the ".cur" file. The beginning of a ".cur" file, first line, looks like this: Code: [Select]LazarusResources.Add('compass1','CUR',[ When the program is running (event that triggers the mouse cursor change), then is this problem with the resource. I've tried adding resource file to a subdirectory of a current program and then loading (e.g. with ExtractFilePath inside LoadCursorFromLazarusResource) but it seems that this doesn't help either. ---------------------------------------------------------------------- fabienwang · 2011-10-10 11:16 vlado, as i told typo, you have to add your resource in the Initialisation section at the bottom of your class: initialization {$I myresource.lrs}   end. of course, replace myresource.lrs by the name of your file. ---------------------------------------------------------------------- typo · 2011-10-10 12:10 In fact, LazRes has told me the resource  name and I have used that instead of "myresource". Code: [Select]  Screen.Cursors[1] := LoadCursorFromLazarusResource('aero_move'); ---------------------------------------------------------------------- vlado · 2011-10-10 14:03 @FabienWang: Resource name was in the initialization section! So, that is not a problem. But, what is? ---------------------------------------------------------------------- typo · 2011-10-10 14:09 Create one near the final end of your unit: Code: [Select]initialization {$I myresource.lrs} end. ---------------------------------------------------------------------- vlado · 2011-10-10 14:46 @Typo: that was there! ---------------------------------------------------------------------- typo · 2011-10-10 16:24 Replace "myresource" with the resource name shown by LazRes. Code: [Select]Screen.Cursors[1] := LoadCursorFromLazarusResource('cursorname');  On Windows, make a BAT file with the following code: Code: [Select]lazres myresource.lrs cursorname.cur pause and use it instead of running LazRes directly. Then you will see the resource name shown by LazRes. ---------------------------------------------------------------------- vlado · 2011-10-10 19:18 @Typo & all: Thank you! Finally works, that was kind of a trick ) ---------------------------------------------------------------------- vlado · 2011-10-12 04:44 Furthermore, how can we put that cursor file(s) inside .exe file? ---------------------------------------------------------------------- User137 · 2011-10-12 05:33 Aren't resources are always added inside .exe? And if you were to use an image you can add and load it from the resource. ---------------------------------------------------------------------- vlado · 2011-10-12 08:10 Huh, thanks! Didn't know that! I thought that resources are external files, but it seems that they are inside .exe.