Skip to content

Commit 4d5dde2

Browse files
2.3.3.7 - Memory leak fix.
1 parent ab565a1 commit 4d5dde2

File tree

5 files changed

+62
-53
lines changed

5 files changed

+62
-53
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.3.6")]
36-
[assembly: AssemblyFileVersion("2.3.3.6")]
35+
[assembly: AssemblyVersion("2.3.3.7")]
36+
[assembly: AssemblyFileVersion("2.3.3.7")]
3737
[assembly: NeutralResourcesLanguageAttribute("en-CA")]

ScreenCapture.cs

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public class ScreenCapture
3939
[StructLayout(LayoutKind.Sequential)]
4040
private struct CURSORINFO
4141
{
42-
public Int32 cbSize;
43-
public Int32 flags;
42+
public int cbSize;
43+
public int flags;
4444
public IntPtr hCursor;
4545
public POINTAPI ptScreenPos;
4646
}
@@ -70,8 +70,8 @@ private struct POINTAPI
7070
[DllImport("user32.dll", SetLastError = true)]
7171
private static extern bool DrawIconEx(IntPtr hdc, int xLeft, int yTop, IntPtr hIcon, int cxWidth, int cyHeight, int istepIfAniCur, IntPtr hbrFlickerFreeDraw, int diFlags);
7272

73-
private const Int32 CURSOR_SHOWING = 0x0001;
74-
private const Int32 DI_NORMAL = 0x0003;
73+
private const int CURSOR_SHOWING = 0x0001;
74+
private const int DI_NORMAL = 0x0003;
7575

7676
[DllImport("user32.dll")]
7777
private static extern bool SetForegroundWindow(IntPtr hWnd);
@@ -103,56 +103,56 @@ internal struct WINDOWPLACEMENT
103103
public int length;
104104
public int flags;
105105
public ShowWindowCommands showCmd;
106-
public System.Drawing.Point ptMinPosition;
107-
public System.Drawing.Point ptMaxPosition;
108-
public System.Drawing.Rectangle rcNormalPosition;
106+
public Point ptMinPosition;
107+
public Point ptMaxPosition;
108+
public Rectangle rcNormalPosition;
109109
}
110110

111111
[DllImport("user32.dll")]
112112
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
113113

114-
public const int ENUM_CURRENT_SETTINGS = -1;
114+
private const int ENUM_CURRENT_SETTINGS = -1;
115115

116116
[DllImport("user32.dll")]
117-
public static extern bool EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);
117+
private static extern bool EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);
118118

119119
[StructLayout(LayoutKind.Sequential)]
120-
public struct DEVMODE
120+
private struct DEVMODE
121121
{
122122
private const int CCHDEVICENAME = 0x20;
123123
private const int CCHFORMNAME = 0x20;
124124
[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;
125+
private string dmDeviceName;
126+
private short dmSpecVersion;
127+
private short dmDriverVersion;
128+
internal short dmSize;
129+
private short dmDriverExtra;
130+
private int dmFields;
131+
private int dmPositionX;
132+
private int dmPositionY;
133+
private ScreenOrientation dmDisplayOrientation;
134+
private int dmDisplayFixedOutput;
135+
private short dmColor;
136+
private short dmDuplex;
137+
private short dmYResolution;
138+
private short dmTTOption;
139+
private short dmCollate;
140140
[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;
141+
private string dmFormName;
142+
private short dmLogPixels;
143+
private int dmBitsPerPel;
144+
internal int dmPelsWidth;
145+
internal int dmPelsHeight;
146+
private int dmDisplayFlags;
147+
private int dmDisplayFrequency;
148+
private int dmICMMethod;
149+
private int dmICMIntent;
150+
private int dmMediaType;
151+
private int dmDitherType;
152+
private int dmReserved1;
153+
private int dmReserved2;
154+
private int dmPanningWidth;
155+
private int dmPanningHeight;
156156
}
157157

158158
/// <summary>
@@ -356,12 +356,16 @@ private void SaveToFile(string path, ImageFormat format, int jpegQuality, Bitmap
356356
bitmap.Save(path, format.Format);
357357
}
358358

359+
bitmap.Dispose();
360+
359361
Log.WriteMessage("Screenshot saved to file at path \"" + path + "\"");
360362
}
361363
}
362-
catch (Exception ex)
364+
catch (Exception)
363365
{
364-
Log.WriteExceptionMessage("ScreenCapture::SaveToFile", ex);
366+
// We want to write to the error file instead of writing an exception just in case the user
367+
// has ExitOnError set and the exception causes the application to exit.
368+
Log.WriteErrorMessage("There was an error encountered when saving the screenshot image.");
365369
}
366370
}
367371

@@ -372,8 +376,11 @@ private void SaveToFile(string path, ImageFormat format, int jpegQuality, Bitmap
372376
/// <returns>A struct having the screen, display device width, and display device height.</returns>
373377
public static DeviceResolution GetDeviceResolution(System.Windows.Forms.Screen screen)
374378
{
375-
DEVMODE dm = new DEVMODE();
376-
dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
379+
DEVMODE dm = new DEVMODE
380+
{
381+
dmSize = (short)Marshal.SizeOf(typeof(DEVMODE))
382+
};
383+
377384
EnumDisplaySettings(screen.DeviceName, ENUM_CURRENT_SETTINGS, ref dm);
378385

379386
DeviceResolution deviceResolution = new DeviceResolution()
@@ -478,7 +485,7 @@ public Bitmap GetScreenBitmap(int x, int y, int width, int height, int resolutio
478485
graphicsDestination.Flush();
479486

480487
CaptureError = false;
481-
488+
482489
return bitmapDestination;
483490
}
484491

@@ -613,7 +620,7 @@ public string GetActiveWindowProcessName()
613620
/// <summary>
614621
/// Gets the bitmap images for the avaialble screens.
615622
/// </summary>
616-
/// <param name="component">The component to capture. This could be the active window or a screen.</param>
623+
/// <param name="component">The component index.</param>
617624
/// <param name="x">The X value of the bitmap.</param>
618625
/// <param name="y">The Y value of the bitmap.</param>
619626
/// <param name="width">The Width value of the bitmap.</param>
@@ -669,7 +676,7 @@ public bool SaveScreenshot(int jpegQuality, Screenshot screenshot, ScreenshotCol
669676
try
670677
{
671678
int filepathLengthLimit = Convert.ToInt32(Settings.Application.GetByKey("FilepathLengthLimit", DefaultSettings.FilepathLengthLimit).Value);
672-
679+
673680
if (!string.IsNullOrEmpty(screenshot.Path))
674681
{
675682
if (screenshot.Path.Length > filepathLengthLimit)
@@ -709,7 +716,7 @@ public bool SaveScreenshot(int jpegQuality, Screenshot screenshot, ScreenshotCol
709716

710717
return false;
711718
}
712-
719+
713720
ApplicationWarning = true;
714721
}
715722
}

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.3.6"/>
6+
version="2.3.3.7"/>
77
<asmv3:application>
88
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
99
<dpiAware>True/PM</dpiAware>

interface/FormAbout.resx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@
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.3.6 ("Boombayah")
122-
Developed by Gavin Kendall (2008 - 2020)
121+
<value>Auto Screen Capture 2.3.3.7 ("Boombayah")
122+
Developed by Gavin Kendall (2008 - 2021)
123123

124124
SourceForge Project Site
125125
https://autoscreen.sourceforge.io/
@@ -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.7 Memory leak fix.
325326
2.3.3.6 Active Window Title text comparison includes type of match to use during text comparison.
326327
2.3.3.5 Application Focus now has Delay Before and Delay After options.
327328
2.3.3.4 A bug fix for saving of file when adding screenshot to collection.

settings/Settings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public static void Initialize()
177177
_versionCollection.Add(new Version(CODENAME_BOOMBAYAH, "2.3.3.3")); // An internal list of image hash values are stored when emailing screenshots so we do not email duplicate images.
178178
_versionCollection.Add(new Version(CODENAME_BOOMBAYAH, "2.3.3.4")); // A bug fix for saving of file when adding screenshot to collection.
179179
_versionCollection.Add(new Version(CODENAME_BOOMBAYAH, "2.3.3.5")); // Application Focus now has Delay Before and Delay After options.
180+
_versionCollection.Add(new Version(CODENAME_BOOMBAYAH, "2.3.3.6")); // Active Window Title text comparison includes type of match to use during text comparison.
180181

181182
Application = new SettingCollection
182183
{

0 commit comments

Comments
 (0)