diff --git a/Hotkeys.cs b/Hotkeys.cs index b35453a..04f3bce 100644 --- a/Hotkeys.cs +++ b/Hotkeys.cs @@ -31,24 +31,24 @@ public class Hotkeys : Form private readonly int[] _windowId; private Thread _worker; private bool _busyCapturing; - Settings _settings; + Settings _settings; public Hotkeys() { - _windowId = new[] { GetHashCode(), GetHashCode() ^ 327 }; - WindowsApi.RegisterHotKey(Handle, _windowId[0], MOD_ALT, (int)Keys.PrintScreen); - WindowsApi.RegisterHotKey(Handle, _windowId[1], MOD_ALT | MOD_CONTROL, (int)Keys.PrintScreen); + _windowId = new[] { GetHashCode(), GetHashCode() ^ 327 }; + WindowsApi.RegisterHotKey(Handle, _windowId[0], MOD_ALT, (int)Keys.PrintScreen); + WindowsApi.RegisterHotKey(Handle, _windowId[1], MOD_ALT | MOD_CONTROL, (int)Keys.PrintScreen); - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormClose); + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormClose); } - private void FormClose(object sender, FormClosingEventArgs e) - { - foreach (var id in _windowId) + private void FormClose(object sender, FormClosingEventArgs e) + { + foreach (var id in _windowId) { WindowsApi.UnregisterHotKey(Handle, id); } - } + } protected override void WndProc(ref Message m) { @@ -56,7 +56,7 @@ protected override void WndProc(ref Message m) if (m.Msg == WM_HOTKEY) { - _settings = new Settings(); + _settings = new Settings(); if (_busyCapturing) return; @@ -89,26 +89,26 @@ protected override void WndProc(ref Message m) private ScreenshotTask GetParamteresFromUI() { var type = ScreenshotTask.BackgroundType.Transparent; - if (_settings.opaqueCheckbox && _settings.opaqueType == 0) + if (_settings.opaqueCheckbox && _settings.opaqueType == 0) type = ScreenshotTask.BackgroundType.Checkerboard; - else if (_settings.opaqueCheckbox && _settings.opaqueType == 1) + else if (_settings.opaqueCheckbox && _settings.opaqueType == 1) type = ScreenshotTask.BackgroundType.SolidColor; return new ScreenshotTask( - WindowsApi.GetForegroundWindow(), - _settings.clipboardButton, - _settings.folderTextBox, - _settings.resizeCheckbox, - _settings.windowWidth, - _settings.windowHeight, - type, - Color.FromArgb(Convert.ToInt32("FF" + _settings.opaqueColorHexBox, 16)), - _settings.checkerValue, + WindowsApi.GetForegroundWindow(), + _settings.clipboardButton, + _settings.folderTextBox, + _settings.resizeCheckbox, + _settings.windowWidth, + _settings.windowHeight, + type, + Color.FromArgb(Convert.ToInt32("FF" + _settings.opaqueColorHexBox, 16)), + _settings.checkerValue, _settings.aeroColorCheckbox, Color.FromArgb(Convert.ToInt32("FF" + _settings.aeroColorHexBox, 16)), - _settings.mouseCheckbox, + _settings.mouseCheckbox, _settings.clearTypeCheckbox); } - } -} + } +} \ No newline at end of file diff --git a/Main.Designer.cs b/Main.Designer.cs index 001d4eb..a55004e 100644 --- a/Main.Designer.cs +++ b/Main.Designer.cs @@ -168,7 +168,7 @@ private void InitializeComponent() // folderSelectionDialog // this.folderSelectionDialog.Description = "Please select the folder you wish screenshots to be saved to.\r\nFilenames are dete" + - "rmined by the title of the window you are capturing."; + "rmined by the title of the window you are capturing."; // // resizeCheckbox // @@ -187,23 +187,23 @@ private void InitializeComponent() // this.windowHeight.Location = new System.Drawing.Point(338, 25); this.windowHeight.Maximum = new decimal(new int[] { - 16777215, - 0, - 0, - 0}); + 16777215, + 0, + 0, + 0}); this.windowHeight.Minimum = new decimal(new int[] { - 100, - 0, - 0, - 0}); + 100, + 0, + 0, + 0}); this.windowHeight.Name = "windowHeight"; this.windowHeight.Size = new System.Drawing.Size(60, 20); this.windowHeight.TabIndex = 14; this.windowHeight.Value = new decimal(new int[] { - 480, - 0, - 0, - 0}); + 480, + 0, + 0, + 0}); // // labelX // @@ -219,23 +219,23 @@ private void InitializeComponent() // this.windowWidth.Location = new System.Drawing.Point(262, 25); this.windowWidth.Maximum = new decimal(new int[] { - 16777215, - 0, - 0, - 0}); + 16777215, + 0, + 0, + 0}); this.windowWidth.Minimum = new decimal(new int[] { - 100, - 0, - 0, - 0}); + 100, + 0, + 0, + 0}); this.windowWidth.Name = "windowWidth"; this.windowWidth.Size = new System.Drawing.Size(60, 20); this.windowWidth.TabIndex = 12; this.windowWidth.Value = new decimal(new int[] { - 640, - 0, - 0, - 0}); + 640, + 0, + 0, + 0}); // // opaqueCheckbox // @@ -256,8 +256,8 @@ private void InitializeComponent() this.opaqueType.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.opaqueType.FormattingEnabled = true; this.opaqueType.Items.AddRange(new object[] { - "Checkerboard", - "Solid color"}); + "Checkerboard", + "Solid color"}); this.opaqueType.Location = new System.Drawing.Point(195, 19); this.opaqueType.Name = "opaqueType"; this.opaqueType.Size = new System.Drawing.Size(204, 21); @@ -279,23 +279,23 @@ private void InitializeComponent() // this.checkerValue.Location = new System.Drawing.Point(327, 46); this.checkerValue.Maximum = new decimal(new int[] { - 256, - 0, - 0, - 0}); + 256, + 0, + 0, + 0}); this.checkerValue.Minimum = new decimal(new int[] { - 2, - 0, - 0, - 0}); + 2, + 0, + 0, + 0}); this.checkerValue.Name = "checkerValue"; this.checkerValue.Size = new System.Drawing.Size(48, 20); this.checkerValue.TabIndex = 23; this.checkerValue.Value = new decimal(new int[] { - 8, - 0, - 0, - 0}); + 8, + 0, + 0, + 0}); // // opaqueGroupBox // @@ -452,7 +452,7 @@ private void InitializeComponent() this.resizeLabel.Size = new System.Drawing.Size(239, 26); this.resizeLabel.TabIndex = 11; this.resizeLabel.Text = "Sets the exact resolution screenshots are\r\ncaptured in, if the window supports re" + - "sizing."; + "sizing."; // // opaqueColorDialog // @@ -570,23 +570,23 @@ private void InitializeComponent() // this.delaySeconds.Location = new System.Drawing.Point(327, 25); this.delaySeconds.Maximum = new decimal(new int[] { - 10, - 0, - 0, - 0}); + 10, + 0, + 0, + 0}); this.delaySeconds.Minimum = new decimal(new int[] { - 1, - 0, - 0, - 0}); + 1, + 0, + 0, + 0}); this.delaySeconds.Name = "delaySeconds"; this.delaySeconds.Size = new System.Drawing.Size(40, 20); this.delaySeconds.TabIndex = 31; this.delaySeconds.Value = new decimal(new int[] { - 3, - 0, - 0, - 0}); + 3, + 0, + 0, + 0}); // // secondsLabel // diff --git a/Main.cs b/Main.cs index d171cda..79dda51 100644 --- a/Main.cs +++ b/Main.cs @@ -30,7 +30,7 @@ public sealed partial class MainForm : Form private const uint SPI_GETFONTSMOOTHINGTYPE = 0x200A; private readonly RegistryKey _registryKey; - Settings _settings = new Settings(); + Settings _settings = new Settings(); public MainForm() { @@ -38,21 +38,21 @@ public MainForm() Icon = new Icon(typeof(MainForm), "icon.ico"); InitializeComponent(); - folderTextBox.Text = _settings.folderTextBox; - clipboardButton.Checked = _settings.clipboardButton; - diskButton.Checked = _settings.diskButton; - resizeCheckbox.Checked = _settings.resizeCheckbox; - windowWidth.Value = _settings.windowWidth; - windowHeight.Value = _settings.windowHeight; - opaqueCheckbox.Checked = _settings.opaqueCheckbox; - opaqueType.SelectedIndex = _settings.opaqueType; - checkerValue.Value = _settings.checkerValue; - opaqueColorHexBox.Text = _settings.opaqueColorHexBox; + folderTextBox.Text = _settings.folderTextBox; + clipboardButton.Checked = _settings.clipboardButton; + diskButton.Checked = _settings.diskButton; + resizeCheckbox.Checked = _settings.resizeCheckbox; + windowWidth.Value = _settings.windowWidth; + windowHeight.Value = _settings.windowHeight; + opaqueCheckbox.Checked = _settings.opaqueCheckbox; + opaqueType.SelectedIndex = _settings.opaqueType; + checkerValue.Value = _settings.checkerValue; + opaqueColorHexBox.Text = _settings.opaqueColorHexBox; aeroColorCheckbox.Checked = _settings.aeroColorCheckbox; aeroColorHexBox.Text = _settings.aeroColorHexBox; - mouseCheckbox.Checked = _settings.mouseCheckbox; - delayCheckbox.Checked = _settings.delayCheckbox; - delaySeconds.Value = _settings.delaySeconds; + mouseCheckbox.Checked = _settings.mouseCheckbox; + delayCheckbox.Checked = _settings.delayCheckbox; + delaySeconds.Value = _settings.delaySeconds; clearTypeCheckbox.Checked = _settings.clearTypeCheckbox; if (!GlassAvailable()) @@ -74,7 +74,7 @@ public MainForm() clearTypeGroupBox.Enabled = clearTypeCheckbox.Checked; aeroColorGroupBox.Enabled = aeroColorCheckbox.Checked; - _registryKey = Registry.CurrentUser.CreateSubKey(@"Software\AeroShot"); + _registryKey = Registry.CurrentUser.CreateSubKey(@"Software\AeroShot"); } private static bool GlassAvailable() @@ -109,9 +109,9 @@ private static bool ClearTypeEnabled() private void BrowseButtonClick(object sender, EventArgs e) { if (folderSelectionDialog.ShowDialog() == DialogResult.OK) - { - folderTextBox.Text = folderSelectionDialog.SelectedPath; - } + { + folderTextBox.Text = folderSelectionDialog.SelectedPath; + } } private void opaqueColorDisplayClick(object sender, EventArgs e) @@ -278,7 +278,7 @@ private void AeroColorTextboxTextChange(object sender, EventArgs e) aeroColorDialog.Color = Color.FromArgb(Convert.ToInt32("FF" + aeroColorHexBox.Text, 16)); } - private void OkButtonClick(object sender, EventArgs e) + private void OkButtonClick(object sender, EventArgs e) { if (clipboardButton.Checked) _registryKey.SetValue("LastPath", "*" + folderTextBox.Text); @@ -342,13 +342,13 @@ private void OkButtonClick(object sender, EventArgs e) data = BitConverter.ToInt64(b, 0); _registryKey.SetValue("Delay", data, RegistryValueKind.QWord); - this.Close(); + this.Close(); } - private void CancelButtonClick(object sender, EventArgs e) - { - this.Close(); - } + private void CancelButtonClick(object sender, EventArgs e) + { + this.Close(); + } } public class ColorDisplay : UserControl diff --git a/Settings.cs b/Settings.cs index 17b6a66..db33354 100644 --- a/Settings.cs +++ b/Settings.cs @@ -21,92 +21,92 @@ You should have received a copy of the GNU General Public License namespace AeroShot { - public class Settings - { - public bool firstRun; - public int checkerValue = 8; - public string opaqueColorHexBox; - public string folderTextBox; - public bool opaqueCheckbox; - public byte opaqueType; + public class Settings + { + public bool firstRun; + public int checkerValue = 8; + public string opaqueColorHexBox; + public string folderTextBox; + public bool opaqueCheckbox; + public byte opaqueType; public bool aeroColorCheckbox; public string aeroColorHexBox; - public bool resizeCheckbox; - public int windowHeight = 640; - public int windowWidth = 480; - public bool diskButton; - public bool clipboardButton; - public bool mouseCheckbox; - public bool delayCheckbox; - public byte delaySeconds = 3; + public bool resizeCheckbox; + public int windowHeight = 640; + public int windowWidth = 480; + public bool diskButton; + public bool clipboardButton; + public bool mouseCheckbox; + public bool delayCheckbox; + public byte delaySeconds = 3; public bool clearTypeCheckbox; - private readonly RegistryKey _registryKey; - - - public Settings() - { - object value; - _registryKey = Registry.CurrentUser.CreateSubKey(@"Software\AeroShot"); - - if ((value = _registryKey.GetValue("FirstRun")) == null) - { - firstRun = true; - } - - - if ((value = _registryKey.GetValue("LastPath")) != null && - value.GetType() == (typeof(string))) - { - if (((string)value).Substring(0, 1) == "*") - { - folderTextBox = ((string)value).Substring(1); - clipboardButton = true; - } - else - { - folderTextBox = (string)value; - diskButton = true; - } - } - else - { - folderTextBox = - Environment.GetFolderPath(Environment.SpecialFolder.Desktop); - } - - if ((value = _registryKey.GetValue("WindowSize")) != null && - value.GetType() == (typeof(long))) - { - var b = new byte[8]; - for (int i = 0; i < 8; i++) - b[i] = (byte)(((long)value >> (i * 8)) & 0xff); - resizeCheckbox = (b[0] & 1) == 1; - windowWidth = b[1] << 16 | b[2] << 8 | b[3]; - windowHeight = b[4] << 16 | b[5] << 8 | b[6]; - } - - if ((value = _registryKey.GetValue("Opaque")) != null && - value.GetType() == (typeof(long))) - { - var b = new byte[8]; - for (int i = 0; i < 8; i++) - b[i] = (byte)(((long)value >> (i * 8)) & 0xff); - opaqueCheckbox = (b[0] & 1) == 1; - if ((b[0] & 2) == 2) - opaqueType = 0; - if ((b[0] & 4) == 4) - opaqueType = 1; - - checkerValue = b[1] + 2; - - var hex = new StringBuilder(6); - hex.AppendFormat("{0:X2}", b[2]); - hex.AppendFormat("{0:X2}", b[3]); - hex.AppendFormat("{0:X2}", b[4]); - opaqueColorHexBox = hex.ToString(); - } - else - opaqueType = 0; + private readonly RegistryKey _registryKey; + + + public Settings() + { + object value; + _registryKey = Registry.CurrentUser.CreateSubKey(@"Software\AeroShot"); + + if ((value = _registryKey.GetValue("FirstRun")) == null) + { + firstRun = true; + } + + + if ((value = _registryKey.GetValue("LastPath")) != null && + value.GetType() == (typeof(string))) + { + if (((string)value).Substring(0, 1) == "*") + { + folderTextBox = ((string)value).Substring(1); + clipboardButton = true; + } + else + { + folderTextBox = (string)value; + diskButton = true; + } + } + else + { + folderTextBox = + Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + } + + if ((value = _registryKey.GetValue("WindowSize")) != null && + value.GetType() == (typeof(long))) + { + var b = new byte[8]; + for (int i = 0; i < 8; i++) + b[i] = (byte)(((long)value >> (i * 8)) & 0xff); + resizeCheckbox = (b[0] & 1) == 1; + windowWidth = b[1] << 16 | b[2] << 8 | b[3]; + windowHeight = b[4] << 16 | b[5] << 8 | b[6]; + } + + if ((value = _registryKey.GetValue("Opaque")) != null && + value.GetType() == (typeof(long))) + { + var b = new byte[8]; + for (int i = 0; i < 8; i++) + b[i] = (byte)(((long)value >> (i * 8)) & 0xff); + opaqueCheckbox = (b[0] & 1) == 1; + if ((b[0] & 2) == 2) + opaqueType = 0; + if ((b[0] & 4) == 4) + opaqueType = 1; + + checkerValue = b[1] + 2; + + var hex = new StringBuilder(6); + hex.AppendFormat("{0:X2}", b[2]); + hex.AppendFormat("{0:X2}", b[3]); + hex.AppendFormat("{0:X2}", b[4]); + opaqueColorHexBox = hex.ToString(); + } + else + opaqueType = 0; if ((value = _registryKey.GetValue("AeroColor")) != null && value.GetType() == (typeof(long))) @@ -125,23 +125,23 @@ public Settings() else opaqueType = 0; - if ((value = _registryKey.GetValue("CapturePointer")) != null && - value.GetType() == (typeof(int))) - mouseCheckbox = ((int)value & 1) == 1; + if ((value = _registryKey.GetValue("CapturePointer")) != null && + value.GetType() == (typeof(int))) + mouseCheckbox = ((int)value & 1) == 1; if ((value = _registryKey.GetValue("ClearType")) != null && value.GetType() == (typeof(int))) clearTypeCheckbox = ((int)value & 1) == 1; - if ((value = _registryKey.GetValue("Delay")) != null && - value.GetType() == (typeof(long))) - { - var b = new byte[8]; - for (int i = 0; i < 8; i++) - b[i] = (byte)(((long)value >> (i * 8)) & 0xff); - delayCheckbox = (b[0] & 1) == 1; - delaySeconds = b[1]; - } - } - } -} + if ((value = _registryKey.GetValue("Delay")) != null && + value.GetType() == (typeof(long))) + { + var b = new byte[8]; + for (int i = 0; i < 8; i++) + b[i] = (byte)(((long)value >> (i * 8)) & 0xff); + delayCheckbox = (b[0] & 1) == 1; + delaySeconds = b[1]; + } + } + } +} \ No newline at end of file diff --git a/Tray.cs b/Tray.cs index 3f8533d..ad876ee 100644 --- a/Tray.cs +++ b/Tray.cs @@ -27,7 +27,7 @@ public class SysTray : Form MainForm _window = new MainForm(); Hotkeys _hotkeys = new Hotkeys(); - Settings _settings = new Settings(); + Settings _settings = new Settings(); public SysTray() { @@ -40,7 +40,7 @@ public SysTray() // Create a tray menu trayMenu = new ContextMenu(); trayMenu.MenuItems.Add("Settings...", ShowWindow); - trayMenu.MenuItems.Add("-"); + trayMenu.MenuItems.Add("-"); trayMenu.MenuItems.Add("Exit", OnExit); // Add menu to tray icon and show it. @@ -56,22 +56,22 @@ protected override void OnLoad(EventArgs e) base.OnLoad(e); - string saveLocation; - if (_settings.diskButton) - { - saveLocation = "\"" + _settings.folderTextBox + "\""; - } - else - { - saveLocation = "the Clipboard"; - } - trayIcon.ShowBalloonTip(10000, "Press Alt+PrtSrn to Capture Screenshots", "Screenshot will be save to " + saveLocation + ".", ToolTipIcon.Info); + string saveLocation; + if (_settings.diskButton) + { + saveLocation = "\"" + _settings.folderTextBox + "\""; + } + else + { + saveLocation = "the Clipboard"; + } + trayIcon.ShowBalloonTip(10000, "Press Alt+PrtSrn to Capture Screenshots", "Screenshot will be save to " + saveLocation + ".", ToolTipIcon.Info); } private void OnExit(object sender, EventArgs e) { - _hotkeys.Close(); //unregisters the hotkeys on program exit - Application.Exit(); + _hotkeys.Close(); //unregisters the hotkeys on program exit + Application.Exit(); } private void ShowWindow(object sender, EventArgs e) diff --git a/WindowsAPI.cs b/WindowsAPI.cs index 6ae35b9..7b92b12 100644 --- a/WindowsAPI.cs +++ b/WindowsAPI.cs @@ -209,7 +209,7 @@ internal static extern bool RegisterHotKey(IntPtr hWnd, int id, [DllImport("user32.dll")] internal static extern bool UnregisterHotKey(IntPtr hWnd, int id); - [DllImport("user32.dll")] + [DllImport("user32.dll")] internal static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int pvParam, uint fWinIni); [DllImport("user32.dll")]