DELPHI 游戏后台截图黑屏,该如何处理
DELPHI 游戏后台截图黑屏
function PrintWindow(SourceWindow: hwnd; Destination: hdc; nFlags: cardinal): bool; stdcall; external 'user32.dll' name 'PrintWindow';
procedure TForm1.Button3Click(Sender: TObject);
var
bmp: TBitmap;
wnd : cardinal;
rec: TRect;
begin
wnd := FindWindow(nil,'计算器'); // 查找窗口句柄,这里用计算器演示
GetWindowRect(wnd, rec); // 获取到计算器窗口的举行
bmp := TBitmap.Create;
try
bmp.Width := rec.Right - rec.Left;
bmp.Height := rec.Bottom - rec.Top;
bmp.PixelFormat := pf24bit;
PrintWindow(wnd, bmp.Canvas.Handle, 0);
bmp.SaveToFile('cao.bmp');
finally
bmp.Free;
end;
end;
用在其它方面能正常截图,但。。。
用在游戏上截出来的是黑屏, 请问有什么办法不黑屏的
------解决方案--------------------
试试下面这个代码,定时器里面写如下代码:
uses Clipbrd;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
keybd_event(VK_SNAPSHOT, 0, 0, 0);
keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0);
if not ClipBoard.HasFormat(CF_BITMAP) then Exit;
Image1.Picture.Bitmap.LoadFromClipboardFormat(CF_BITMAP,
ClipBoard.GetAsHandle(CF_BITMAP), 0);
end;
function PrintWindow(SourceWindow: hwnd; Destination: hdc; nFlags: cardinal): bool; stdcall; external 'user32.dll' name 'PrintWindow';
procedure TForm1.Button3Click(Sender: TObject);
var
bmp: TBitmap;
wnd : cardinal;
rec: TRect;
begin
wnd := FindWindow(nil,'计算器'); // 查找窗口句柄,这里用计算器演示
GetWindowRect(wnd, rec); // 获取到计算器窗口的举行
bmp := TBitmap.Create;
try
bmp.Width := rec.Right - rec.Left;
bmp.Height := rec.Bottom - rec.Top;
bmp.PixelFormat := pf24bit;
PrintWindow(wnd, bmp.Canvas.Handle, 0);
bmp.SaveToFile('cao.bmp');
finally
bmp.Free;
end;
end;
用在其它方面能正常截图,但。。。
用在游戏上截出来的是黑屏, 请问有什么办法不黑屏的
------解决方案--------------------
试试下面这个代码,定时器里面写如下代码:
uses Clipbrd;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
keybd_event(VK_SNAPSHOT, 0, 0, 0);
keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0);
if not ClipBoard.HasFormat(CF_BITMAP) then Exit;
Image1.Picture.Bitmap.LoadFromClipboardFormat(CF_BITMAP,
ClipBoard.GetAsHandle(CF_BITMAP), 0);
end;