当我释放画布时 DC 会发生什么?
在此代码中,我希望在 MyCanvas.Free
中调用 ReleaseDC
,但此代码运行良好,这是怎么回事?
TCanvas 自己的 DC 会怎样?
var GlobalDC: THandle;
procedure TForm1.FormCreate(Sender: TObject);
begin
GlobalDC:= GetDC(0);
end;
function LoopMeOften(const X, Y: Integer): TColor;
var
MyCanvas: TCanvas;
begin
MyCanvas := TCanvas.Create;
MyCanvas.Handle := GlobalDC;
Result := GetPixel(MyCanvas.Handle, X, Y);
MyCanvas.Free;
end;
In this code I would expect a call to ReleaseDC
to happen in MyCanvas.Free
, but this code runs fine, how come?
And what happens to TCanvas' own DC?
var GlobalDC: THandle;
procedure TForm1.FormCreate(Sender: TObject);
begin
GlobalDC:= GetDC(0);
end;
function LoopMeOften(const X, Y: Integer): TColor;
var
MyCanvas: TCanvas;
begin
MyCanvas := TCanvas.Create;
MyCanvas.Handle := GlobalDC;
Result := GetPixel(MyCanvas.Handle, X, Y);
MyCanvas.Free;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TCanvas
没有自己的 DC,它既不获取也不释放 DC。它的后代TControlCanvas
确实如此。来自 TCanvas.Handle 属性
TCanvas
does not have its own DC, it neither acquires nor releases a DC. Its descendantTControlCanvas
does.From TCanvas.Handle Property