From: ZeppinHood Subject: Re: PLEASE HELP ME Date: 02 Jul 1999 00:00:00 GMT Message-ID: <377D20AE.4AD3@badsector.com> Content-Transfer-Encoding: 7bit References: <377CA07D.A8678F8A@compuletra.com.br> To: Gustavo Becker Content-Type: text/plain; charset=us-ascii Organization: ZeppinHood's Lair Mime-Version: 1.0 Reply-To: zeppinhood@badsector.com Newsgroups: borland.public.delphi.graphics Gustavo Becker wrote: > > Hi,. > I need to capture a part of a form and print it on a printer. I would > have to do some kind of "screen capture" like an ALT + PRINT SCREEN > followed with a cut off of a determined form area. Then I'll print this > image. The form area contains two OCX. These OCX don't have a > CopyToClipboard method or similar methods. > Could someone in the world halp me? > Gustavo Becker > gpbecker@compuletra.com.br procedure 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 begin exit; end; bm.Width := Width; bm.Height := Height; {get the screen dc} dc := GetDc(0); if (dc = 0) then begin exit; end; {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, x, y, SRCCOPY); {release the screen dc} ReleaseDc(0, dc); end; Joe Hecht