捕捉图片死机:
并不是内存泄漏,因为我检测内存正常。
如果我在捕捉程序界面图片的时候,频繁操作其他窗口,会导致程序界面死机。
我的代码:
C:=TCanvas.Create;
B:=TBitmap.Create ;
Hand:= GetForegroundWindow();
if hand=0 then exit;
H:=GetWindowDC(Hand); //取得这个窗口的句柄
try
GetWindowRect(hand,R); //取得这个窗口的大小,将其赋给位图对象
B.Width:=(R.Right-R.Left);
B.Height:=(R.Bottom-R.Top);
C.Handle:=H;
B.Canvas.CopyRect(Rect(0,0,B.Width,B.Height),C
,Rect(0,0,B.Width,B.Height));
B.SaveToFile(extractfiledir(application.ExeName)+'\1.bmp');
finally
C.Free;
B.Free;
ReleaseDC(Hand, H);
end;
并不是内存泄漏,因为我检测内存正常。
如果我在捕捉程序界面图片的时候,频繁操作其他窗口,会导致程序界面死机。
我的代码:
C:=TCanvas.Create;
B:=TBitmap.Create ;
Hand:= GetForegroundWindow();
if hand=0 then exit;
H:=GetWindowDC(Hand); //取得这个窗口的句柄
try
GetWindowRect(hand,R); //取得这个窗口的大小,将其赋给位图对象
B.Width:=(R.Right-R.Left);
B.Height:=(R.Bottom-R.Top);
C.Handle:=H;
B.Canvas.CopyRect(Rect(0,0,B.Width,B.Height),C
,Rect(0,0,B.Width,B.Height));
B.SaveToFile(extractfiledir(application.ExeName)+'\1.bmp');
finally
C.Free;
B.Free;
ReleaseDC(Hand, H);
end;
我试着调整过截图频率,频率慢现象会不是那么明显