private void RemoveHotKeys() { KeyboardHookHelper.UnregisterHotKey(_windowHandle, 0); KeyboardHookHelper.UnregisterHotKey(_windowHandle, 1); KeyboardHookHelper.UnregisterHotKey(_windowHandle, 2); _source?.RemoveHook(HwndHook); }
private void OnSourceChanged(object sender, SourceChangedEventArgs e) { _currentHwndSource?.RemoveHook(_hook); _currentHwndSource = e.NewSource as HwndSource; _currentHwndSource?.AddHook(_hook); _ttl.ScalingChanged?.Invoke(_ttl.Scaling); }
protected override void OnClosed(EventArgs e) { _source?.RemoveHook(HwndHook); HotKeyApi.UnregisterHotKey(_windowHandle, HotKeyApi.ActivateHotKeyId); base.OnClosed(e); }
public static void RemoveGlobalKeyHook(Window window) { WindowInteropHelper helper = new WindowInteropHelper(window); HwndSource hwndSource = HwndSource.FromHwnd(helper.Handle); hwndSource?.RemoveHook(HwndHook); UnregisterHotKey(helper.Handle, WinApiConstants.HOTKEY_ID); }
protected override void OnClosed(EventArgs e) { HotkeyManager.UnregisterHotKey(this); handle?.RemoveHook(WndProc); icon?.Dispose(); viewModel?.Dispose(); serverBridge?.Dispose(); }
protected virtual void Dispose(bool disposing) { _source?.RemoveHook(MessageSink); RawInputDevice.UnregisterDevice(HidUsageAndPage.Keyboard); RawInputDevice.UnregisterDevice(HidUsageAndPage.Mouse); _source = null; }
private void OnClosed(object sender, EventArgs e) { ManipulationDelta = null; ManipulationCompleted = null; _source?.RemoveHook(WndProc); TouchpadHelper.UnregisterInput(); }
public void UnregisterHotKeysAndHooks() { UnregisterRecordHotKey(); SoundboardSampleCollection.ToList().ForEach(soundboardSample => { UnregisterSoundboardSampleHotKey(soundboardSample.HotkeyId); }); // Hooks _hwndSource?.RemoveHook(HwndHook); _hwndSource?.Dispose(); }
/// <inheritdoc /> /// <summary> /// Unregister all the hotkeys that were previously registered /// </summary> public void Dispose() { _logController?.AddLog(new ApplicationLog("Disposing all available hotkey objects and hooks")); // Unregister all the registered hot keys. for (int i = _currentId; i > 0; i--) { NativeMethods.UnregisterHotKey(_helper.Handle, i); } // Remove the hook from the HwndSource _source?.RemoveHook(HwndHook); _source = null; _logController?.AddLog(new ApplicationLog("Done disposing all available hotkey objects and hooks")); }
protected override void OnClosed(EventArgs e) { if (!skipSaveAggregation) { viewModel?.SaveAggregation(); } HotkeyManager.UnregisterHotKey(this); handle?.RemoveHook(WndProc); icon?.Dispose(); viewModel?.Dispose(); serverBridge?.Dispose(); saveDimensionScheduler?.Dispose(); }
protected virtual void Dispose(bool itIsSafeToAlsoFreeManagedObjects) { if (_disposed) { return; } if (itIsSafeToAlsoFreeManagedObjects) { HwndSource?source = PresentationSource.FromVisual(this) as HwndSource; source?.RemoveHook(WndProc); } _disposed = true; }
private async void Closing(CancelEventArgs e) { await _appData.DealExistedFileAction?.Invoke(); var dataSourceFile = ResourcesMap.LocationDic[Location.DataSourceFile]; if (!string.IsNullOrWhiteSpace(_appData.Config.DataSourceJsonString)) { FileHelper.SaveToFile(dataSourceFile, _appData.Config.DataSourceJsonString); } else { if (FileHelper.Exists(dataSourceFile)) { File.Delete(dataSourceFile); } } FileHelper.SaveToJsonFile(ResourcesMap.LocationDic[Location.GlobalConfigFile], _appData.Config); _hwndSource?.RemoveHook(_hwndSourceHook); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public override void Dispose() { // Note Setup can be run after disposing, to "reset" this instance // due to the code in ChromiumWebBrowser.PresentationSourceChangedHandler if (!isSetup) { return; } isSetup = false; owner.GotFocus -= OwnerGotFocus; owner.LostFocus -= OwnerLostFocus; owner.RemoveHandler(UIElement.MouseDownEvent, mouseDownEventHandler); if (source != null && sourceHook != null) { source.RemoveHook(sourceHook); source = null; } }
/// <summary> /// Detachs self /// </summary> public void Detach() { if (!attached) { return; } attached = false; if (window != null) { window.KeyDown -= OnWindowKeyDown; window.KeyUp -= OnWindowKeyUp; this.window = null; } // Hookup non client area messages if ((attachedHwndSource != null) && (!attachedHwndSource.IsDisposed)) { attachedHwndSource.RemoveHook(WindowProc); } }
public void Stop() { if (disposed) { throw new ObjectDisposedException(null); } if (source != null) { source.RemoveHook(WndProc); if (!source.IsDisposed) { if (!DeregisterShellHookWindow(hWnd)) { int error = Marshal.GetLastWin32Error(); throw new Win32Exception(error, "Call DeregisterShellHookWindow failed."); } source.Dispose(); } source = null; } }
private void SetRawMouseInputHook(bool enable) { try { IntPtr hWnd = this.GetHandle(true); if (hWnd == IntPtr.Zero) { // The app is probably terminating return; } HwndSource source = HwndSource.FromHwnd(hWnd); if (source == null) { logger.Error($"Raw mouse input hook not registered: couldn't get {nameof(HwndSource)}!"); return; } if (enable) { if (RawInputApi.RegisterRawMouseInput(source.Handle)) { source.AddHook(this.RawInputWndProc); } else { logger.Error($"Failed to register raw input mouse device. Error code: {Marshal.GetLastWin32Error()}"); } } else { source.RemoveHook(this.RawInputWndProc); } } catch (Exception e) { logger.Error($"Unhandled error while {(enable ? "en" : "dis")}abling raw mouse input hook", e); } }
private void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { this.SuppressException = true; hwndSource.RemoveHook(hook); } for (int i = GlobalHotKeyContainer.Count - 1; i >= 0; i--) { RemoveGlobalHotKey(GlobalHotKeyContainer[i]); } KeyBoardUnHook(); LocalHotKeyContainer.Clear(); ChordHotKeyContainer.Clear(); disposed = true; }
private void FrictionScrollViewer_Unloaded(object sender, RoutedEventArgs e) { if (_window == null) { return; } IntPtr windowhandle = new WindowInteropHelper(_window).Handle; if (windowhandle == IntPtr.Zero) { return; } HwndSource hwndSource = HwndSource.FromHwnd(windowhandle); hwndSource.RemoveHook(new HwndSourceHook(WndProc)); if (f != null) { f.Cleanup(); } }
private void Cleanup() { if (!isCleanedUp) { isCleanedUp = true; // clean up events System.ComponentModel.DependencyPropertyDescriptor.FromProperty(Window.ResizeModeProperty, typeof(Window)) .RemoveValueChanged(AssociatedObject, ResizeModePropertyChangedCallback); AssociatedObject.Loaded -= AssociatedObject_Loaded; AssociatedObject.Unloaded -= AssociatedObject_Unloaded; AssociatedObject.SourceInitialized -= AssociatedObject_SourceInitialized; AssociatedObject.StateChanged -= AssociatedObject_StateChanged; AssociatedObject.Activated -= AssociatedObject_Activated; AssociatedObject.Deactivated -= AssociatedObject_Deactivated; AssociatedObject.IsVisibleChanged -= AssociatedObject_IsVisibleChanged; if (hwndSource != null) { hwndSource.RemoveHook(WindowProc); } windowChrome = null; } }
// Protected implementation of Dispose pattern. private void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { _handle.Dispose(); NativeMethods.RemoveClipboardFormatListener(_hwndSource.Handle); _hwndSource.RemoveHook(WndProc); try { _hwndSource?.Dispose(); } catch (Exception) { //if here, already disposed } } _disposed = true; }
/// <summary> /// Unregister, removes hook and frees identifier. /// </summary> private void InternalDispose(bool calledManually) { if (IsDisposed) { return; } _source.RemoveHook(HwndHook); if (IsRegistered) { Unregister(); } ActiveIdentifiers.Remove(_identifier); IsDisposed = true; if (calledManually) { GC.SuppressFinalize(this); } }
private void SetHotKey(bool Add) { if (Add) { hWndSource.AddHook(MainWindowProc); HotKeyBF = HotKey.GlobalAddAtom($"{SettingHelp.Settings.播放暂停.Item1}-{Enum.GetName(typeof(System.Windows.Forms.Keys), SettingHelp.Settings.播放暂停.Item2)}"); HotKeyTZ = HotKey.GlobalAddAtom($"{SettingHelp.Settings.停止关闭.Item1}-{Enum.GetName(typeof(System.Windows.Forms.Keys), SettingHelp.Settings.停止关闭.Item2)}"); HotKeyHB = HotKey.GlobalAddAtom($"{SettingHelp.Settings.开关画笔.Item1}-{Enum.GetName(typeof(System.Windows.Forms.Keys), SettingHelp.Settings.开关画笔.Item2)}"); HotKey.RegisterHotKey(winHandle, HotKeyBF, SettingHelp.Settings.播放暂停.Item1, SettingHelp.Settings.播放暂停.Item2); HotKey.RegisterHotKey(winHandle, HotKeyTZ, SettingHelp.Settings.停止关闭.Item1, SettingHelp.Settings.停止关闭.Item2); HotKey.RegisterHotKey(winHandle, HotKeyHB, SettingHelp.Settings.开关画笔.Item1, SettingHelp.Settings.开关画笔.Item2); } else//暂时没起作用,todo { hWndSource.RemoveHook(MainWindowProc); HotKey.GlobalDeleteAtom((short)HotKeyBF); HotKey.GlobalDeleteAtom((short)HotKeyTZ); HotKey.GlobalDeleteAtom((short)HotKeyHB); HotKey.UnregisterHotKey(winHandle, HotKeyBF); HotKey.UnregisterHotKey(winHandle, HotKeyTZ); HotKey.UnregisterHotKey(winHandle, HotKeyHB); } }
private void Cleanup() { if (!isCleanedUp) { isCleanedUp = true; // clean up events if (AssociatedObject is MetroWindow) { System.ComponentModel.DependencyPropertyDescriptor.FromProperty(MetroWindow.IgnoreTaskbarOnMaximizeProperty, typeof(MetroWindow)) .RemoveValueChanged(AssociatedObject, IgnoreTaskbarOnMaximizePropertyChangedCallback); } AssociatedObject.Loaded -= AssociatedObject_Loaded; AssociatedObject.Unloaded -= AssociatedObject_Unloaded; AssociatedObject.SourceInitialized -= AssociatedObject_SourceInitialized; AssociatedObject.StateChanged -= AssociatedObject_StateChanged; AssociatedObject.Activated -= AssociatedObject_Activated; if (hwndSource != null) { hwndSource.RemoveHook(WindowProc); } windowChrome = null; } }
private void Cleanup(bool isClosing) { if (isCleanedUp) { return; } isCleanedUp = true; OnCleanup(); // clean up events AssociatedObject.SourceInitialized -= AssociatedObject_SourceInitialized; AssociatedObject.Loaded -= AssociatedObject_Loaded; AssociatedObject.Unloaded -= AssociatedObject_Unloaded; AssociatedObject.Closed -= AssociatedObject_Closed; AssociatedObject.StateChanged -= AssociatedObject_StateChanged; AssociatedObject.LostFocus -= AssociatedObject_LostFocus; AssociatedObject.Deactivated -= AssociatedObject_Deactivated; hwndSource?.RemoveHook(WindowProc); _RestoreStandardChromeState(isClosing); }
private void PresentationSourceChangedHandler(object sender, SourceChangedEventArgs args) { if (args.NewSource != null) { var newSource = (HwndSource)args.NewSource; source = newSource; if (source != null) { matrix = source.CompositionTarget.TransformToDevice; sourceHook = SourceHook; source.AddHook(sourceHook); } } else if (args.OldSource != null) { if (source != null && sourceHook != null) { source.RemoveHook(sourceHook); source = null; } } }
private void RemoveHwndHook() { AssociatedObject.SourceInitialized -= AssociatedObject_SourceInitialized; _mHWNDSource.RemoveHook(HwndHook); }
public static void RemoveHotkey(Window parentWindow) { HwndSource.RemoveHook(HwndHook); HwndSource = null; UnregisterHotKey(parentWindow); }
public void RemoveHooksAndUnregister() { PresentationSource.RemoveHook(WndProc); IsHookActive = false; }
} // private void StopListeningToClipboard() { ChangeClipboardChain(_HWndSource.Handle, _HWndNextViewer); // remove from cliboard viewer chain _HWndNextViewer = IntPtr.Zero; _HWndSource.RemoveHook(WinProc); } //
/// <summary> /// Create an observable for the specified window or HwndSource /// </summary> /// <param name="window">Window</param> /// <param name="hWndSource">HwndSource</param> /// <param name="before">Func which does something as soon as the observable is created</param> /// <param name="disposeAction">Action which disposes something when the observable is disposed</param> /// <returns>IObservable</returns> internal static IObservable <WindowMessageInfo> WinProcMessages <TState>(Window window, HwndSource hWndSource, Func <IntPtr, TState> before = null, Action <TState> disposeAction = null) { if (window == null && hWndSource == null) { throw new NotSupportedException("One of Window or HwndSource must be supplied"); } return(Observable.Create <WindowMessageInfo>(observer => { // This handles the message, and generates the observable OnNext IntPtr WindowMessageHandler(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { observer.OnNext(WindowMessageInfo.Create(hWnd, msg, wParam, lParam)); // ReSharper disable once AccessToDisposedClosure if (hWndSource.IsDisposed) { observer.OnCompleted(); } return IntPtr.Zero; } TState state = default; void HwndSourceDisposedHandle(object sender, EventArgs e) { observer.OnCompleted(); } void RegisterHwndSource() { if (before != null) { state = before(hWndSource.Handle); } hWndSource.Disposed += HwndSourceDisposedHandle; hWndSource.AddHook(WindowMessageHandler); } if (window != null) { hWndSource = window.ToHwndSource(); } if (hWndSource != null) { RegisterHwndSource(); } else if (window != null) { // No, try to get it later window.SourceInitialized += (sender, args) => { hWndSource = window.ToHwndSource(); RegisterHwndSource(); // Simulate the WM_NCCREATE observer.OnNext(WindowMessageInfo.Create(hWndSource.Handle, (int)WindowsMessages.WM_NCCREATE, IntPtr.Zero, IntPtr.Zero)); }; } return Disposable.Create(() => { disposeAction?.Invoke(state); hWndSource.Disposed -= HwndSourceDisposedHandle; hWndSource.RemoveHook(WindowMessageHandler); hWndSource.Dispose(); }); }) // Make sure there is always a value produced when connecting .Publish() .RefCount()); }