Skip to content

Commit 49f32fe

Browse files
committed
2.3.3.0 - Application Focus moved from Screen to Setup. Fixed Application Focus bug with Active Window Title. Renamed user setting keys. New method for capturing device display resolution.
1 parent 599d3d9 commit 49f32fe

29 files changed

+681
-610
lines changed

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.3.2.9")]
36-
[assembly: AssemblyFileVersion("2.3.2.9")]
35+
[assembly: AssemblyVersion("2.3.3.0")]
36+
[assembly: AssemblyFileVersion("2.3.3.0")]
3737
[assembly: NeutralResourcesLanguageAttribute("en-CA")]

ScreenCapture.cs

Lines changed: 163 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using System.Text;
2828
using System.IO;
2929
using System.Security.Cryptography;
30+
using System.Windows.Forms;
3031

3132
namespace AutoScreenCapture
3233
{
@@ -110,6 +111,71 @@ internal struct WINDOWPLACEMENT
110111
[DllImport("user32.dll")]
111112
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
112113

114+
public const int ENUM_CURRENT_SETTINGS = -1;
115+
116+
[DllImport("user32.dll")]
117+
public static extern bool EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);
118+
119+
[StructLayout(LayoutKind.Sequential)]
120+
public struct DEVMODE
121+
{
122+
private const int CCHDEVICENAME = 0x20;
123+
private const int CCHFORMNAME = 0x20;
124+
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
125+
public string dmDeviceName;
126+
public short dmSpecVersion;
127+
public short dmDriverVersion;
128+
public short dmSize;
129+
public short dmDriverExtra;
130+
public int dmFields;
131+
public int dmPositionX;
132+
public int dmPositionY;
133+
public ScreenOrientation dmDisplayOrientation;
134+
public int dmDisplayFixedOutput;
135+
public short dmColor;
136+
public short dmDuplex;
137+
public short dmYResolution;
138+
public short dmTTOption;
139+
public short dmCollate;
140+
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
141+
public string dmFormName;
142+
public short dmLogPixels;
143+
public int dmBitsPerPel;
144+
public int dmPelsWidth;
145+
public int dmPelsHeight;
146+
public int dmDisplayFlags;
147+
public int dmDisplayFrequency;
148+
public int dmICMMethod;
149+
public int dmICMIntent;
150+
public int dmMediaType;
151+
public int dmDitherType;
152+
public int dmReserved1;
153+
public int dmReserved2;
154+
public int dmPanningWidth;
155+
public int dmPanningHeight;
156+
}
157+
158+
/// <summary>
159+
/// A struct containing a Windows Forms screen object, display device width, and display device height.
160+
/// </summary>
161+
public struct DeviceResolution
162+
{
163+
/// <summary>
164+
/// A Windows Forms screen object.
165+
/// </summary>
166+
public System.Windows.Forms.Screen screen;
167+
168+
/// <summary>
169+
/// The width of the display device.
170+
/// </summary>
171+
public int width;
172+
173+
/// <summary>
174+
/// The height of the display device.
175+
/// </summary>
176+
public int height;
177+
}
178+
113179
/// <summary>
114180
/// The minimum capture limit.
115181
/// </summary>
@@ -220,6 +286,86 @@ internal struct WINDOWPLACEMENT
220286
/// </summary>
221287
public bool CaptureNow { get; set; }
222288

289+
private ImageCodecInfo GetEncoderInfo(string mimeType)
290+
{
291+
var encoders = ImageCodecInfo.GetImageEncoders();
292+
return encoders.FirstOrDefault(t => t.MimeType == mimeType);
293+
}
294+
295+
private static string GetMD5Hash(Bitmap bitmap, ImageFormat format)
296+
{
297+
byte[] bytes = null;
298+
299+
using (MemoryStream ms = new MemoryStream())
300+
{
301+
bitmap.Save(ms, format.Format);
302+
bytes = ms.ToArray();
303+
}
304+
305+
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
306+
307+
byte[] hash = md5.ComputeHash(bytes);
308+
309+
StringBuilder sb = new StringBuilder();
310+
311+
foreach (byte b in hash)
312+
{
313+
sb.Append(b.ToString("x2").ToLower());
314+
}
315+
316+
return sb.ToString();
317+
}
318+
319+
private void SaveToFile(string path, ImageFormat format, int jpegQuality, Bitmap bitmap)
320+
{
321+
try
322+
{
323+
if (bitmap != null && format != null && !string.IsNullOrEmpty(path))
324+
{
325+
if (format.Name.Equals(ImageFormatSpec.NAME_JPEG))
326+
{
327+
var encoderParams = new EncoderParameters(1);
328+
encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, jpegQuality);
329+
330+
var encoderInfo = GetEncoderInfo("image/jpeg");
331+
332+
bitmap.Save(path, encoderInfo, encoderParams);
333+
}
334+
else
335+
{
336+
bitmap.Save(path, format.Format);
337+
}
338+
339+
Log.WriteMessage("Screenshot saved to file at path \"" + path + "\"");
340+
}
341+
}
342+
catch (Exception ex)
343+
{
344+
Log.WriteExceptionMessage("ScreenCapture::SaveToFile", ex);
345+
}
346+
}
347+
348+
/// <summary>
349+
/// Gets the resolution of the display device associated with the screen.
350+
/// </summary>
351+
/// <param name="screen">The Windows Forms screen object associated with the display device.</param>
352+
/// <returns>A struct having the screen, display device width, and display device height.</returns>
353+
public static DeviceResolution GetDeviceResolution(System.Windows.Forms.Screen screen)
354+
{
355+
DEVMODE dm = new DEVMODE();
356+
dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
357+
EnumDisplaySettings(screen.DeviceName, ENUM_CURRENT_SETTINGS, ref dm);
358+
359+
DeviceResolution deviceResolution = new DeviceResolution()
360+
{
361+
screen = screen,
362+
width = dm.dmPelsWidth,
363+
height = dm.dmPelsHeight
364+
};
365+
366+
return deviceResolution;
367+
}
368+
223369
/// <summary>
224370
/// Gets the screenshot image from an image file. This is used when we want to show screenshot images.
225371
/// </summary>
@@ -507,7 +653,7 @@ public bool GetScreenImages(int component, int x, int y, int width, int height,
507653
/// <param name="screenshotCollection">A collection of screenshot objects.</param>
508654
/// <returns>A boolean to determine if we successfully saved the screenshot.</returns>
509655
public bool SaveScreenshot(string path, ImageFormat format, int component, ScreenshotType screenshotType, int jpegQuality,
510-
Guid viewId, Bitmap bitmap, string label, string windowTitle, string processName, ScreenshotCollection screenshotCollection, string applicationFocus)
656+
Guid viewId, Bitmap bitmap, string label, string windowTitle, string processName, ScreenshotCollection screenshotCollection)
511657
{
512658
try
513659
{
@@ -522,26 +668,6 @@ public bool SaveScreenshot(string path, ImageFormat format, int component, Scree
522668
path = path.Substring(0, filepathLengthLimit);
523669
}
524670

525-
if (!string.IsNullOrEmpty(applicationFocus))
526-
{
527-
Process[] process = Process.GetProcessesByName(applicationFocus);
528-
529-
foreach (var item in process)
530-
{
531-
var proc = Process.GetProcessById(item.Id);
532-
533-
IntPtr handle = proc.MainWindowHandle;
534-
SetForegroundWindow(handle);
535-
536-
var placement = GetPlacement(proc.MainWindowHandle);
537-
538-
if (placement.showCmd == ShowWindowCommands.Minimized)
539-
{
540-
ShowWindowAsync(proc.MainWindowHandle, (int)ShowWindowCommands.Normal);
541-
}
542-
}
543-
}
544-
545671
Log.WriteMessage("Attempting to write image to file at path \"" + path + "\"");
546672

547673
// This is a normal path used in Windows (such as "C:\screenshots\").
@@ -701,63 +827,30 @@ public bool SaveScreenshot(string path, ImageFormat format, int component, Scree
701827
}
702828
}
703829

704-
private void SaveToFile(string path, ImageFormat format, int jpegQuality, Bitmap bitmap)
705-
{
706-
try
707-
{
708-
if (bitmap != null && format != null && !string.IsNullOrEmpty(path))
709-
{
710-
if (format.Name.Equals(ImageFormatSpec.NAME_JPEG))
711-
{
712-
var encoderParams = new EncoderParameters(1);
713-
encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, jpegQuality);
714-
715-
var encoderInfo = GetEncoderInfo("image/jpeg");
716-
717-
bitmap.Save(path, encoderInfo, encoderParams);
718-
}
719-
else
720-
{
721-
bitmap.Save(path, format.Format);
722-
}
723-
724-
Log.WriteMessage("Screenshot saved to file at path \"" + path + "\"");
725-
}
726-
}
727-
catch (Exception ex)
728-
{
729-
Log.WriteExceptionMessage("ScreenCapture::SaveToFile", ex);
730-
}
731-
}
732-
733-
private ImageCodecInfo GetEncoderInfo(string mimeType)
830+
/// <summary>
831+
/// Sets the application focus to the defined application using a given process name.
832+
/// </summary>
833+
/// <param name="applicationFocus">The name of the process of the application to focus.</param>
834+
public static void SetApplicationFocus(string applicationFocus)
734835
{
735-
var encoders = ImageCodecInfo.GetImageEncoders();
736-
return encoders.FirstOrDefault(t => t.MimeType == mimeType);
737-
}
836+
if (string.IsNullOrEmpty(applicationFocus)) return;
738837

739-
private static string GetMD5Hash(Bitmap bitmap, ImageFormat format)
740-
{
741-
byte[] bytes = null;
838+
Process[] process = Process.GetProcessesByName(applicationFocus);
742839

743-
using (MemoryStream ms = new MemoryStream())
840+
foreach (var item in process)
744841
{
745-
bitmap.Save(ms, format.Format);
746-
bytes = ms.ToArray();
747-
}
842+
var proc = Process.GetProcessById(item.Id);
748843

749-
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
844+
IntPtr handle = proc.MainWindowHandle;
845+
SetForegroundWindow(handle);
750846

751-
byte[] hash = md5.ComputeHash(bytes);
847+
var placement = GetPlacement(proc.MainWindowHandle);
752848

753-
StringBuilder sb = new StringBuilder();
754-
755-
foreach (byte b in hash)
756-
{
757-
sb.Append(b.ToString("x2").ToLower());
849+
if (placement.showCmd == ShowWindowCommands.Minimized)
850+
{
851+
ShowWindowAsync(proc.MainWindowHandle, (int)ShowWindowCommands.Normal);
852+
}
758853
}
759-
760-
return sb.ToString();
761854
}
762855
}
763856
}

app.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<assemblyIdentity
44
type="win32"
55
name="GavinKendall.AutoScreenCapture"
6-
version="2.3.2.9"/>
6+
version="2.3.3.0"/>
77
<asmv3:application>
88
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
99
<dpiAware>True/PM</dpiAware>

interface/FormAbout.resx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120120
<data name="richTextBoxDeveloper.Text" xml:space="preserve">
121-
<value>Auto Screen Capture 2.3.2.9 ("Boombayah")
121+
<value>Auto Screen Capture 2.3.3.0 ("Boombayah")
122122
Developed by Gavin Kendall (2008 - 2020)
123123

124124
SourceForge Project Site
@@ -322,6 +322,7 @@ END OF TERMS AND CONDITIONS</value>
322322
</data>
323323
<data name="richTextBoxChangelog.Text" xml:space="preserve">
324324
<value>Codename "Boombayah"
325+
2.3.3.0 Application Focus moved from Screen to Setup. Fixed Application Focus bug with Active Window Title. Renamed user setting keys. New method for capturing device display resolution.
325326
2.3.2.9 Application Focus implemented for Screen.
326327
2.3.2.8 Changelog added to About Auto Screen Capture window. Fixed bug with hidden system tray icon so no notification balloon appears when system tray icon is hidden.
327328
2.3.2.7 Quarter Year tag implemented so you can have %quarteryear% return "3" if we're currently in the third quarter of the current year.

interface/FormEnterPassphrase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private void buttonUnlock_Click(object sender, EventArgs e)
5151
{
5252
if (string.IsNullOrEmpty(textBoxPassphrase.Text)) return;
5353

54-
if (Security.Hash(textBoxPassphrase.Text).Equals(Settings.User.GetByKey("StringPassphrase", DefaultSettings.StringPassphrase).Value))
54+
if (Security.Hash(textBoxPassphrase.Text).Equals(Settings.User.GetByKey("Passphrase", DefaultSettings.Passphrase).Value))
5555
{
5656
Log.WriteDebugMessage("Screen capture session was successfully unlocked by " + Environment.UserName + " on " + Environment.MachineName);
5757

0 commit comments

Comments
 (0)