Esempio n. 1
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="WindowManager"/> class.
        /// </summary>
        public WindowManager([NotNull] Dispatcher dispatcher)
        {
            if (dispatcher is null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }

            if (initialized)
            {
                throw new InvalidOperationException("An instance of WindowManager is already existing.");
            }

            initialized              = true;
            winEventProc             = WinEventProc;
            WindowManager.dispatcher = dispatcher;
            uint processId = (uint)Process.GetCurrentProcess().Id;

            hook = NativeHelper.SetWinEventHook(NativeHelper.EVENT_OBJECT_SHOW, NativeHelper.EVENT_OBJECT_HIDE, IntPtr.Zero, winEventProc, processId, 0, NativeHelper.WINEVENT_OUTOFCONTEXT);
            if (hook == IntPtr.Zero)
            {
                throw new InvalidOperationException("Unable to initialize the window manager.");
            }

            Logger.Info($"{nameof(WindowManager)} initialized");
        }
Esempio n. 2
0
 public void Dispose()
 {
     uiDispatcher.Invoke(() =>
     {
         manager.Dispose();
         if (!NativeHelper.UnhookWinEvent(hook))
         {
             throw new InvalidOperationException("An error occurred while disposing the window manager.");
         }
         hook         = IntPtr.Zero;
         winEventProc = null;
     });
 }
Esempio n. 3
0
 public WindowManagerWrapper(Dispatcher dispatcher)
 {
     uiDispatcher = dispatcher;
     manager      = uiDispatcher.Invoke(() =>
     {
         winEventProc  = WinEventProc;
         var processId = (uint)Process.GetCurrentProcess().Id;
         hook          = NativeHelper.SetWinEventHook(NativeHelper.EVENT_OBJECT_SHOW, NativeHelper.EVENT_OBJECT_HIDE, IntPtr.Zero, winEventProc, processId, 0, NativeHelper.WINEVENT_OUTOFCONTEXT);
         if (hook == IntPtr.Zero)
         {
             throw new InvalidOperationException("Unable to initialize the window manager.");
         }
         return(new WindowManager(uiDispatcher));
     });
 }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WindowManager"/> class.
        /// </summary>
        public WindowManager(Dispatcher dispatcher)
        {
            if (dispatcher == null) throw new ArgumentNullException(nameof(dispatcher));
            if (initialized) throw new InvalidOperationException("An instance of WindowManager is already existing.");

            initialized = true;
            winEventProc = WinEventProc;
            WindowManager.dispatcher = dispatcher;
            uint processId = (uint)Process.GetCurrentProcess().Id;
            hook = NativeHelper.SetWinEventHook(NativeHelper.EVENT_OBJECT_SHOW, NativeHelper.EVENT_OBJECT_HIDE, IntPtr.Zero, winEventProc, processId, 0, NativeHelper.WINEVENT_OUTOFCONTEXT);
            if (hook == IntPtr.Zero)
                throw new InvalidOperationException("Unable to initialize the window manager.");

            Logger.Info($"{nameof(WindowManager)} initialized");
        }
Esempio n. 5
0
        public void Dispose()
        {
            if (!NativeHelper.UnhookWinEvent(hook))
            {
                throw new InvalidOperationException("An error occurred while disposing the window manager.");
            }

            hook         = IntPtr.Zero;
            winEventProc = null;
            initialized  = false;
            dispatcher   = null;
            MainWindow   = null;
            AllWindowsList.Clear();
            ModalWindowsList.Clear();

            Logger.Info($"{nameof(WindowManager)} disposed");
        }
Esempio n. 6
0
        public void Dispose()
        {
            if (!NativeHelper.UnhookWinEvent(hook))
                throw new InvalidOperationException("An error occurred while disposing the window manager.");

            hook = IntPtr.Zero;
            winEventProc = null;
            initialized = false;
            dispatcher = null;
            MainWindow = null;
            AllWindowsList.Clear();
            ModalWindowsList.Clear();

            Logger.Info($"{nameof(WindowManager)} disposed");
        }