Skip to content

Commit 82b8016

Browse files
committed
Improved XP/Vista Beta compatibility
GUI options for checking which types of screenshot to save Improved Vista beta support (wrapped DWM calls in try catch in case they don't exist on the builds)
1 parent 6f40c2c commit 82b8016

File tree

5 files changed

+162
-28
lines changed

5 files changed

+162
-28
lines changed

Main.Designer.cs

Lines changed: 97 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Main.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public MainForm()
5757
delaySeconds.Value = _settings.delaySeconds;
5858
clearTypeCheckbox.Checked = _settings.clearTypeCheckbox;
5959
shadowCheckbox.Checked = _settings.shadowCheckbox;
60+
saveActiveDarkCheckbox.Checked = _settings.saveActiveDarkCheckbox;
61+
saveActiveLightCheckbox.Checked = _settings.saveActiveLightCheckbox;
62+
saveInactiveDarkCheckbox.Checked = _settings.saveInactiveDarkCheckbox;
63+
saveInactiveLightCheckbox.Checked = _settings.saveInactiveLightCheckbox;
6064

6165
if (!GlassAvailable())
6266
{
@@ -92,7 +96,13 @@ private static bool GlassAvailable()
9296
if ((Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor > 1) || Environment.OSVersion.Version.Major >= 10 || Environment.OSVersion.Version.Major < 6) return false;
9397

9498
bool aeroEnabled = true;
95-
WindowsApi.DwmIsCompositionEnabled(out aeroEnabled);
99+
try {
100+
WindowsApi.DwmIsCompositionEnabled(out aeroEnabled);
101+
}
102+
catch (Exception)
103+
{
104+
//This is fallback intended for beta versions of Windows Vista
105+
}
96106
return aeroEnabled;
97107
}
98108

@@ -347,6 +357,14 @@ private void OkButtonClick(object sender, EventArgs e)
347357

348358
_registryKey.SetValue("Shadow", shadowCheckbox.Checked ? 1 : 0, RegistryValueKind.DWord);
349359

360+
_registryKey.SetValue("SaveActiveDark", saveActiveDarkCheckbox.Checked ? 1 : 0, RegistryValueKind.DWord);
361+
362+
_registryKey.SetValue("SaveActiveLight", saveActiveDarkCheckbox.Checked ? 1 : 0, RegistryValueKind.DWord);
363+
364+
_registryKey.SetValue("SaveInactiveDark", saveActiveDarkCheckbox.Checked ? 1 : 0, RegistryValueKind.DWord);
365+
366+
_registryKey.SetValue("SaveInactiveLight", saveActiveDarkCheckbox.Checked ? 1 : 0, RegistryValueKind.DWord);
367+
350368
// Save delay settings in an 8-byte long
351369
b = new byte[8];
352370
b[0] = (byte)(delayCheckbox.Checked ? 1 : 0);

Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private static void Main()
5757
Application.EnableVisualStyles();
5858
Application.SetCompatibleTextRenderingDefault(false);
5959
Application.Run(new SysTray());
60-
//GC.KeepAlive(mutex);
60+
GC.KeepAlive(mutex);
6161
}
6262
}
6363
}

Screenshot.cs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -124,27 +124,33 @@ internal static void CaptureWindow(ref ScreenshotTask data)
124124

125125
bool AeroColorToggled = false;
126126
WindowsApi.DWM_COLORIZATION_PARAMS originalParameters = new WindowsApi.DWM_COLORIZATION_PARAMS();
127-
//TODO: reenable
128127
if (Environment.OSVersion.Version.Major >= 6)
129128
{
130-
WindowsApi.DwmGetColorizationParameters(out originalParameters);
131-
if (data.CustomGlass && AeroEnabled())
132-
{
133-
// Original colorization parameters
134-
originalParameters.clrGlassReflectionIntensity = 50;
135-
136-
// Custom colorization parameters
137-
WindowsApi.DWM_COLORIZATION_PARAMS parameters;
138-
WindowsApi.DwmGetColorizationParameters(out parameters);
139-
parameters.clrAfterGlowBalance = 2;
140-
parameters.clrBlurBalance = 29;
141-
parameters.clrColor = ColorToBgra(data.AeroColor);
142-
parameters.nIntensity = 69;
143-
144-
// Call the DwmSetColorizationParameters to make the change take effect.
145-
WindowsApi.DwmSetColorizationParameters(ref parameters, false);
146-
AeroColorToggled = true;
147-
}
129+
try
130+
{
131+
WindowsApi.DwmGetColorizationParameters(out originalParameters);
132+
if (data.CustomGlass && AeroEnabled())
133+
{
134+
// Original colorization parameters
135+
originalParameters.clrGlassReflectionIntensity = 50;
136+
137+
// Custom colorization parameters
138+
WindowsApi.DWM_COLORIZATION_PARAMS parameters;
139+
WindowsApi.DwmGetColorizationParameters(out parameters);
140+
parameters.clrAfterGlowBalance = 2;
141+
parameters.clrBlurBalance = 29;
142+
parameters.clrColor = ColorToBgra(data.AeroColor);
143+
parameters.nIntensity = 69;
144+
145+
// Call the DwmSetColorizationParameters to make the change take effect.
146+
WindowsApi.DwmSetColorizationParameters(ref parameters, false);
147+
AeroColorToggled = true;
148+
}
149+
}
150+
catch (Exception)
151+
{
152+
AeroColorToggled = false; //workaround for Vista Betas
153+
}
148154
}
149155

150156

@@ -239,15 +245,15 @@ internal static void CaptureWindow(ref ScreenshotTask data)
239245
string pathWhiteActive = Path.Combine(data.DiskSaveDirectory, name + "_w1.png");
240246
string pathWhiteInactive = Path.Combine(data.DiskSaveDirectory, name + "_w2.png");
241247

242-
if (File.Exists(pathActive) || File.Exists(pathInactive))
248+
if (File.Exists(pathActive) || File.Exists(pathInactive) || File.Exists(pathWhiteActive) || File.Exists(pathWhiteInactive))
243249
{
244250
for (int i = 1; i < 9999; i++)
245251
{
246252
pathActive = Path.Combine(data.DiskSaveDirectory, name + " " + i + "_b1.png");
247253
pathInactive = Path.Combine(data.DiskSaveDirectory, name + " " + i + "_b2.png");
248254
pathWhiteActive = Path.Combine(data.DiskSaveDirectory, name + " " + i + "_w1.png");
249255
pathWhiteInactive = Path.Combine(data.DiskSaveDirectory, name + " " + i + "_w2.png");
250-
if (!File.Exists(pathActive))
256+
if (!File.Exists(pathActive) && !File.Exists(pathInactive) && !File.Exists(pathWhiteActive) && !File.Exists(pathWhiteInactive))
251257
break;
252258
}
253259
}
@@ -258,6 +264,8 @@ internal static void CaptureWindow(ref ScreenshotTask data)
258264
}
259265
s[0].Dispose();
260266
s[1].Dispose();
267+
s[2].Dispose();
268+
s[3].Dispose();
261269
}
262270

263271
if (data.DoResize)

Settings.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public class Settings
4242
public byte delaySeconds = 3;
4343
public bool clearTypeCheckbox;
4444
public bool shadowCheckbox;
45+
public bool saveActiveDarkCheckbox;
46+
public bool saveActiveLightCheckbox;
47+
public bool saveInactiveDarkCheckbox;
48+
public bool saveInactiveLightCheckbox;
4549
private readonly RegistryKey _registryKey;
4650

4751

@@ -132,6 +136,18 @@ public Settings()
132136
if ((value = _registryKey.GetValue("Shadow")) != null && value.GetType() == (typeof(int)))
133137
shadowCheckbox = ((int)value & 1) == 1;
134138

139+
if ((value = _registryKey.GetValue("SaveActiveDark")) != null && value.GetType() == (typeof(int)))
140+
saveActiveDarkCheckbox = ((int)value & 1) == 1;
141+
142+
if ((value = _registryKey.GetValue("SaveActiveLight")) != null && value.GetType() == (typeof(int)))
143+
saveActiveLightCheckbox = ((int)value & 1) == 1;
144+
145+
if ((value = _registryKey.GetValue("SaveInactiveDark")) != null && value.GetType() == (typeof(int)))
146+
saveInactiveDarkCheckbox = ((int)value & 1) == 1;
147+
148+
if ((value = _registryKey.GetValue("SaveInactiveLight")) != null && value.GetType() == (typeof(int)))
149+
saveInactiveLightCheckbox = ((int)value & 1) == 1;
150+
135151
if ((value = _registryKey.GetValue("Delay")) != null && value.GetType() == (typeof(long)))
136152
{
137153
var b = new byte[8];

0 commit comments

Comments
 (0)