我用线程的形式测试一下写屏好像效果还行,代码如下:
unit Unit2;
interface
uses
Classes,Windows,SyncObjs;
type
ShowTEXTToWin = class(TThread)
private
{ Private declarations }
FullscreenDC:HDC;
strText:String;
m_stop:TEvent;
procedure ShowText();
protected
procedure Execute; override;
public
constructor Create(Astop:TEvent);
end;
implementation
{ ShowTEXTToWin }
procedure ShowTEXTToWin.ShowText();
begin
FullscreenDC:=GetDC(0);
Textout(FullscreenDC,1,1,Pchar(strText),Length(strText));
end;
constructor ShowTEXTToWin.Create(Astop:TEvent);
begin
strText:='这里在测试!!';
m_stop:=Astop;
FreeOnTerminate := TRUE;
inherited Create(False);
end;
procedure ShowTEXTToWin.Execute;
begin
{ Place thread code here }
while true do
begin
ShowText();
if wrSignaled=m_stop.WaitFor(20) then break;
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,SyncObjs;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
m_stop:TEvent;
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
te:ShowTEXTToWin;
begin
te:=ShowTEXTToWin.Create(m_stop);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
m_stop.SetEvent();
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
m_stop:=TEvent.Create(NIL,TRUE,FALSE,'Stop Show TEXT');
end;
end.