The cursor obtained by using Loadcursor() in Delphi is only black and white. How to get a colored cursor in the program? The author tried to create the following program:
Method 1: Use Loadcursorfromfile() to load the icon as the cursor from the outside
The Loadcursorfromfile() function can read files with the suffix *CUR, *ICO, and *ANI as cursors, where ICO is a color icon format (can be produced with Image Editor), and ANI is an animated cursor format. The following is a demonstration program segment that opens an icon as a cursor. When the cursor moves to the test area, the cursor will change to the selected pattern;
{Suppose: opendialog1:Topendialog;Bitbtn1:Tbitbtn}
PRocedure TForm1.BitBtn1Click(Sender:TObject);
var tt:pchar;size:integer;s:string;
begin
if opendialog1.Execute then
begin
size:=length(opendialog1.filename);
getmem(tt,size);
s:=opendialog1.filename;
strpcopy(tt,s);
screen.cursors[2]:=loadcursorfromfile(tt);
bf.cursor:=2;
freemem(tt,size);
end;
end;
Method 2: Load colored cursor from resource file
The *CUR file must be included when sending the program using method 1, so loading the colored cursor from the resource file is a more feasible method. Use an icon to store the colored cursor, store the icon in a temporary file when using it, and use Loadcursorfromfile() to read the colored cursor from the temporary file.
Program segment:
procedure ZloadfromResourse(screenindex:integer;name:Pchar);
var td:ticon;
begin
try
td:=ticon.Create;
td.Handle:=LoadIcon(Hinstance,name);
td.SaveToFile(′temp.cur′);
screen.Cursors[screenindex]:=loadcursorfromfile(′temp.cur′);
deletefile(′temp.cur′);
finally
td.free;
end;
end;
This program changes the icon named name into the cursor with the serial number screenindex;
example:
ZloadfromResourse(2,′myicon′);
Form1.cursor:=2;