Ejemplo n.º 1
0
            public NotificationWindow(ShellNotificationListener parent)
            {
                SHChangeNotifyEntry notify = new SHChangeNotifyEntry();

                notify.pidl       = ShellItem.Desktop.Pidl;
                notify.fRecursive = true;
                m_NotifyId        = Shell32.SHChangeNotifyRegister(this.Handle,
                                                                   SHCNRF.InterruptLevel | SHCNRF.ShellLevel,
                                                                   SHCNE.ALLEVENTS, WM_SHNOTIFY, 1, ref notify);
                m_Parent = parent;
            }
Ejemplo n.º 2
0
            public NotificationWindow(ShellNotificationListener parent)
            {
                var notify = new SHChangeNotifyEntry
                {
                    pidl       = ShellItem.Desktop.Pidl,
                    fRecursive = true
                };

                _mNotifyId = Shell32.SHChangeNotifyRegister(Handle,
                                                            SHCNRF.InterruptLevel | SHCNRF.ShellLevel,
                                                            SHCNE.ALLEVENTS, WmShnotify, 1, ref notify);
                _mParent = parent;
            }
        private static void RegiterShNotify(Window window)
        {
            var handle     = (new WindowInteropHelper(window)).Handle;
            var hwndSource = HwndSource.FromHwnd(handle);

            hwndSource.AddHook(WndProc);

            // WM_SHNOTIFY をハンドルするためのおまじない
            var notifyEntry = new Shell32.SHChangeNotifyEntry()
            {
                pIdl = IntPtr.Zero, Recursively = true
            };
            var notifyId = Shell32.SHChangeNotifyRegister(handle,
                                                          Shell32.Constant.SHCNF_TYPE | Shell32.Constant.SHCNF_IDLIST,
                                                          Shell32.Constant.SHCNE_MEDIAINSERTED | Shell32.Constant.SHCNE_MEDIAREMOVED,
                                                          (uint)Shell32.Constant.WM_SHNOTIFY,
                                                          1,
                                                          ref notifyEntry);
        }