public static extern bool GetWindowPlacement(IntPtr hWnd, out WINDOWPLACEMENT lpwndpl);
public static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref WINDOWPLACEMENT lpwndpl);
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { if (ActiveProfile != null && ActiveProfile.IsStarted) { ActiveProfile.Stop(); } ConfigManager.LogManager.LogInfo("Saving control center window position."); // Persist window placement details to application settings WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); IntPtr hwnd = new WindowInteropHelper(this).Handle; NativeMethods.GetWindowPlacement(hwnd, out wp); //Properties.Settings.Default.ControlCenterPlacement = wp; ConfigManager.SettingsManager.SaveSetting("ControlCenter", "WindowLocation", wp.normalPosition); if (ActiveProfile != null && _profileIndex >= 0 && _profileIndex < _profiles.Count) { ConfigManager.SettingsManager.SaveSetting("ControlCenter", "LastProfile", _profiles[_profileIndex]); } Properties.Settings.Default.Save(); base.OnClosing(e); }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); try { // Load window placement details for previous application session from application settings // Note - if window was closed on a monitor that is now disconnected from the computer, // SetWindowPlacement will place the window onto a visible monitor. if (ConfigManager.SettingsManager.IsSettingAvailable("ControlCenter", "WindowLocation")) { WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); wp.normalPosition = ConfigManager.SettingsManager.LoadSetting("ControlCenter", "WindowLocation", new RECT(0, 0, (int)Width, (int)Height)); wp.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT)); wp.flags = 0; wp.showCmd = (wp.showCmd == NativeMethods.SW_SHOWMINIMIZED ? NativeMethods.SW_SHOWNORMAL : wp.showCmd); IntPtr hwnd = new WindowInteropHelper(this).Handle; NativeMethods.SetWindowPlacement(hwnd, ref wp); } ModifierKeys mods = (ModifierKeys)Enum.Parse(typeof(ModifierKeys), ConfigManager.SettingsManager.LoadSetting("ControlCenter", "HotKeyModifiers", "None")); Keys hotKey = (Keys)Enum.Parse(typeof(Keys), ConfigManager.SettingsManager.LoadSetting("ControlCenter", "HotKey", "None")); if (hotKey != Keys.None) { _hotkey = new HotKey(mods, hotKey, this); _hotkey.HotKeyPressed += new Action<HotKey>(HotKeyPressed); HotKeyDescription = KeyboardEmulator.ModifierKeysToString(_hotkey.KeyModifier) + _hotkey.Key.ToString(); } else { HotKeyDescription = "None"; } } catch { } }