I think that DrawIconEx might be useful to help with this. With it you can simply draw the entire cursor image to a certain canvas. There is also possibility to draw the specified animated cursor frame by passing its index into the istepIfAniCur parameter. The following example shows how to save the current cursor into the stream (Button1Click) and load it back and display (Button2Click).
The other question is how to detect if the cursor is animated.
var
Stream: TMemoryStream;
procedure TForm1.FormCreate(Sender: TObject);
begin
Stream := TMemoryStream.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Stream.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Picture: TPicture;
CursorInfo: TCursorInfo;
begin
Picture := TPicture.Create;
CursorInfo.cbSize := SizeOf(CursorInfo);
GetCursorInfo(CursorInfo);
Picture.Bitmap.Transparent := True;
Picture.Bitmap.Width := GetSystemMetrics(SM_CXCURSOR);
Picture.Bitmap.Height := GetSystemMetrics(SM_CYCURSOR);
DrawIconEx(
Picture.Bitmap.Canvas.Handle, // handle to the target canvas
0, // left coordinate
0, // top coordinate
CursorInfo.hCursor, // handle to the current cursor
0, // width, 0 for autosize
0, // height, 0 for autosize
0, // animated cursor frame index
0, // flicker-free brush handle
DI_NORMAL // flag for drawing image and mask
);
Picture.Bitmap.SaveToStream(Stream);
Picture.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Picture: TPicture;
begin
Stream.Position := 0;
Picture := TPicture.Create;
Picture.Bitmap.Transparent := True;
Picture.Bitmap.Width := GetSystemMetrics(SM_CXCURSOR);
Picture.Bitmap.Height := GetSystemMetrics(SM_CYCURSOR);
Picture.Bitmap.LoadFromStream(Stream);
SetBkMode(Canvas.Handle, TRANSPARENT);
Canvas.FillRect(Rect(0, 0, 32, 32));
Canvas.Draw(0, 0, Picture.Graphic);
Picture.Free;
end;