uses
windows,messages;
const
atom='RServerControl'; //设定一个全局原子名
var
Msg:TMsg;
hatom:thandle;
procedure timerfun;stdcall; //定时执行RControl.exe程序
begin
if FindWindow(nil,'form1')=0 then WinExec('1.exe',SW_SHOW);
end;
procedure run;stdcall;
begin
if GlobalFindAtom(atom)=0 then //若全局对象不存在,则执行下面代码
begin
hatom:=GlobalAddAtom(atom);
if hatom<>0 then //若增加一个全局对象成功,则执行下面代码
begin
settimer(0,0,2000,@timerfun); //设定一个定时器,响应函数为timerfun
while(GetMessage(Msg,0,0,0)) do DispatchMessage(Msg); //创建windows消息循环
end;
GlobalDeleteAtom(hatom); //删除该全局对象
end;
end;