Delphi编程中实现动画鼠标
新建一个工程,在FORM1上放一个BUTTON1,再找一个动画光标文件*.ANI,你可以到网上下载一个,也可从一些光盘中找一个(如:查找*.ANI文件),然后输入以下代码:
unit CURSOR;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
Type TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private { Private declarations }
public { Public declarations }
end;
var
Form1: TForm1;
HOLDCURSOR:HCURSOR; ′定义一个变量
Implementation {$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
VAR
HNEWCURSOR:HCURSOR;
begin
BUTTON1.CAPTION:=′关闭′;
HNEWCURSOR:=LOADCURSORFROMFILE(′E:\BATMAN.ANI′);
{调用API函数装载动画光标文件,ANI文件路径请根据自己的实际情况进行调整}
HOLDCURSOR:=SETCLASSLONG(FORM1.HANDLE,GCL_HCURSOR,HNEWCURSOR);
{把原光标储存起来以备以后的恢复}
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
HOLDCURSOR:=SETCLASSLONG(FORM1.HANDLE,GCL_HCURSOR,HOLDCURSOR);
CLOSE(); {在结束程序前一定不要忘记恢复光标}
end;
end.
现在你运行一下(按F9),启动后光标就变成动画光标了。