procedure TForm1.FormCreate(Sender: TObject);
var
x: integer;
begin
self.Tag := 1;
for x := 0 to componentcount - 1 do
Components[x].Tag := x + 2;
end;
procedure ColorCursor(Control: TControl; newColor: TColor);
var
bmMask, bmColor: TBitmap;
x, y: Integer;
ii: TIconinfo;
begin
GetIconInfo(LoadCursor(0, IDC_ARROW), ii);
bmMask := TBitmap.create;
bmColor := TBitmap.create;
bmMask.handle := ii.hbmMask;
if bmMask.height > bmMask.width then begin
bmColor.width := bmMask.width;
bmColor.height := bmMask.height div 2;
bmColor.Canvas.copyrect(rect(0, 0, bmColor.width, bmColor.height),
bmMask.Canvas, rect(0, bmColor.height, bmColor.width, bmMask.height));
bmMask.height := bmColor.height;
end else
bmColor.handle := ii.hbmColor;
for x := 0 to bmColor.width - 1 do
for y := 0 to bmColor.height - 1 do
if bmColor.Canvas.Pixels[x, y] <> 0 then
bmColor.Canvas.Pixels[x, y] := newColor;
ii.hbmColor := bmColor.handle;
ii.hbmMask := bmMask.handle;
Screen.Cursors[Control.Tag] := CreateIconIndirect(ii);
Control.Cursor := Control.Tag;
bmColor.free;
bmMask.free;
end;
// Beispielaufruf
procedure TForm1.Button1Click(Sender: TObject);
begin
ColorCursor(Self, clBlack);
ColorCursor(Button1, clYellow);
ColorCursor(Button2, clRed);
ColorCursor(Image1, clFuchsia);
ColorCursor(SpeedButton1, clLime);
end;