301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
|
//----------------------------------------------------------------------------
function ScreenShot: tBitmap;
var r: tRect;
begin
r := rect( 0, 0, 0, 0 );
result := ScreenShot( 0, r )
end;
//----------------------------------------------------------------------------
function ScreenShot( clip: tRect ): tBitmap;
begin
result := ScreenShot( 0, clip )
end;
//----------------------------------------------------------------------------
function ScreenShot( win: hWnd ): tBitmap;
var r: tRect;
begin
r := rect( 0, 0, 0, 0 );
result := ScreenShot( win, r )
end;
//----------------------------------------------------------------------------
function ScreenShot( win: hWND; clip: tRect ): tBitmap;
var
dc: hDC;
r: tRect;
begin
// Get the device context and window size
if win = 0
then begin // entire desktop
win := GetDesktopWindow;
dc := GetDC( win );
r.left := 0;
r.top := 0;
r.right := GetDeviceCaps( dc, HORZRES );
r.bottom := GetDeviceCaps( dc, VERTRES )
end
else begin // specific window
dc := GetWindowDC( win );
GetWindowRect( win, r );
dec( r.right, r.left );
dec( r.bottom, r.top );
r.left := 0;
r.top := 0
end;
try
// Clip the specified rects --> r
if not IsRectEmpty( clip ) then
if not IntersectRect( r, r, clip )
then RaiseLastOSError;
// Create and fill the result
result := tBitmap.create;
try
result.width := r.right -r.left;
result.height := r.bottom -r.top;
if not BitBlt(
result.canvas.handle,
0,
0,
result.width,
result.height,
dc,
r.left,
r.top,
SRCCOPY
) then RaiseLastOSError
except result.free; raise end
finally ReleaseDC( win, dc ) end
end;
|