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;
   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 );

   { ... }


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.

Who is Participating?
MatveyConnect With a Mentor Commented:
OK, sorry for not asking permition, but I hope you'll agree that there is no need for this question to stay open anymore...
Glad to help, Matvey
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
Try Forrm.GetFormImage, it returns a bitmap that contains your form.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Levente, did you try Matvey's suggestion? Form.GetFormImage...
LeventeAuthor Commented:
Hi Matvey and Zifnab,

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

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.