Articles

Use GetDC function (this function returns handle of a display device context) and Handle method of Bitmap.Canvas for assigning result of GetDC function with it.

procedure TForm1.Button1Click(Sender: TObject);
var
  Bitmap, Bitmap2: TBitmap;
  ButHandle: THandle;
  Rec: TRect;
begin
  Bitmap:=TBitmap.Create;
  Bitmap2:=TBitmap.Create;
  Bitmap2.LoadFromFile('factory.bmp');
  Rec:=Rect(2, 2, Button1.Width-2, Button1.Height-2);
  ButHandle:=GetDC(Button1.Handle);
  Bitmap.Canvas.Handle:=ButHandle;
  Bitmap.Canvas.StretchDraw(Rec, Bitmap2);
end;