在VCL中很容易通过Screen.Cursors加载自定义cursor,但在FMX中,cursor是通过IFMXCursorService管理的,只支持系统默认的cursor。如果要加载自定义的cursor,我们需要替换平台默认实现的IFMXCursorService。
Windows平台源码如下:
unit uWinCursorService;
interface
uses FMX.Platform, System.UITypes, FMX.Types, Winapi.Windows, System.Generics.Collections;
type
TWinCursorService = class(TInterfacedObject, IFMXCursorService)
private class var
FWinCursorService: TWinCursorService;
FOldCursorService: IFMXCursorService;
FCursors: TList<HCURSOR>;
protected
class constructor Create;
class destructor Destroy;
procedure SetCursor(const ACursor: TCursor);
function GetCursor: TCursor;
public
class function AddCursor(const AFileName: string): Integer;
end;
implementation
uses System.SysUtils;
{ TWinCursorService }
class constructor TWinCursorService.Create;