R
rackrain
Unregistered / Unconfirmed
GUEST, unregistred user!
根据别人的程序改的,原程序是截桌面的,有效,改成截游戏的两面就变成黑的,源程序如下,是那里有问题,请大家看一下。谢谢。采用directx的D9.pas
procedure TForm1.Button1Click(Sender: TObject);
var
BitsPerPixel: Byte;
pD3D: IDirect3D9;
pSurface: IDirect3DSurface9;
g_pD3DDevice: IDirect3DDevice9;
D3DPP: TD3DPresentParameters;
ARect,t: TRect;
LockedRect: TD3DLockedRect;
BMP: TBitmap;
i, p: Integer;
h:Thandle;
begin
h:=findwindow(nil,'aaa');
// h:=GetDesktopWindow;
GetWindowRect(h,t);
BitsPerPixel := GetDeviceCaps(Canvas.Handle, BITSPIXEL);
FillChar(d3dpp, SizeOf(d3dpp), 0);
D3DPP.Windowed := True;
D3DPP.Flags := D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
D3DPP.SwapEffect := D3DSWAPEFFECT_DISCARD;
D3DPP.BackBufferWidth := t.Right-t.Left;
D3DPP.BackBufferHeight := t.Bottom-t.Top;
D3DPP.BackBufferFormat := D3DFMT_X8R8G8B8;
pD3D := Direct3DCreate9(D3D_SDK_VERSION);
pD3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, h,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, @D3DPP, g_pD3DDevice);
g_pD3DDevice.CreateOffscreenPlainSurface(t.Right-t.Left, t.Bottom-t.Top, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, pSurface, nil);
g_pD3DDevice.GetFrontBufferData(0, pSurface);
// use D3D to save surface. Notes: D3DX%ab.dll is required!
// D3DXSaveSurfaceToFile('Desktop.bmp', D3DXIFF_BMP, pSurface, nil, nil);
// use Bitmap to save surface
//ARect :=t;
ARect:=Rect(0,0,t.Right-t.Left,t.Bottom-t.Top);
//arect:=Screen.DesktopRect;
pSurface.LockRect(LockedRect, @ARect, D3DLOCK_NO_DIRTY_UPDATE or D3DLOCK_NOSYSLOCK or D3DLOCK_READONLY);
BMP := TBitmap.Create;
BMP.Width := t.Right-t.Left;
BMP.Height := t.Bottom-t.Top;
case BitsPerPixel of
8: BMP.PixelFormat := pf8bit;
16: BMP.PixelFormat := pf16bit;
24: BMP.PixelFormat := pf24bit;
32: BMP.PixelFormat := pf32bit;
end;
p := Cardinal(LockedRect.pBits);
for i := 0 to (t.Bottom-t.Top) - 1 do
begin
CopyMemory(BMP.ScanLine, Ptr(p), (t.Right-t.Left) * BitsPerPixel div 8);
p := p + LockedRect.Pitch;
end;
//BMP.SaveToFile('Desktop.bmp');
image1.Picture.Bitmap:=bmp;
BMP.Free;
pSurface.UnlockRect;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
BitsPerPixel: Byte;
pD3D: IDirect3D9;
pSurface: IDirect3DSurface9;
g_pD3DDevice: IDirect3DDevice9;
D3DPP: TD3DPresentParameters;
ARect,t: TRect;
LockedRect: TD3DLockedRect;
BMP: TBitmap;
i, p: Integer;
h:Thandle;
begin
h:=findwindow(nil,'aaa');
// h:=GetDesktopWindow;
GetWindowRect(h,t);
BitsPerPixel := GetDeviceCaps(Canvas.Handle, BITSPIXEL);
FillChar(d3dpp, SizeOf(d3dpp), 0);
D3DPP.Windowed := True;
D3DPP.Flags := D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
D3DPP.SwapEffect := D3DSWAPEFFECT_DISCARD;
D3DPP.BackBufferWidth := t.Right-t.Left;
D3DPP.BackBufferHeight := t.Bottom-t.Top;
D3DPP.BackBufferFormat := D3DFMT_X8R8G8B8;
pD3D := Direct3DCreate9(D3D_SDK_VERSION);
pD3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, h,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, @D3DPP, g_pD3DDevice);
g_pD3DDevice.CreateOffscreenPlainSurface(t.Right-t.Left, t.Bottom-t.Top, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, pSurface, nil);
g_pD3DDevice.GetFrontBufferData(0, pSurface);
// use D3D to save surface. Notes: D3DX%ab.dll is required!
// D3DXSaveSurfaceToFile('Desktop.bmp', D3DXIFF_BMP, pSurface, nil, nil);
// use Bitmap to save surface
//ARect :=t;
ARect:=Rect(0,0,t.Right-t.Left,t.Bottom-t.Top);
//arect:=Screen.DesktopRect;
pSurface.LockRect(LockedRect, @ARect, D3DLOCK_NO_DIRTY_UPDATE or D3DLOCK_NOSYSLOCK or D3DLOCK_READONLY);
BMP := TBitmap.Create;
BMP.Width := t.Right-t.Left;
BMP.Height := t.Bottom-t.Top;
case BitsPerPixel of
8: BMP.PixelFormat := pf8bit;
16: BMP.PixelFormat := pf16bit;
24: BMP.PixelFormat := pf24bit;
32: BMP.PixelFormat := pf32bit;
end;
p := Cardinal(LockedRect.pBits);
for i := 0 to (t.Bottom-t.Top) - 1 do
begin
CopyMemory(BMP.ScanLine, Ptr(p), (t.Right-t.Left) * BitsPerPixel div 8);
p := p + LockedRect.Pitch;
end;
//BMP.SaveToFile('Desktop.bmp');
image1.Picture.Bitmap:=bmp;
BMP.Free;
pSurface.UnlockRect;
end;