public void DeregisterFromPnpEvents() { System.Windows.Interop.HwndSource hwndSource = System.Windows.Interop.HwndSource.FromHwnd(new System.Windows.Interop.WindowInteropHelper(this).Handle); hwndSource.RemoveHook(new System.Windows.Interop.HwndSourceHook(WndProc)); Win32Api.UnregisterDeviceNotification(hwndSource.Handle); }
private void mainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { IntPtr windowHandle = (new System.Windows.Interop.WindowInteropHelper(this)).Handle; System.Windows.Interop.HwndSource src = System.Windows.Interop.HwndSource.FromHwnd(windowHandle); src.RemoveHook(new System.Windows.Interop.HwndSourceHook(this.WndProc)); }
// We should clean up our hotkeys to avoid having orphaned events in Windows protected override void OnClosed(EventArgs e) { _source.RemoveHook(HwndHook); _source = null; // Ensure that all events are deregistered properly hotKeyManager.Clear(); base.OnClosed(e); }
private void RemoveHook() { if (_HwndSource != null) { _HwndSource.RemoveHook(TaskDialogHelpers.CloseButtonHook); _HwndSource = null; } }
private void MainWindow_Closing() { System.Windows.Interop.HwndSource src = System.Windows.Interop.HwndSource.FromHwnd(((MainWindow)Application.Current.MainWindow).MainWin); src.RemoveHook(new System.Windows.Interop.HwndSourceHook(this.WndProc)); }