Well a quick search turns up:
delphi.about.com/od/internetintranet/l/aa012004a.htm <-- Witch points
to articles that talk about screen captures. Looking into the code we find
a method ScreenShot. Looking into this method we find that it retrieves the
Screen DC and uses that to capture a section of the (or the entire) screen.
This tells us that we can change to use our own DC GetWindowDC(form.handle)
(API reference) and then move the code that we need their. After the
modification we come up with:
procedure TForm1.ScreenShot(x : integer; y : integer; Width : integer;
Height : integer; bm : TBitMap);
var
dc: HDC; lpPal : PLOGPALETTE;
begin
{test width and height}
if ((Width = 0) OR (Height = 0)) then exit;
bm.Width := Width;
bm.Height := Height;
{get the screen dc}
dc := GetWindowDC(Form1.Handle);//replaced GetDc(0); witch pulls the
screen
if (dc = 0) then exit;
{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(TPALET{*word*249}TRY)));
{zero it out to be neat}
FillChar(lpPal^, sizeof(TLOGPALETTE) + (255 * sizeof(TPALET{*word*249}TRY)),
#0);
{fill in the palette version}
lpPal^.palVersion := $300;
{grab the system palette entries}
lpPal^.palNumEntries
:=GetSystemPalet{*word*249}tries(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(TPALET{*word*249}TRY)));
end;
{copy from the screen to the bitmap}
BitBlt(bm.Canvas.Handle,0,0,Width,Height,Dc,x,y,SRCCOPY);
{release the screen dc}
ReleaseDc(0, dc);
end; (* ScreenShot *)
That should get you started. BTW: I did answer the question that I thougth
you were asking for :). Just didn't understand you. The above code should
point you in the right direction or work straight out of the box. Haven't
tested it, but it makes sense.
One final note: The BitBlt function here (as I referenced in my first
reply) is the key, you can modify it to capture a small or the complete
section you want.
Jeremy