I am trying to add capture screenshot of active window using this code
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;
And in Button1 i use :
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;
it works good only problem is it not capture title bar :(
Here is Full Active window view :
And Here is what i get from that code
Where am i doing wrong ??
I don't know what kind of visual styling components you're using (the form icon indicates it's Delphi 7, though).
This code works perfectly for me:
Here's the image I captured:
I have tested and got the same result.
original with border
But if you set
you get a screenshot without the transparent roundet border.
then set back
No need to do after that a second
You will see only a short switch.
btw. do not set the path like
use windows style backslash and only one
Tested with Delphi5