为何不能释放资源?看看这段代码
为何不能释放资源?看看这段代码
请指点
var
ps: PAINTSTRUCT;
DC, drawDC1, drawDC2: HDC;
drawBMP1, drawBMP2, oldBMP1, oldBMP2: HBitmap;
iWidth, iHeight, ibmpWidth, ibmpHeight, I, J, K, W: integer;
begin
FInterDrawing := True;
try
BeginPaint(Self.Handle, Ps);
try
DC := Ps.hdc;
iWidth := ClientWidth;
iHeight := ClientHeight;
drawDC1 := CreateCompatibleDC(DC);
drawBMP1 := CreateCompatibleBitmap(DC, iWidth, iHeight);
oldBMP1 := SelectObject(drawDC1, drawBMP1);
SendMessage(Handle, WM_PAINT, drawDC1, 0);
drawDC2 := CreateCompatibleDC(DC);
drawBMP2 := CreateCompatibleBitmap(DC, iWidth, iHeight);
oldBMP2 := SelectObject(drawDC2, drawBMP2);
iBmpWidth := Background.Width;
iBmpHeight := Background.Height;
K := ClientWidth div iBmpWidth;
W := ClientHeight div iBmpHeight;
for I := 0 to K do
for J := 0 to W do
BitBlt(drawDC2, I * iBmpWidth, J * iBmpHeight, iBmpWidth, iBmpHeight, Background.Canvas.Handle, 0, 0, SRCCOPY);
TransparentBlt(drawDC2, 0, 0, iWidth, iHeight, drawDC1, 0, 0, iWidth, iHeight, ColorToRGB(clWindow));
BitBlt(DC, 0, 0, iWidth, iHeight, drawDC2, 0, 0, SRCCOPY);
SelectObject(drawDC1, oldBMP1);
DeleteObject(drawBMP1);
SelectObject(drawDC2, oldBMP2);
DeleteObject(drawBMP2);
finally
ReleaseDC(self.Handle,DC);
DeleteDC(drawDC1);
DeleteDC(drawDC2);
EndPaint(Handle, Ps);
end;
finally
FInterDrawing := False;
end;