procedure TForm1.Button1Click(Sender: TObject);
var
I: integer;
b: TBitMap;
begin
fwin := True;
while True
do
begin
if fwin = FALSE
then
exit;
b := TBitMap.Create;
try
Application.ProcessMessages;
Sleep(100);
// ScreenShot(0, 0, 1364, 768, b);
Capture(1364, 768,b);
Image1.Picture.Assign(b);
finally
b.Free;
end;
end;
end;
function TForm1.Capture(Width, Height: integer;bm: TBitMap): Boolean;
var
dc: HDC;
RasterOp, ExStyle: DWORD;
begin
result := FALSE;
if ((Width = 0)
or (Height = 0))
then
exit;
bm.Width := Width;
bm.Height := Height;
RasterOp := SRCCOPY;
ExStyle := GetWindowLong(
Handle, GWL_EXSTYLE);
if (ExStyle
and WS_EX_LAYERED) = WS_EX_LAYERED
then
RasterOp := SRCCOPY
or CAPTUREBLT;
dc := GetDCEx(0, 0, DCX_WINDOW
or DCX_NORESETATTRS
or DCX_CACHE);
//dc := GetDCEx(0, 0, DCX_WINDOW or DCX_NORESETATTRS or DCX_CACHE or DCX_CLIPCHILDREN or DCX_CLIPSIBLINGS or DCX_PARENTCLIP or DCX_EXCLUDERGN or
//DCX_INTERSECTRGN or DCX_EXCLUDEUPDATE or DCX_INTERSECTUPDATE or DCX_LOCKWINDOWUPDATE or DCX_VALIDATE);
//dc := GetWindowDC(GetDesktopWindow);
if (
dc = 0)
then
exit;
try
SelectClipRgn(bm.Canvas.Handle, FRgn);
result := BitBlt(bm.Canvas.Handle, 0, 0, 1320, 768,
dc, 0, 0, RasterOp);
SelectClipRgn(bm.Canvas.Handle, 0);
finally
ReleaseDc(0,
dc);
// ReleaseDC(GetDesktopWindow, dc);
end;
end;