Canvas do es not allow drawing...没辙了(100分)

  • 主题发起人 主题发起人 Rik
  • 开始时间 开始时间
R

Rik

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TMainForm.Timer1Timer(Sender: TObject);
var
i: Integer;
DC: HDC;
begin
GetCursorPos(JCursor);
begin
iWidth := 110;
iHeight := 110;
DirectRect := Rect(0, 0, iWidth, iHeight);
SourCerect := Rect(JCursor.X - 5, JCursor.Y - 5, JCursor.X + 6, JCursor.Y + 6);
DC:=GetDesktopWindow;
C := TCanvas.Create;
C.Handle := GetDc(DC);
try
MainImage.Canvas.CopyRect(DirectRect, C, SourCerect);
finally
ReleaseDC(C.Handle, DC);
C.Free;
end;
Application.ProcessMessages;
end;
end;

这段代码为什么会在运行一段时间后出现Canvas does not allow drawing...我也查了查,网上有说用Canvas.Lock or Canvas.TryLock解决,可我使用却没有效果。请各位帮我看看
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
MainImage: TImage;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
JCursor:tpoint;
DirectRect,SourceRect:TRect;
C:TCanvas;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
var
i: Integer;
DC: HDC;
iwidth,iheight:integer;
begin
GetCursorPos(JCursor);
begin
iWidth := 110;
iHeight := 110;
DirectRect := Rect(0, 0, iWidth, iHeight);
SourCerect := Rect(JCursor.X - 5, JCursor.Y - 5, JCursor.X + 6, JCursor.Y + 6);
DC:=GetDesktopWindow;
C := TCanvas.Create;
C.Handle := GetDc(DC);
try
MainImage.Canvas.CopyRect(DirectRect, C, SourCerect);
finally
ReleaseDC(C.Handle, DC);
C.Free;
end;
Application.ProcessMessages;
end;

end;

end.
我改写的,怎么我运行一个小时也没有出现你说的问题?
我用DELPHI6+WIN2003SEVER
 
程序运行时就只看见内存使用值不断上升。求教。。。。。
 
奇怪了,为什么在我的机器上就是这样子呢?
 
如果我的运行一天没有问题的话,你就把计算机轧了,,
我在Delphi6,Win2003 Server平台下。
C1.4G,480M内存,笔记本
 
资源耗尽
 
爱大侠:
资源耗尽我也这么想,
确实这样,资源上涨一直这样。
建议楼主
,使用BitBlt、StretchBlt,直接把屏幕的图像放到MainImage上。
 
我看了些文章,也知道是资源问题。可是怎么解决呢?郁闷
 
大概搞定了,需要在恰当位置ReleaseDC
 
多人接受答案了。
 
后退
顶部