Link to home
Start Free TrialLog in
Avatar of Levente
Levente

asked on

Get a partially covered window's canvas

Get a form's canvas ?

I need to save my form's entire canvas. Now I use the following code:

var AppDC  : HDC;
    Bitmap : TBitmap;
begin
   Bitmap := TBitmap.Create;
   Bitmap.Width := Form1.Width;
   Bitmap.Height := Form1.Height;

   AppDC := GetWindowDC( Form1.Handle );
   BitBlt( Bitmap.Canvas.Handle, 0, 0, Width, Height, AppDC, 0, 0, SRCCOPY );
   ReleaseDC( Form1.Handle, AppDC );

   { ... }

   Bitmap.Free;
end;

This code works well, BUT when another window (such as System monitor)
partially covers my form this window's canvas is also saved to my Bitmap.

How can I save my forms canvas only even if it is partially covered ?

Any help is *greatly* appreciated.

Levente
Avatar of erajoj
erajoj
Flag of Sweden image

It's not possible unless you put it on top. The window DC doesn't save any hidden information.
Set FormStyle := fsStayOnTop, take snapshot and reset FormStyle.

/// John
Avatar of Matvey
Matvey

Try Forrm.GetFormImage, it returns a bitmap that contains your form.
Levente, did you try Matvey's suggestion? Form.GetFormImage...
Avatar of Levente

ASKER

Hi Matvey and Zifnab,

Yes, I've tried it and works perfectly. I think I should 've read the TForm help thoroughly. Sorry.

Levente
ASKER CERTIFIED SOLUTION
Avatar of Matvey
Matvey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Levente

ASKER

Agreed. I was in a hurry and had no time to read the TForm help thorougly.

Levente