跟随鼠标移动的图像 Delphi / Windows SDK/APIhttp://www.delphi2007.net/DelphiAPI/html/delphi_20061120102940195.html
一个图片跟随鼠标移动,
要求是不能用窗体跟随鼠标的方法,只能在屏幕上画图,鼠标移动后,擦除图像,根据新位置在画,
高手来
//参考如下代码
type
TForm1 = class(TForm)
Timer1: TTimer;
Image1: TImage;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FRect: TRect;
FBitmap: TBitmap;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
var
vDesktopCanvas: TCanvas;
begin
if (FRect.Left = Mouse.CursorPos.X) and (FRect.Top = Mouse.CursorPos.Y) then // 鼠标没有移动
Exit;
vDesktopCanvas := TControlCanvas.Create;
with vDesktopCanvas do try
Handle := GetWindowDC(GetDesktopWindow);
if FRect.Left >= 0 then Draw(FRect.Left, FRect.Top, FBitmap); // 恢复上次屏幕
FRect := Bounds(Mouse.CursorPos.X, Mouse.CursorPos.Y,
Image1.Picture.Width, Image1.Picture.Height);
FBitmap.Canvas.CopyRect(FBitmap.Canvas.ClipRect, vDesktopCanvas, FRect); // 保存本次绘制
Draw(FRect.Left, FRect.Top, Image1.Picture.Graphic);
finally
vDesktopCanvas.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Interval := 10;
FBitmap := TBitmap.Create;
FBitmap.Width := Image1.Picture.Width;
FBitmap.Height := Image1.Picture.Height;
FRect.Left := -1;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FBitmap.Free;
end;
抢分!
伴水占了位置,过来接分。
。。。。。。。
文章来源:
http://www.delphi2007.net/DelphiAPI/html/delphi_20061120102940195.html