Library RServer;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;exports run; //输出run函数begin end.
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;exports run; //输出run函数begin
end.
1.调用函数的handle,windows会定时发送WM_TIMER消息给此handle
2.timer的标识,可设置为0
3.定时器的值,单位是毫秒
4.回调函数个人认为:如果从窗体调用,可以用一下代码:
SetTimer(self.handle,0,50,nil)
可以省去便协会调函数的麻烦