Winodws Mobile中怎样做到定时启动一个EXE?

今天朋友问我,我过去写的那个定时发送短信的程序是怎么实现的。我觉得很有必要把这两个api拿出来跟大家分享一下。

 

CeRunAppAtTimeCeSetUserNotificationEx。这个两个的功能差不多都是在你设定的时间运行一个EXE程序。但是后者可以带一些附加功能比如在运行EXE的同时播放音乐之类。下面我具体说一下这两个API的使用。

 

CeRunAppAtTime

 

函数原型:

 

BOOL CeRunAppAtTime(  TCHAR* pwszAppName,  SYSTEMTIME* lpTime );

 

参数:

 

pwszAppName :要被运行的EXE名字

 

lpTime :要求时间格式是 SYSTEMTIME ,如果参数是NULL,取消运行。

 

返回值:TRUE indicates success. FALSE indicates failure.

 

注意事项:

 

Calling the CeRunAppAtTime function replaces any previous run request for the specified application.

 

The system passes the APP_RUN_AT_TIME string to the application as the command line. If an instance of the application is already running, the new instance must send a private message to the existing instance and then shut down. Use CeRunAppAtTime sparingly because automatically starting an application can confuse the user and cause low-memory conditions on a machine with restricted memory. Ideally, the application should be small and non-intrusive.If the specified time falls within the platform-dependent period defined by the accuracy of the real-time clock (RTC), the notification is scheduled immediately. The accuracy can be retrieved using IOCTL_KLIB_GETALARMRESOLUTION and ranges from 1 to 60 seconds. If the system does not implement IOCTL_KLIB_GETALARMRESOLUTION, the default RTC accuracy of 10 seconds is assumed.

 

 

CeSetUserNotificationEx

 

函数原型:

 

HANDLE CeSetUserNotificationEx(  HANDLE hNotification, 

 

                                                     CE_NOTIFICATION_TRIGGER*pcnt,                                                           CE_USER_NOTIFICATION* pceun );

 

参数:

 

hNotification

 

[in] Handle to the notification to overwrite or 0 to add a new notification.

 

pcnt

 

[in] Pointer to a CE_NOTIFICATION_TRIGGER structure that defines what event activates a notification.

 

pceun

 

[in] Pointer to the CE_USER_NOTIFICATION structure that defines how the system should respond when a notification occurs. For example, the system could launch a dialog box or another application.

 

返回值:成功返回提醒事件的句柄,如果失败返回NULL

 

注意事项:

 

If the scheduled time lies within the platform-dependent period defined by the accuracy of the real-time clock (RTC), the notification may be scheduled immediately. The accuracy may be retrieved by IOCTL_KLIB_GETALARMRESOLUTION and may range from 1 to 60 seconds. If the platform does not implement IOCTL_KLIB_GETALARMRESOLUTION, the default RTC accuracy of 10 seconds is assumed.

 

说明:对于CeSetUserNotificationEx的参数第一个是句柄不多说了。后两个都是结构体,第一个是设定时间用的格式也是SYSTEMTIME 。第二个是运行哪个EXE还有附加效果用的。具体可以看看MSDN

 

对于这两个API都具体涉及到了SYSTEMTIME这个结构,它包含了8个参数。当时遇到这个结构的时候也困惑了一阵子,后来找到一个中间跳板,他可以让我通往任何我想要去的地方,那就是带两个参数的FILETIME。这个结构非常好用可以将时间控件的日期,与时间直接赋进来,然后转化成任何你想要的时间格式。

 

 

说到底还是要自己动手试试。有时间用第二个API写个闹钟也不错啊!~

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值