delphi函数定时


本文整理自网络,侵删。

 delphi中不使用timer控件,直接用settimer函数实现定时运行程序方法:
函数:
SetTimer(hWnd,ID_TIMER,1000,NULL) ;
KillTimer(hWnd,ID_TIMER) ;

参数依次为:
1.调用函数的handle,windows会定时发送WM_TIMER消息给此handle
2.timer的标识,可设置为0
3.定时器的值,单位是毫秒
4.回调函数
一般这样写:
settimer(self.handle,0,1000,@timerfun);
举例:以下为每2秒打开hao123网站
program Project2;
uses
windows,shellapi;
//===========================
procedure setrun;//自定义过程
begin
ShellExecute(0,'open','http://www.hao123.com',nil,nil,sw_ShowNormal);
end;
//===========================
var
msg: Tmsg;
begin
SetTimer(0, 0, 2000, @setrun); //定时间器,2秒钟运行一次
while GetMessage(msg, 0, 0, 0) do DispatchMessage(msg);
KillTimer(0, 0);
end.
{GetMessage函数可取得与指定窗口联系的消息
在这里DispatchMessage函数通常调度从GetMessage取得的消息}

相关阅读 >>

Delphi 枚举resource资源名

Delphi禁止webbrowser弹出窗口或者脚本错误

Delphi 调用shellexecute打开txt文本

Delphi 动态修改显示器分辨率

Delphi datamodule1 fdconnection1数据库连接

Delphi 的 tstringbuilder 可以完美实现jave ,c#的tstringbuilder功能

Delphi改变文件夹图标

Delphi 得到cxgrid筛选后的记录数

Delphi使用xmlhttp组件代码

Delphi 使用fastscript调试脚本

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...