/// <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"); }
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; }); }
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)); }); }
/// <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"); }
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"); }
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"); }