New Notification API in Pocket PC 2002

New Notification API in Pocket PC 2002

Microsoft Corporation

June 2002

Summary: Describes the new Notification API of Pocket PC 2002, which allows your application to send notification to the top of the visible screen. (5 printed pages)

Applies to:
   Microsoft® Windows® Powered Pocket PC 2002
   Microsoft eMbedded Visual Tools version 3.0
   Pocket PC 2002 Software Development Kit

Gotchas

The Notification API is not part of Microsoft Messenger. This means if you have subscribed to Microsoft .NET Alerts you will not get the notification automatically in Messenger. Microsoft Messenger uses the Notification API to display incoming chat request and text during a chat session.

Contents

Why Notifications?
Introducing the Notification API
Step 1: Adding a Simple Notification
Step 2: Receiving Notifications from the Notification
Conclusion

Why Notifications?

You are probably as addicted to Instant Messaging* as I am. You immediately look to the corner of the screen that shows you if one of your buddies has logged on or if someone has sent you an instant message. Well, the heart of Instant Messaging, and especially the little "toast" that shows up, is a notification system. By definition a notification is a little message that pops up on the screen no matter what you are doing or what application has the window focus.

Starting with the idea of Instant Messaging you can imagine all sorts of interesting usages for notifications: incoming phone calls, incoming e-mails, incoming messages, stock quote updates, downloads of complete messages, alerts of critical states in your application, and so on. While the first three are already implemented in Pocket PC 2002 and you will encounter them sooner or later, the others are up to us, the developers, to create.

Figure 1. A sample "New Mail" notification

Introducing the Notification API

Pocket PC 2002 is a great communication platform. To qualify for a great communication platform, at least in my eyes, it has to support notifications. The new Notification API included in Pocket PC 2002 has everything to create exiting applications that benefit from notifications. The notification system is intended for applications that are not in the foreground in order to notify the user of some activity without stealing the context of which the user is in at that moment. It is NOT a replacement for message box or Information Dialog, which request general information during the use of an application.

The application programming interface (API) consists of a series of calls all starting with "SH..." because they belong to the family of Shell-APIs. The three most important calls are: SHNotificationAdd—to add a new notification to the notification subsystem of the Pocket PC Shell; SHNotificationRemove—to remove it again; and SHNotificationUpdate—to update a notification.

I assembled a short list of steps to show you what needs to be done to include the API in your application.

Step 1: Adding a Simple Notification

The following codes show how you can add a simple notification to your application. As you can see you can even send well-formatted HTML as a notification. Even form fields and hyperlinks are shown correctly.

#include "stdafx.h"
#include <stdlib.h> 
#include "resource.h"

#define IDS_DEFAULTTITLE      TEXT("Sample Notification...")
#define IDS_DEFAULTHTMLMESSAGE   TEXT("<html><body><a 
href=/"cmd:11/">Test Link

</a><p><form method=/"POST/" action=><p>This is an <font 
color=/"#0000FF/">

<b>HTML</b></font> notification stored in a  <font 
color=/"#FF0000/"><i>string</i>

</font> table!</p><p align=right><input type=button name='cmd:10' 
value='Ok'> 

<input type=button name='cmd:2' value='Cancel'></p></body></html>");

// GUID for the app   please calculate your own!
// {CA777AF7-3CDE-4c15-A7CD-81F629ABA6B8}
static const GUID guidPPCAlertsApp = 
{ 0xca777af7, 0x3cde, 0x4c15, { 0xa7, 0xcd, 0x81, 0xf6, 0x29, 0xab, 
0xa6, 0xb8 } };

int WINAPI WinMain(   HINSTANCE hInstance,
               HINSTANCE hPrevInstance,
               LPTSTR    lpCmdLine,
               int       nCmdShow)
{
SHNOTIFICATIONDATA* pCurrentNotification = NULL;
HICON   hIcon = NULL;
      
   // IDI_MESSAGE Icon has to be created in the resources…
   hIcon = (HICON)LoadImage (hInstance, MAKEINTRESOURCE(IDI_MESSAGE),
   IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);

   pCurrentNotification = (SHNOTIFICATIONDATA*)malloc(
 sizeof(SHNOTIFICATIONDATA)); 

   pCurrentNotification->dwID = 4711;
   pCurrentNotification->clsid = guidPPCAlertsApp;
   pCurrentNotification->npPriority = SHNP_INFORM;
   pCurrentNotification->csDuration = 20;
   pCurrentNotification->hwndSink = NULL;  
   pCurrentNotification->pszHTML = IDS_DEFAULTHTMLMESSAGE;
   pCurrentNotification->hicon = hIcon;
   pCurrentNotification->cbStruct = sizeof(SHNOTIFICATIONDATA);
   pCurrentNotification->pszTitle = IDS_DEFAULTTITLE;
   pCurrentNotification->grfFlags = NULL;
 
   SHNotificationAdd(pCurrentNotification);

// We just wait for 30 second before we remove the Notification again
   Sleep(30000);   

   SHNotificationRemove(&guidPPCAlertsApp, 4711);

   return 0;
}

If you start this application it will show a sample notification as seen in the figure.

Step 2: Receiving Notifications from the Notification

Sending a notification has one major purpose for an application: to bring the user back to the application! Seen by a developer, this can only be implemented if the application is notified by the notification.

Here are the steps to get a notification in your application when a user taps on a link in the notification window.

  • Step 2A: Add the hWND of your main windows to the hwndSink of the notification.
   pCurrentNotification->hwndSink = hWnd;
  • Step 2B: Add a case branch to your WM_COMMAND processing parsing for the number in the HREF "cmd:11" and "cmd:10" in the previous example.

Done! Simple, isn't it?

Conclusion

The Notification API is simple and powerful at the same time. For more detailed information about the parameters and structure members of the API, please consult the SDK documentation. The SDK also includes a great example named "NotifyMFC" that shows the full power of the notification API.

*Use of some functionality contained in the software may require a separately purchased modem or other wireless accessory. See Pocket PC device manufacturer for details.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值