// Hook the WinProg procedure // Source: https://pingfu.net/csharp/2015/04/22/receive-wndproc-messages-in-wpf.html protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource; if (hwndSource != null) { hwndSource.AddHook(WndProc); // Remove if the below is activated again // Install the Clipboard notification hook ClipboardHook.InstallHook(hwndSource.Handle); } else { MessageBox.Show("Failed to add clipboard hook. The program will not be able to catch clipboard updates.", "Clipboard Accelerator", MessageBoxButton.OK, MessageBoxImage.Warning); } /* Re-activate if the above "InstallHook()" is removed * // Install the Clipboard notification hook * HwndSource hwndSourceHandle = PresentationSource.FromVisual(this) as HwndSource; * ClipboardHook.InstallHook(hwndSourceHandle.Handle); */ // Create the actual instance of the Clipboard timer // Source: http://stackoverflow.com/questions/12535722/what-is-the-best-way-to-implement-a-timer ClipboardTimer = new System.Timers.Timer(); // Set the text size of the listbox of external commands to the size stored in the user settings if (Properties.Settings.Default.uiCommandsFontSize > 7 && Properties.Settings.Default.uiCommandsFontSize < 73) { listBoxCommands.FontSize = Properties.Settings.Default.uiCommandsFontSize * 1.33333333; } else { // TODO: set correct default font size listBoxCommands.FontSize = 22 * 1.33333333; } if (Properties.Settings.Default.ShowStartupWindow) { // Init the splash screen message StartupNotificationWindow startupWindow = new StartupNotificationWindow(); startupWindow.ShowDialog(); if (startupWindow.DialogResult == false) { bTestingCloseFlag = true; this.Close(); } } Logger.WriteLog("Program started."); }
void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!bTestingCloseFlag) { MessageBoxResult result = MessageBox.Show("Are you sure you want to close Clipboard Accelerator?", "Clipboard Accelerator", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.No) { e.Cancel = true; return; } } ClipboardHook.OnWindowClosing(); }