我做了个小程序,有你类似的功能:以下是部分代码:
procedure TSprite.SaveBackGround();
var
SC:TCanvas;
begin
SetWindowPos(FormMain.Handle,HWND_BOTTOM,FormMain.Left,FormMain.Top,FormMain.Width,FormMain.Height,SWP_HIDEWINDOW);
SC:=TCanvas.Create;
try
SC.Handle:=GetDC(0);
FOldBmp.Canvas.CopyRect(Rect(0,0,SPWIDTH,SPHEIGHT),SC,Rect(FPosition.X,FPosition.Y,FPosition.X+SPWIDTH,FPosition.Y+SPHEIGHT));
FNewBmp.Assign(FOldBmp);
ReleaseDC(0,Sc.Handle);
finally
SC.Free;
end;
FormMain.Canvas.Draw(0,0,FOldBmp);//this line here let the form be transparent when the form create
SetWindowPos(FormMain.Handle,HWND_TOPMOST,FormMain.Left,FormMain.Top,FormMain.Width,FormMain.Height,SWP_NOMOVE+SWP_SHOWWINDOW);
end;
procedure TSprite.Paint(X,Y:integer;Image:TBitmap);
function XslateRect(R:Trect;X,Y:integer):TRect;
begin
with R do Result:=Rect(Left-X,Top-Y,Right-X,Bottom-Y);
end;//XslateRect(R:Trect;X,Y:integer):TRect;
var
SC:TCanvas;
OrgRect,OldRect,NewRect,TmpRect:TRect;
OldRgn,NewRgn,TmpRgn:HRgn;
TmpWindow:Hwnd;
begin
OrgRect:=Rect(0,0,SPWIDTH,SPHEIGHT);
OldRect:=Rect(FPosition.X,FPosition.Y,FPosition.X+SPWIDTH,FPosition.Y+SPHEIGHT);
NewRect:=Rect(X,Y,X+SPWIDTH,Y+SPHEIGHT);
OldRgn:=CreateRectRgnIndirect(OldRect);
NewRgn:=CreateRectRgnIndirect(NewRect);
TmpRgn:=CreateRectRgnIndirect(OldRect);
TmpWindow:=GetForeGroundWindow();
if (TopWindow<>TmpWindow) and (TmpWindow<>FormMain.Handle) and (TmpWindow<>Application.Handle) then begin
SaveBackground();
TopWindow:=TmpWindow;
end;
try
SC:=TCanvas.Create();
try
SC.Handle:=GetDC(0);
FNewBmp.Canvas.CopyRect(OrgRect,SC,NewRect);
CombineRgn(TmpRgn,NewRgn,OldRgn,RGN_AND);
GetRgnBox(TmpRgn,TmpRect);
FNewBmp.Canvas.CopyRect(XslateRect(OldRect,X,Y),FOldBmp.Canvas,OrgRect);
FOldBmp.Canvas.CopyRect(OrgRect,FNewBmp.Canvas,OrgRect);
FNewBmp.Canvas.Draw(0,0,Image);
FormMain.Canvas.Draw(0,0,FNewBmp);
ReleaseDC(0,SC.Handle);
finally
SC.Free;
end;
finally
DeleteObject(TmpRgn);
DeleteObject(NewRgn);
DeleteObject(OldRgn);
end;
FPosition.X:=X;FPosition.Y:=Y;
end;//Paint(X,Y:integer;Image:TBitmap);
你也可以写信给我,我把完整程序给你。。