Google code search returns the following:
Code:
procedure MakeDesktopScreenshot( const FN : string );
var
DesktopDC : HDC;
myBitmap : TBitmap;
ScreenHandle : HWND;
begin
myBitmap := TBitmap.Create;
try
ScreenHandle := GetDesktopWindow;
DesktopDC := GetDC( ScreenHandle );
try
myBitmap.Width := screen.Width;
myBitmap.Height := screen.Height;
BitBlt( myBitmap.Canvas.Handle, 0, 0, screen.Width, screen.Height, DesktopDC, 0, 0, SRCCOPY );
if ( FN <> '' ) then
myBitmap.SaveToFile( FN )
else
Clipboard.Assign( myBitmap );
finally
ReleaseDC( ScreenHandle, DesktopDC );
end;
finally
myBitmap.Free;
end;
end; // MakeDesktopScreenshot
procedure MakeFormScreenshot(hWindow: HWND; const Filename : string );
var
Left, Top, Width, Height: Word;
R: TRect;
dc: HDC;
lpPal: PLOGPALETTE;
BM : TBitmap;
begin
{Check if valid window handle}
if not IsWindow(hWindow) then Exit;
{Retrieves the rectangular coordinates of the specified window}
GetWindowRect(hWindow, R);
Left := R.Left;
Top := R.Top;
Width := R.Right - R.Left;
Height := R.Bottom - R.Top;
{get the screen dc}
dc := GetDc(0);
if (dc = 0) then
exit;
BM := TBitmap.Create;
try
bm.Width := Width;
bm.Height := Height;
{do we have a palette device?}
if (GetDeviceCaps(dc, RASTERCAPS) and
RC_PALETTE = RC_PALETTE) then
begin
{allocate memory for a logical palette}
GetMem(lpPal,
SizeOf(TLOGPALETTE) +
(255 * SizeOf(TPALETTEENTRY)));
{zero it out to be neat}
FillChar(lpPal^,
SizeOf(TLOGPALETTE) +
(255 * SizeOf(TPALETTEENTRY)),
#0);
{fill in the palette version}
lpPal^.palVersion := $300;
{grab the system palette entries}
lpPal^.palNumEntries :=
GetSystemPaletteEntries(dc,
0,
256,
lpPal^.palPalEntry);
if (lpPal^.PalNumEntries <> 0) then
begin
{create the palette}
bm.Palette := CreatePalette(lpPal^);
end;
FreeMem(lpPal, SizeOf(TLOGPALETTE) +
(255 * SizeOf(TPALETTEENTRY)));
end;
{copy from the screen to the bitmap}
BitBlt(bm.Canvas.Handle,
0,
0,
Width,
Height,
Dc,
Left,
Top,
SRCCOPY);
{release the screen dc}
ReleaseDc(0, dc);
BM.SaveToFile( Filename );
finally
BM.Free;
end;
end;
Haven't tried it, as usually I just include it in my games via a quick key.
Bookmarks