Download the source code

The API SHNotificationAdd is used to display Notification Bubbles in Windows Mobile. The API has only one parameter, a pointer to the SHNOTIFICATIONDATA structure and is defined as:

typedef struct _SHNOTIFICATIONDATA
{
DWORD cbStruct;
DWORD dwID;
SHNP npPriority;
DWORD csDuration;
HICON hicon;
DWORD grfFlags;
CLSID clsid;
HWND hwndSink;
LPCTSTR pszHTML;
LPCTSTR pszTitle;
LPARAM lParam;
union
{
SOFTKEYMENU skm;
SOFTKEYNOTIFY rgskn[NOTIF_NUM_SOFTKEYS];
};
LPCTSTR pszTodaySK;
LPCTSTR pszTodayExec;
}SHNOTIFICATIONDATA;

The SHNotificationAdd will be asynchronous. The system will notify the hwndSink window when the user is notified and some action is taken. The member pszHTML can an HTML string. You can include any valid HTML tags. The given HMTL text will be rendered when the notification is displayed. You can take input from the user using standatd HTML input tags, for example:

<input type=button name=’cmd:1000′ value=’Click’>

The system will send WM_COMMAND with wParam set to 1000 to the hwndSink window. You can display a link like this:

<a href=’cmd:1000’>Click Me</a>

It will send the WM_COMMAND with wParam 1000.

You can also have a form in HTML text and when it is submitted it will send the notification back to the window. The system will send you a WM_NOTIFY message with NMSHN structure. The NMSHN structure is defined as:

typedef struct _NMSHN
{
NMHDR hdr;
LPARAM lParam;
DWORD dwReturn;
union
{
LPCTSTR pszLink;
BOOL fTimeout;
POINT pt;
};
} NMSHN;

typedef struct tagNMHDR
{
HWND hwndFrom;
UINT idFrom;
UINT code; // NM_ code
} NMHDR;
typedef NMHDR FAR * LPNMHDR;

the code member of the NMHDR will be SHNN_LINKSEL and the pszLink member will contain the URL encoded from.

The following code snippet displays the notification:

SHNOTIFICATIONDATA sIconData = {0};
SHNP shnp = SHNP_INFORM;
DWORD dwDuration = SHN_DURATION;
DWORD dwFlags = SHNF_CRITICAL | SHNF_ALERTONUPDATE;

ZeroMemory(&sIconData,sizeof(SHNOTIFICATIONDATA));

sIconData.cbStruct = sizeof(SHNOTIFICATIONDATA);
sIconData.dwID = SHN_ID_NOTIFICATION;
sIconData.npPriority = shnp;
sIconData.csDuration = dwDuration;
sIconData.hicon = m_hIcon;
sIconData.grfFlags = dwFlags;
sIconData.clsid = CLSID_SampleNotification;
sIconData.hwndSink = m_hWnd;
sIconData.pszHTML = m_strHTMLData;
sIconData.pszTitle = m_strTitle;
sIconData.lParam = 0;
sIconData.rgskn[0].pszTitle = TEXT("Dismiss");
sIconData.rgskn[0].skc.grfFlags = NOTIF_SOFTKEY_FLAGS_DISMISS;

LRESULT lResult = SHNotificationAdd(&sIconData);

You can use SHNotificationRemove to remove the notification.