Skip to content

Commit b1a7b55

Browse files
committed
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.
1 parent c81fbaf commit b1a7b55

File tree

5 files changed

+53
-36
lines changed

5 files changed

+53
-36
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.6.7")]
36-
[assembly: AssemblyFileVersion("2.3.6.7")]
35+
[assembly: AssemblyVersion("2.3.6.8")]
36+
[assembly: AssemblyFileVersion("2.3.6.8")]
3737
[assembly: NeutralResourcesLanguageAttribute("en-CA")]

ScreenCapture.cs

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -449,55 +449,70 @@ public Image GetImageByPath(string path)
449449
/// <returns>A bitmap image representing what we captured.</returns>
450450
public Bitmap GetScreenBitmap(int source, int component, int x, int y, int width, int height, bool mouse)
451451
{
452-
if (width > 0 && height > 0)
452+
try
453453
{
454-
if (source > 0 && component > -1)
454+
if (width > 0 && height > 0)
455455
{
456-
try
456+
if (source > 0 && component > -1)
457457
{
458-
// Test if we can acquire the actual screen from Windows and if we can't just let this
459-
// method catch the out of bounds exception error.
460-
System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.AllScreens[component];
461-
}
462-
catch
463-
{
464-
return null;
458+
try
459+
{
460+
// Test if we can acquire the actual screen from Windows and if we can't just let this
461+
// method catch the out of bounds exception error.
462+
System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.AllScreens[component];
463+
}
464+
catch
465+
{
466+
return null;
467+
}
465468
}
466-
}
467469

468-
Size blockRegionSize = new Size(width, height);
470+
Size blockRegionSize = new Size(width, height);
469471

470-
Bitmap bmp = new Bitmap(width, height);
471-
472-
using (Graphics g = Graphics.FromImage(bmp))
473-
{
474-
g.CopyFromScreen(x, y, 0, 0, blockRegionSize, CopyPixelOperation.SourceCopy);
472+
Bitmap bmp = new Bitmap(width, height);
475473

476-
if (mouse)
474+
using (Graphics g = Graphics.FromImage(bmp))
477475
{
478-
CURSORINFO pci;
479-
pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
476+
g.CopyFromScreen(x, y, 0, 0, blockRegionSize, CopyPixelOperation.SourceCopy);
480477

481-
if (GetCursorInfo(out pci))
478+
if (mouse)
482479
{
483-
if (pci.flags == CURSOR_SHOWING)
480+
CURSORINFO pci;
481+
pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
482+
483+
if (GetCursorInfo(out pci))
484484
{
485-
var hdc = g.GetHdc();
486-
DrawIconEx(hdc, pci.ptScreenPos.x - x, pci.ptScreenPos.y - y, pci.hCursor, 0, 0, 0, IntPtr.Zero, DI_NORMAL);
487-
g.ReleaseHdc();
485+
if (pci.flags == CURSOR_SHOWING)
486+
{
487+
var hdc = g.GetHdc();
488+
DrawIconEx(hdc, pci.ptScreenPos.x - x, pci.ptScreenPos.y - y, pci.hCursor, 0, 0, 0, IntPtr.Zero, DI_NORMAL);
489+
g.ReleaseHdc();
490+
}
488491
}
489492
}
490493
}
494+
495+
CaptureError = false;
496+
497+
return bmp;
491498
}
492499

493-
CaptureError = false;
500+
CaptureError = true;
494501

495-
return bmp;
502+
return null;
496503
}
504+
catch (Exception ex)
505+
{
506+
// Don't log an error if Windows is locked at the time a screenshot was taken.
507+
if (!ex.Message.Equals("The handle is invalid"))
508+
{
509+
_log.WriteExceptionMessage("ScreenCapture::GetScreenBitmap", ex);
510+
}
497511

498-
CaptureError = true;
512+
CaptureError = true;
499513

500-
return null;
514+
return null;
515+
}
501516
}
502517

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

542557
CaptureError = true;

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

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Auto Screen Capture by Gavin Kendall
33

44

55
Codename "Boombayah"
6+
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.
67
2.3.6.7 Fixed bug with emailing screenshots from a one time schedule.
78
2.3.6.6 Execution level changed from highestAvailable to asInvoker.
89
2.3.6.5 Execution level changed from requireAdministrator to highestAvailable.

interface/FormAbout.resx

Lines changed: 4 additions & 3 deletions
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="richTextBoxApplication.Text" xml:space="preserve">
121-
<value>Auto Screen Capture 2.3.6.7 ("Boombayah")
121+
<value>Auto Screen Capture 2.3.6.8 ("Boombayah")
122122
Developed by Gavin Kendall (2008 - 2021)
123123

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

133-
Fixed bug with emailing screenshots from a one time schedule.</value>
133+
This version should no longer crash when Windows is locked while a screenshot is being taken.</value>
134134
</data>
135135
<data name="richTextBoxChangelog.Text" xml:space="preserve">
136136
<value>Codename "Boombayah"
137+
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.
137138
2.3.6.7 Fixed bug with emailing screenshots from a one time schedule.
138139
2.3.6.6 Execution level changed from highestAvailable to asInvoker.
139140
2.3.6.5 Execution level changed from requireAdministrator to highestAvailable.

0 commit comments

Comments
 (0)