Solution to putting rich text into a bitmap


2003-11-14 11:18:57 PM
delphi225
For those who are interested, here is a solution to the problem I posed in
my 11/5/2003 post. The solution described there gives me a canvas but no
text in the bitmap. Here are two functions that solve the problem:
function CaptureScreenRect( ARect: TRect ): TBitmap;
// Capture a rectangle on the screen
var
ScreenDC: HDC;
begin
Result := TBitmap.Create;
with Result, ARect do
begin
Width := Right - Left;
Height := Bottom - Top;
ScreenDC := GetDC( 0 );
try
BitBlt( Canvas.Handle, 0, 0, Width, Height, ScreenDC,
Left, Top, SRCCOPY );
finally
ReleaseDC( 0, ScreenDC );
end;
end;
end; //CaptureScreenRect
function CaptureControlImage( Control: TControl ): TBitmap;
// Capture an entire form or control
begin
with Control do
if Parent = nil then
Result := CaptureScreenRect( Bounds( Left, Top, Width,
Height ))
else
with Parent.ClientToScreen( Point( Left, Top )) do
Result := CaptureScreenRect( Bounds( X, Y, Width,
Height ));
end; //CaptureControlImage