I want to draw a screenshot from the entire screen onto the TForm1 canvas.
This code works well in Delphi XE3
procedure TForm1.Button1Click(Sender: TObject); var c,scr: TCanvas; r,r2: TRect; begin c := TCanvas.Create; scr := TCanvas.Create; c.Handle := GetWindowDC(GetDesktopWindow); try r := Rect(0, 0, 200, 200); form1.Canvas.CopyRect(r, c, r); finally ReleaseDC(0, c.Handle); c.Free; end;
Now I want to first copy the screenshot to another canvas. Is there any way to do this without getting this error?
procedure TForm1.Button1Click(Sender: TObject); var c,scr: TCanvas; r,r2: TRect; begin c := TCanvas.Create; scr := TCanvas.Create; c.Handle := GetWindowDC(GetDesktopWindow); try r := Rect(0, 0, 200, 200); scr.CopyRect(r,c,r); <-- Error, canvas does not allow drawing form1.Canvas.CopyRect(r, scr, r); <-- Error, canvas does not allow drawing finally ReleaseDC(0, c.Handle); c.Free; end;
source share