Example #1
0
        /*
         * public ulong RegisterChangeNotify(IntPtr hWnd, IListItemEx item, bool Recursively)
         * {
         *  IntPtr handle = IntPtr.Zero;
         *  handle = hWnd;
         *  if (notifyid != 0) return (0);
         *  var changeentry = new SHChangeNotifyEntry() { pIdl = item.PIDL, Recursively = Recursively, };
         *  var changenetrys = new SHChangeNotifyEntry[1] { changeentry };
         *  //changenetrys[0] = changeentry;
         *
         *  notifyid = SHChangeNotifyRegister(
         *      hWnd,
         * (SHCNRF)0x00FF | (SHCNRF)0x0000 | SHCNRF.NewDelivery,
         *      SHCNE.SHCNE_ALLEVENTS | SHCNE.SHCNE_INTERRUPT,
         *      WM_SHNOTIFY,
         *      1,
         *      changenetrys);
         *  return (notifyid);
         * }
         */

        /// <summary>
        /// Unregister the form
        /// </summary>
        /// <returns>True if successfull</returns>
        public Boolean UnregisterChangeNotify()
        {
            if (notifyid == 0)
            {
                return(false);
            }
            if (Shell32.SHChangeNotifyUnregister(notifyid))
            {
                notifyid = 0;
                return(true);
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Message received from the WndProc of a registered form
        /// </summary>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns>True if this is a new notification</returns>
        public bool NotificationReceipt(IntPtr wParam, IntPtr lParam)
        {
            IntPtr ptr;
            uint   eventID;
            var    lockPtr = Shell32.SHChangeNotification_Lock(wParam, (int)lParam, out ptr, out eventID);

            try
            {
                SHNOTIFYSTRUCT shNotify = (SHNOTIFYSTRUCT)Marshal.PtrToStructure(
                    ptr,
                    typeof(SHNOTIFYSTRUCT));
                NotifyInfos info = new NotifyInfos((SHCNE)(int)eventID);
                //System.Windows.Forms.MessageBox.Show(info.Notification.ToString());

                //Not supported notifications
                //if (info.Notification == SHCNE.SHCNE_FREESPACE ||
                //    info.Notification == SHCNE.SHCNE_UPDATEIMAGE)
                //    return (false);

                info.Item1 = shNotify.dwItem1;
                info.Item2 = shNotify.dwItem2;

                // Was this notification in the received notifications ?
                if (NotificationsReceived.Contains(info))
                {
                    return(false);
                }
                NotificationsReceived.Add(info);
            }
            finally
            {
                if (lockPtr != IntPtr.Zero)
                {
                    Shell32.SHChangeNotification_Unlock(lockPtr);
                }
            }
            return(true);
            //DisplayName1 = GetDisplayNameFromPidl(shNotify.dwItem1);
            //DisplayName2 = GetDisplayNameFromPidl(shNotify.dwItem2);
        }