private void Event_DisplaySettingsChanged(object sender, EventArgs e) { _updatingDisplaySettings = true; Debug.WriteLine("\nDisplay Settings Changed..."); Debug.WriteLine(_screenSet = new ScreenSet()); _updatingDisplaySettings = false; }
public void Run() { // DPI Awareness API is not available on older OS's, but they work in // physical pixels anyway, so we just ignore if the call fails. try { SHCore.SetProcessDpiAwareness(PROCESS_DPI_AWARENESS.Process_Per_Monitor_DPI_Aware); } catch (DllNotFoundException) { Debug.WriteLine("No SHCore.DLL. No problem."); } // Make sure we catch CTRL-C hard-exit of program. _ctrlCHandler = new Kernel32.ConsoleEventDelegate(ConsoleEventCallback); Kernel32.SetConsoleCtrlHandler(_ctrlCHandler, true); Debug.WriteLine(_screenSet = new ScreenSet()); // Get notified of any screen configuration changes. SystemEvents.DisplaySettingsChanged += Event_DisplaySettingsChanged; //User32.ShowWindow(Kernel32.GetConsoleWindow(), User32.SW_HIDE); //--Keep a reference to the delegate, so it does not get garbage collected. _mouseHookDelegate = LLMouseHookCallback; _llMouseHookhand = SetHook(User32.WH_MOUSE_LL, _mouseHookDelegate); Debug.WriteLine(""); // This is the one that runs "forever" while the application is alive, and handles // events, etc. This application is ABSOLUTELY ENTIRELY driven by the LLMouseHook // and DisplaySettingsChanged events. System.Windows.Forms.Application.Run(); Debug.WriteLine("Exiting!!!"); UnsetHook(ref _llMouseHookhand); }