别处找的,没试,成功后,别忘了高速一声.[
]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DXDraws, StdCtrls, StopWatch, DXClass,DIB, DXTexImg, DirectX,csintf;
type
TForm1 = class(TForm)
DXDraw1: TDXDraw;
StopWatch1: TStopWatch;
DXTimer1: TDXTimer;
procedure DXDraw1InitializeSurface(Sender: TObject);
procedure DXDraw1FinalizeSurface(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
FSurface:TDirectDrawSurface;
ScrDC:HDC;
i:Integer;
WW,HH:Integer;
mPos:TPoint;
posX,posY:Integer;
implementation
uses
unit2;
{$R *.DFM}
procedure TForm1.DXDraw1InitializeSurface(Sender: TObject);
begin
FSurface:=TDirectDrawSurface.Create(DXDraw1.DDraw);
//WW:=DXDraw1.Width;
//HH:=DXDraw1.Height;
WW:=640;
HH:=480;
FSurface.SetSize(WW,HH);
FSurface.SystemMemory:=true;
posX:=(fsurface.Width -DXDraw1.Width) div 2;
posY:=(FSurface.Height-DXDraw1.Height) div 2;
fsurface.Fill(0);
ScrDC:=getDC(0);
{ DXDraw1.Primary.SetSize(WW,HH);
DXDraw1.Primary.Fill(20);}
end;
procedure TForm1.DXDraw1FinalizeSurface(Sender: TObject);
begin
FSurface.Free;
FSurface:=nil;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DXTimer1.Enabled:=False;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
DXTimer1.Enabled:=True;
end;
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
var
SurfaceDESC:TDDSurfaceDesc;
begin
GetCursorPos(mPos);
//DXTimer1.Enabled:=False;
{ DXDraw1.Primary.Lock(SurfaceDESC);
unit2.showimg(SurfaceDesc.lpSurface,WW*HH*2);
DXDraw1.Primary.UnLock;
//}
FSurface.Fill(11);
BitBlt(FSurface.Canvas.Handle,0,0,WW,HH,ScrDC,mPos.x-WW div 2,mPos.y-HH div 2,SRCCOPY);
FSurface.Canvas.Textout(posX+5, posY+5,IntToStr(fsurface.Width)+' '+IntToStr(FSurface.Height));
FSurface.Canvas.TextOut(posX+5,posY+20,'FPS: '+IntToStr(DXTimer1.FrameRate));
FSurface.Canvas.Release;
//}
if FSurface.Lock(SurfaceDESC)=False then beep;
unit2.showimg(SurfaceDesc.lpSurface,WW*HH*2);
FSurface.UnLock;
//)
if DXDraw1.CanDraw then
begin
DXDraw1.Surface.Draw(0,0, Rect(posX,posY,posX+DXDraw1.Width,posY+DXDraw1.Height),FSurface,false);
//DXDraw1.Surface.StretchDraw(Rect(0,0,DXDraw1.Width,DXDraw1.Height), Rect(posX-200,posY-200,posX+DXDraw1.Width+200,posY+DXDraw1.Height+200),FSurface,false);
{ DXDraw1.Surface.Canvas.TextOut(5,50,'FPS: '+IntToStr(DXTimer1.FrameRate));
DXDraw1.surface.Canvas.release;}
DXDraw1.Flip;
end; //}
end;
end.