Ejemplo n.º 1
0
        private int loadNotifications()
        {
            int[] iHandles = OpenNETCF.WindowsCE.Notification.Notify.GetUserNotificationHandles();
            _sList = new List <string>();
            _sList.Clear();

            _strArr = new string[iHandles.Length + 1][];

            _strArr[0] = new string[7] {
                "App", "Args", "Event", "Start", "End", "Type", "handle"
            };

            int i = 0;

            eventEntries = new EventEntry[iHandles.Length];
            //eventEntries[0] = new EventEntry("App|Args|Event|Start|End|Type");

            //###############################

            //###############################

            foreach (int iHandle in iHandles)
            {
                OpenNETCF.WindowsCE.Notification.UserNotificationInfoHeader infoHeader = OpenNETCF.WindowsCE.Notification.Notify.GetUserNotification(iHandle);

                _strArr[i] = new string[7];

                string sApp = infoHeader.UserNotificationTrigger.Application;
                _strArr[i][0] = "'" + infoHeader.UserNotificationTrigger.Application + "'";

                sApp         += "|'" + infoHeader.UserNotificationTrigger.Arguments + "'";
                _strArr[i][1] = infoHeader.UserNotificationTrigger.Arguments;

                sApp         += "|" + infoHeader.UserNotificationTrigger.Event.ToString();
                _strArr[i][2] = infoHeader.UserNotificationTrigger.Event.ToString();

                sApp         += "|" + infoHeader.UserNotificationTrigger.StartTime.ToString("ddMMyyyy HH:mm");
                _strArr[i][3] = infoHeader.UserNotificationTrigger.StartTime.ToString("ddMMyyyy HH:mm");

                sApp         += "|" + infoHeader.UserNotificationTrigger.EndTime.ToString("ddMMyyyy HH:mm");
                _strArr[i][4] = infoHeader.UserNotificationTrigger.EndTime.ToString("ddMMyyyy HH:mm");

                sApp         += "|" + infoHeader.UserNotificationTrigger.Type.ToString();
                _strArr[i][5] = infoHeader.UserNotificationTrigger.Type.ToString();

                sApp         += "|" + iHandles[i].ToString();
                _strArr[i][6] = iHandles[i].ToString();

                eventEntries[i] = new EventEntry(sApp);
                //eventEntries[i] = new EventEntry(_strArr[i]);

                i++;
                _sList.Add(sApp);
            }

            return(_sList.Count);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieves notification information associated with a handle.
        /// </summary>
        /// <param name="handle">Handle to the user notification to retrieve.</param>
        /// <returns>The requested <see cref="UserNotificationInfoHeader"/>.</returns>
        public static UserNotificationInfoHeader GetUserNotification(int handle)
        {
            //buffer size
            int size = 0;

            //first query for buffer size required
            NativeMethods.CeGetUserNotification(handle, 0, ref size, IntPtr.Zero);

            //create a marshallable buffer
            IntPtr buffer = Marshal.AllocHGlobal(size);

            //call native getter
            if (!NativeMethods.CeGetUserNotification(handle, (uint)size, ref size, buffer))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Error getting UserNotification");
            }

            //marshaller doesn't cope with marshalling the struct with nested bits using PtrToStructure, so do it manually
            UserNotificationInfoHeader nih = new UserNotificationInfoHeader();

            nih.hNotification = Marshal.ReadInt32(buffer, 0);
            nih.dwStatus      = Marshal.ReadInt32(buffer, 4);
            IntPtr pTrigger = (IntPtr)Marshal.ReadInt32(buffer, 8);
            IntPtr pNotif   = (IntPtr)Marshal.ReadInt32(buffer, 12);

            nih.pcent = new UserNotificationTrigger();
            // FIX: ArgumentNullException in GetUserNotifications (Bug #16)
            if (pTrigger != IntPtr.Zero)
            {
                nih.pcent.dwSize      = Marshal.ReadInt32(pTrigger);
                nih.pcent.Type        = (NotificationType)Marshal.ReadInt32(pTrigger, 4);
                nih.pcent.Event       = (NotificationEvent)Marshal.ReadInt32(pTrigger, 8);
                nih.pcent.Application = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(pTrigger, 12));
                nih.pcent.Arguments   = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(pTrigger, 16));
                nih.pcent.stStartTime =
                    (SYSTEMTIME)Marshal.PtrToStructure((IntPtr)(pTrigger.ToInt32() + 20), typeof(SYSTEMTIME));
                nih.pcent.stEndTime =
                    (SYSTEMTIME)Marshal.PtrToStructure((IntPtr)(pTrigger.ToInt32() + 36), typeof(SYSTEMTIME));
            }

            nih.pceun = new UserNotification();
            // FIX: ArgumentNullException in GetUserNotifications (Bug #16)
            if (pNotif != IntPtr.Zero)
            {
                nih.pceun.Action   = (NotificationAction)Marshal.ReadInt32(pNotif, 0);
                nih.pceun.Title    = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(pNotif, 4));
                nih.pceun.Text     = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(pNotif, 8));
                nih.pceun.Sound    = Marshal.PtrToStringUni((IntPtr)Marshal.ReadInt32(pNotif, 12));
                nih.pceun.MaxSound = Marshal.ReadInt32(pNotif, 16);
            }

            //free native memory
            Marshal.FreeHGlobal(buffer);

            return(nih);
        }
Ejemplo n.º 3
0
        private int loadNotifications(TreeView tv)
        {
            int iCnt = 0;

            tv.Nodes.Clear();
            TreeNode tnMain = tv.Nodes.Add("Notifications");

            tnMain.Tag = "root";

            int[] iHandles = OpenNETCF.WindowsCE.Notification.Notify.GetUserNotificationHandles();
            _sList = new List <string>();
            _sList.Clear();

            _strArr = new string[iHandles.Length + 1][];

            _strArr[0] = new string[7] {
                "App", "Args", "Event", "Start", "End", "Type", "handle"
            };

            int i = 0;

            eventEntries = new EventEntry[iHandles.Length];

            foreach (int iHandle in iHandles)
            {
                OpenNETCF.WindowsCE.Notification.UserNotificationInfoHeader infoHeader = OpenNETCF.WindowsCE.Notification.Notify.GetUserNotification(iHandle);
                string[] strArray = new string[] { infoHeader.UserNotificationTrigger.Application, infoHeader.UserNotificationTrigger.Arguments };
                TreeNode tn       = new TreeNode(infoHeader.UserNotificationTrigger.Application);
                tnMain.Nodes.Add(tn);
                tn.Tag = infoHeader;
                TreeNode tnSub = tn.Nodes.Add("Args: " + infoHeader.UserNotificationTrigger.Arguments);
                tnSub.Tag = infoHeader;
                tnSub     = tn.Nodes.Add("Event: " + infoHeader.UserNotificationTrigger.Event.ToString());
                tnSub.Tag = infoHeader;
                tnSub     = tn.Nodes.Add("Start: " + infoHeader.UserNotificationTrigger.StartTime.ToString("dd.MM.yyyy HH:mm"));
                tnSub.Tag = infoHeader;
                tnSub     = tn.Nodes.Add("End: " + infoHeader.UserNotificationTrigger.EndTime.ToString("dd.MM.yyyy HH:mm"));
                tnSub.Tag = infoHeader;
                tnSub     = tn.Nodes.Add("Type: " + infoHeader.UserNotificationTrigger.Type.ToString());
                tnSub.Tag = infoHeader;
                tnSub     = tn.Nodes.Add("Handle: " + iHandles[i].ToString());
                tnSub.Tag = infoHeader;

                //eventEntries[i].sApp = infoHeader.UserNotificationTrigger.Application;
                //eventEntries[i].sEvent = infoHeader.UserNotificationTrigger.Event.ToString();
                //eventEntries[i].sArg = infoHeader.UserNotificationTrigger.Arguments;
                //eventEntries[i].sStartTime = infoHeader.UserNotificationTrigger.StartTime.ToString("dd.MM.yyyy HH:mm");
                //eventEntries[i].sEndTime = infoHeader.UserNotificationTrigger.EndTime.ToString("dd.MM.yyyy HH:mm");
                //eventEntries[i].sType = infoHeader.UserNotificationTrigger.Type.ToString();
                //eventEntries[i].sHandle = iHandles[i].ToString();

                iCnt++;
            }
            tv.Refresh();
            return(iCnt);
        }