onsdag 14 oktober 2009

CeGetUserNotificationHandles

So far, we've been looking at how to create, modify, handle and delete notifications. When you create a notifiction you are passed a handle to that specific notification by the API and that same handle must be used later on when you either modify or delete the notification. As you know by now - either I've told you or you're about to find out - notifications aren't automatically deleted from the system scheduler after they've been triggered. What this means is that notifications that has served their purpose must be removed using CeClearUserNotification.
This also implies that you must save the handle in between sessions.

Another way to resolve this issue is to enumerate all notifications and find the notification you're looking for based on i.e. the name of the application its set to execute. Enumeration of notifications is accomplished thru the use of CeGetUserNotificationHandles.

        [DllImport("CoreDLL.dll", SetLastError = false, EntryPoint="CeGetUserNotificationHandles")]
public static extern bool GetUserNotificationHandles(IntPtr[] rghNotifications, uint cHandles, ref uint pcHandlesNeeded);


CeGetUserNotificationHandles returns an array of notification handles. Each of the handles can then be used as input for CeGetUserNotification which in turn will return the notification as a byte array.
To determine the size of rghNotifications needed, call CeGetUserNotificationHandless with NULL parameters.
    uint dwHowMany=0;
GetUserNotificationHandles(null, 0 ref dwHowMany);


You then use the value of dwHowMany to create an IntPtr array of the correct size.
    IntPtr rghNotifications = new IntPtr[dwHowMany];

Calling CeGetUserNotificationHandles one more time will fill the IntPtr array.
    GetUserNotificationHandles(rghNotifications, dwHowMany, ref dwHowMany);

Given that GetUserNotificationHandles returned TRUE you should now have an IntPtr array filled with notification handles that can you can use.

Tomorrow we'll tie the knot on the notification sack and look and the final missing piece; CeGetUserNotification.

Inga kommentarer:

Skicka en kommentar