怎样用settimer生成计时器?
能给出例子吗? 问题点数:50、回复次数:4Top
1 楼cg1120(代码最优化-§惟坚韧者始能遂其志§)回复于 2003-02-01 13:26:04 得分 25
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.
Top
2 楼sssa2000()回复于 2003-02-01 21:57:24 得分 0
能解释一下settimer的几个参数的具体含义吗,Top
3 楼sssa2000()回复于 2003-02-04 15:10:32 得分 0
能解释一下settimer的几个参数的具体含义吗,
Top
4 楼softboysxp(fiNAL.Y)回复于 2003-02-05 14:15:34 得分 25
参数依次为:
1.调用函数的handle,windows会定时发送WM_TIMER消息给此handle
2.timer的标识,可设置为0
3.定时器的值,单位是毫秒
4.回调函数
个人认为:如果从窗体调用,可以用一下代码:
SetTimer(self.handle,0,50,nil)
可以省去便协会调函数的麻烦Top




