Skip to content

Commit

Permalink
2.3.6.8 - Fixed bug with "the handle is invalid" to prevent applicati…
Browse files Browse the repository at this point in the history
…on from crashing when Windows is locked. The check on the invalid handle was accidentally removed in 2.3.4.1 but has now been restored.
  • Loading branch information
gavinkendall committed Oct 29, 2021
1 parent c81fbaf commit b1a7b55
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.3.6.7")]
[assembly: AssemblyFileVersion("2.3.6.7")]
[assembly: AssemblyVersion("2.3.6.8")]
[assembly: AssemblyFileVersion("2.3.6.8")]
[assembly: NeutralResourcesLanguageAttribute("en-CA")]
75 changes: 45 additions & 30 deletions ScreenCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,55 +449,70 @@ public Image GetImageByPath(string path)
/// <returns>A bitmap image representing what we captured.</returns>
public Bitmap GetScreenBitmap(int source, int component, int x, int y, int width, int height, bool mouse)
{
if (width > 0 && height > 0)
try
{
if (source > 0 && component > -1)
if (width > 0 && height > 0)
{
try
if (source > 0 && component > -1)
{
// Test if we can acquire the actual screen from Windows and if we can't just let this
// method catch the out of bounds exception error.
System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.AllScreens[component];
}
catch
{
return null;
try
{
// Test if we can acquire the actual screen from Windows and if we can't just let this
// method catch the out of bounds exception error.
System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.AllScreens[component];
}
catch
{
return null;
}
}
}

Size blockRegionSize = new Size(width, height);
Size blockRegionSize = new Size(width, height);

Bitmap bmp = new Bitmap(width, height);

using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(x, y, 0, 0, blockRegionSize, CopyPixelOperation.SourceCopy);
Bitmap bmp = new Bitmap(width, height);

if (mouse)
using (Graphics g = Graphics.FromImage(bmp))
{
CURSORINFO pci;
pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
g.CopyFromScreen(x, y, 0, 0, blockRegionSize, CopyPixelOperation.SourceCopy);

if (GetCursorInfo(out pci))
if (mouse)
{
if (pci.flags == CURSOR_SHOWING)
CURSORINFO pci;
pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));

if (GetCursorInfo(out pci))
{
var hdc = g.GetHdc();
DrawIconEx(hdc, pci.ptScreenPos.x - x, pci.ptScreenPos.y - y, pci.hCursor, 0, 0, 0, IntPtr.Zero, DI_NORMAL);
g.ReleaseHdc();
if (pci.flags == CURSOR_SHOWING)
{
var hdc = g.GetHdc();
DrawIconEx(hdc, pci.ptScreenPos.x - x, pci.ptScreenPos.y - y, pci.hCursor, 0, 0, 0, IntPtr.Zero, DI_NORMAL);
g.ReleaseHdc();
}
}
}
}

CaptureError = false;

return bmp;
}

CaptureError = false;
CaptureError = true;

return bmp;
return null;
}
catch (Exception ex)
{
// Don't log an error if Windows is locked at the time a screenshot was taken.
if (!ex.Message.Equals("The handle is invalid"))
{
_log.WriteExceptionMessage("ScreenCapture::GetScreenBitmap", ex);
}

CaptureError = true;
CaptureError = true;

return null;
return null;
}
}

/// <summary>
Expand Down Expand Up @@ -536,7 +551,7 @@ public Bitmap GetActiveWindowBitmap()
// Don't log an error if Windows is locked at the time a screenshot was taken.
if (!ex.Message.Equals("The handle is invalid"))
{
_log.WriteExceptionMessage("ScreenCapture::GetScreenBitmap", ex);
_log.WriteExceptionMessage("ScreenCapture::GetActiveWindowBitmap", ex);
}

CaptureError = true;
Expand Down
2 changes: 1 addition & 1 deletion app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<assemblyIdentity
type="win32"
name="GavinKendall.AutoScreenCapture"
version="2.3.6.7"/>
version="2.3.6.8"/>
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>True/PM</dpiAware>
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Auto Screen Capture by Gavin Kendall


Codename "Boombayah"
2.3.6.8 Fixed bug with "the handle is invalid" to prevent application from crashing when Windows is locked. The check on the invalid handle was accidentally removed in 2.3.4.1 but has now been restored.
2.3.6.7 Fixed bug with emailing screenshots from a one time schedule.
2.3.6.6 Execution level changed from highestAvailable to asInvoker.
2.3.6.5 Execution level changed from requireAdministrator to highestAvailable.
Expand Down
7 changes: 4 additions & 3 deletions interface/FormAbout.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="richTextBoxApplication.Text" xml:space="preserve">
<value>Auto Screen Capture 2.3.6.7 ("Boombayah")
<value>Auto Screen Capture 2.3.6.8 ("Boombayah")
Developed by Gavin Kendall (2008 - 2021)

SourceForge Project Site
Expand All @@ -128,12 +128,13 @@ GitHub Project Site
https://github.com/gavinkendall/autoscreen/</value>
</data>
<data name="richTextBoxReleaseNotes.Text" xml:space="preserve">
<value>2.3.6.7
<value>2.3.6.8

Fixed bug with emailing screenshots from a one time schedule.</value>
This version should no longer crash when Windows is locked while a screenshot is being taken.</value>
</data>
<data name="richTextBoxChangelog.Text" xml:space="preserve">
<value>Codename "Boombayah"
2.3.6.8 Fixed bug with "the handle is invalid" to prevent application from crashing when Windows is locked. The check on the invalid handle was accidentally removed in 2.3.4.1 but has now been restored.
2.3.6.7 Fixed bug with emailing screenshots from a one time schedule.
2.3.6.6 Execution level changed from highestAvailable to asInvoker.
2.3.6.5 Execution level changed from requireAdministrator to highestAvailable.
Expand Down

0 comments on commit b1a7b55

Please sign in to comment.