我想使用此代码德尔福活动窗口截图
procedure ScreenShot(activeWindow: bool; destBitmap : TBitmap) ;
var
w,h : integer;
DC : HDC;
hWin : Cardinal;
r : TRect;
begin
if activeWindow then
begin
hWin := GetForegroundWindow;
dc := GetWindowDC(hWin) ;
GetWindowRect(hWin,r) ;
w := r.Right - r.Left;
h := r.Bottom - r.Top;
end
else
begin
hWin := GetForegroundWindow;
dc := GetDC(hWin) ;
w := GetDeviceCaps (DC, HORZRES) ;
h := GetDeviceCaps (DC, VERTRES) ;
end;
try
destBitmap.Width := w;
destBitmap.Height := h;
BitBlt(destBitmap.Canvas.Handle,
0,
0,
destBitmap.Width,
destBitmap.Height,
DC,
0,
0,
SRCCOPY) ;
finally
ReleaseDC(hWin, DC) ;
end;
end;
而且在Button1的我使用添加活动窗口的捕捉截屏:
var
path:string;
b:TBitmap;
begin
path:= ExtractFilePath(Application.ExeName) + '/Screenshot/';
b := TBitmap.Create;
try
ScreenShot(TRUE, b) ;
b.SaveToFile(path + 'Screenshot_1.png');
finally
b.FreeImage;
FreeAndNil(b) ;
end;
end;
它做工不错唯一的问题是它不能捕捉称号巴:(
这里到处是活动窗口视图:
这里是我从该代码
如果我做错了什么?得到
参见[这个答案](HTTP测试://计算器。com/q/16700014/62576)到一个类似的问题。它应该有所帮助。 –
改为使用'GetWindowDC'。 –
@KenWhite在答案中的代码给我错误在Bitmap.SetSize(宽度,高度);说Undeclared标识符:'SetSize' – dudey