WinCE7定时器通知

 

WinCE7定时器通知    by斜风细雨QQ:253786989    2012-01-01

  如果想在某个时间点,自动运行一个指定的app,或者将某个event设置为有效状态,而又不需要用户掺和。那这个时候用“定时器通知”就比较适合了。

  置“定时器通知”,同样使用CeSetUserNotificationEx函数。关于CeSetUserNotificationEx函数的使用参考“WinCE7用户通知”。

  范例1:(定时运行NotificationApp.exe) 

SYSTEMTIME st = {0};
HANDLE hNotify;
CE_NOTIFICATION_TRIGGER nt;
TCHAR szExeName[MAX_PATH], szText[128];
TCHAR szArgs[128] = TEXT("Timer notification.");

GetLocalTime (&st);
if (st.wMinute == 59) 
{
     st.wHour++;
     st.wMinute = 0;
} 
else
{
     st.wMinute++;
}

memset (&nt, 0, sizeof (CE_NOTIFICATION_TRIGGER));
nt.dwSize = sizeof (CE_NOTIFICATION_TRIGGER);
nt.dwType = CNT_TIME;
nt.lpszApplication = TEXT("NotificationApp.exe");
nt.lpszArguments = szArgs;
nt.stStartTime = st;

// Set the notification.
hNotify = CeSetUserNotificationEx (0, &nt, NULL);
if (hNotify) 
{ 
     wsprintf (szText, TEXT ("Timer notification set for %d:%02d:%02d"), st.wHour, st.wMinute, st.wSecond);
}
else
{
     wsprintf (szText, TEXT ("Timer notification failed. rc = %d"), GetLastError());
}

MessageBox (szText, TEXT("置定时器通知"), MB_OK | MB_ICONINFORMATION);

  范例2:(定时将某个事件设置为有信号状态)

SYSTEMTIME st = {0};
HANDLE hNotify;
CE_NOTIFICATION_TRIGGER nt;
TCHAR szExeName[MAX_PATH], szText[128];
TCHAR szArgs[128] = TEXT("Timer notification.");

GetLocalTime (&st);
if (st.wMinute == 59) 
{
    st.wHour++;
    st.wMinute = 0;
} 
else
{
    st.wMinute++;
}

memset (&nt, 0, sizeof (CE_NOTIFICATION_TRIGGER));
nt.dwSize = sizeof (CE_NOTIFICATION_TRIGGER);
nt.dwType = CNT_TIME;
nt.lpszApplication = szExeName;
nt.lpszArguments = szArgs;
nt.stStartTime = st;

StringCchCopy (szExeName, dim(szExeName), NAMED_EVENT_PREFIX_TEXT);
StringCchCat (szExeName, dim(szExeName), szEventName);
hNotify = CeSetUserNotificationEx (0, &nt, NULL);
if (hNotify)  
{
    wsprintf (szText, TEXT ("Timer notification set for %d:%02d:%02d"), st.wHour, st.wMinute, st.wSecond);
}
else
{
    wsprintf (szText, TEXT ("Timer notification failed. rc = %d"), GetLastError());
}

MessageBox (hWnd, szText, szAppName, MB_OK);

  将要设置为有效态的event赋值给lpszApplication,event名称有一个固定格式:

  \\.\Notifications\NamedEvents\<Event Name>

  其中Event Name用event名字代替,因为“\”是c/c++语言里面的转义字符,如要设置的event名字为“TimerNotificationEvent”,则:

  nt.lpszApplication = TEXT(“\\\\.\\Notifications\\NamedEvents\\ TimerNotificationEvent”);

上面范例代码中用到的NAMED_EVENT_PREFIX_TEXT是一个宏定义:

  #define NAMED_EVENT_PREFIX_TEXT TEXT(\\\\.\\Notifications\\NamedEvents\\)

WinCE7定时器通知    by斜风细雨QQ:253786989    2012-01-01

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值