Converting the Desktop into a BitMap
Copy whatever is available from the background and paste it in a form.
Step 1:
Create the Procedure to paste a bitmap in a form.

procedure CopyDeskTop(Destination: TForm);
const
  //Image Size
  X = 100;
  Y = 100;
var
  Dc, MemDc, Image: THandle;
begin
  //Set up Device Contexts for DeskTop
  Dc := GetDc(0);
  MemDC := CreateCompatibleDC(DC);
  Image := SelectObject(MemDC, CreateCompatibleBitmap(Dc, X, Y));
  BitBlt(MemDC, 0, 0, X, Y, DC, 0, 0, MergeCopy);
  Image := SelectObject(MemDC, Image);
  //Remove Device Contexts
  DeleteDC(MemDC);
  ReleaseDC(0, DC);
  //Prepare Form
  Dc := GetDc(Destination.Handle);
  MemDC := CreateCompatibleDC(DC);
  Image := SelectObject(MemDC, Image);
  //Display in new location
  BitBlt(DC, 0, 0, X, Y, MemDC, 0, 0, MergeCopy);
  //Delete Bitmap
  Image := SelectObject(MemDC, Image);
  DeleteObject(Image);
  //Remove Device Contexts
  DeleteDC(MemDC);
  ReleaseDC(Destination.Handle, DC);
end;

Step 2:
Use the Procedure

procedure TForm1.Button1Click(Sender: TObject);
begin
  CopyDeskTop(Self);
end;

Notes:
  • Experimentally, using GetDeskTopWindow had the same results as 0 so I left 0 for simplicity. In theory, GetDeskTopWindow is better than 0.
  • Note that the image will disappear if the form is repainted.
Home