如何仅捕获 Microsoft Edge 浏览器 window?
How capture only Microsoft Edge browser window?
我需要捕获 Microsoft Edge window 并尝试使用 PrintWindow
, but unfortunately it doesn't work。然后,现在我想尝试使用 Canvas.CopyRect
api.
我已尝试使用以下代码,但导致 访问冲突 在线错误显示在下面的屏幕截图中:
procedure ScreenShotWindow;
var
c: TCanvas;
r, t: TRect;
h: THandle;
Bild: TBitMap;
begin
c := TCanvas.Create;
h := FindWindow(nil, 'Microsoft Edge');
c.Handle := GetWindowDC(h);
GetWindowRect(h, t);
try
r := Rect(0, 0, t.Right - t.Left, t.Bottom - t.Top);
Bild.Width := t.Right - t.Left; { <-- Access Violation Here }
Bild.Height := t.Bottom - t.Top;
Bild.Canvas.CopyRect(r, c, t);
Bild.SaveToFile('test'+ RandomPassword(10)+'.bmp');
finally
ReleaseDC(0, c.Handle);
c.Free;
end;
end;
我仍然不知道修复此代码后是否可以捕获 Microsoft Edg,所以如果有人知道某种可行的方法,也请告诉我 :D。
您尚未在代码中创建 Bild
。这需要先创建,然后才能使用它(并在完成后销毁)。
procedure ScreenShotWindow;
var
c: TCanvas;
r, t: TRect;
h: THandle;
Bild: TBitMap;
begin
c := TCanvas.Create;
h := FindWindow(nil, 'Microsoft Edge');
c.Handle := GetWindowDC(h);
GetWindowRect(h, t);
try
r := Rect(0, 0, t.Right - t.Left, t.Bottom - t.Top);
Bild := TBitMap.Create;
try
Bild.Width := t.Right - t.Left;
Bild.Height := t.Bottom - t.Top;
Bild.Canvas.CopyRect(r, c, t);
Bild.SaveToFile('test'+ RandomPassword(10)+'.bmp');
finally
Bild.Free;
end;
finally
ReleaseDC(0, c.Handle);
c.Free;
end;
end;
我需要捕获 Microsoft Edge window 并尝试使用 PrintWindow
, but unfortunately it doesn't work。然后,现在我想尝试使用 Canvas.CopyRect
api.
我已尝试使用以下代码,但导致 访问冲突 在线错误显示在下面的屏幕截图中:
procedure ScreenShotWindow;
var
c: TCanvas;
r, t: TRect;
h: THandle;
Bild: TBitMap;
begin
c := TCanvas.Create;
h := FindWindow(nil, 'Microsoft Edge');
c.Handle := GetWindowDC(h);
GetWindowRect(h, t);
try
r := Rect(0, 0, t.Right - t.Left, t.Bottom - t.Top);
Bild.Width := t.Right - t.Left; { <-- Access Violation Here }
Bild.Height := t.Bottom - t.Top;
Bild.Canvas.CopyRect(r, c, t);
Bild.SaveToFile('test'+ RandomPassword(10)+'.bmp');
finally
ReleaseDC(0, c.Handle);
c.Free;
end;
end;
我仍然不知道修复此代码后是否可以捕获 Microsoft Edg,所以如果有人知道某种可行的方法,也请告诉我 :D。
您尚未在代码中创建 Bild
。这需要先创建,然后才能使用它(并在完成后销毁)。
procedure ScreenShotWindow;
var
c: TCanvas;
r, t: TRect;
h: THandle;
Bild: TBitMap;
begin
c := TCanvas.Create;
h := FindWindow(nil, 'Microsoft Edge');
c.Handle := GetWindowDC(h);
GetWindowRect(h, t);
try
r := Rect(0, 0, t.Right - t.Left, t.Bottom - t.Top);
Bild := TBitMap.Create;
try
Bild.Width := t.Right - t.Left;
Bild.Height := t.Bottom - t.Top;
Bild.Canvas.CopyRect(r, c, t);
Bild.SaveToFile('test'+ RandomPassword(10)+'.bmp');
finally
Bild.Free;
end;
finally
ReleaseDC(0, c.Handle);
c.Free;
end;
end;