diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index b3f6463a..2ae3f6ad 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -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")] \ No newline at end of file diff --git a/ScreenCapture.cs b/ScreenCapture.cs index 2a388dcb..99c46ed3 100644 --- a/ScreenCapture.cs +++ b/ScreenCapture.cs @@ -449,55 +449,70 @@ public Image GetImageByPath(string path) /// A bitmap image representing what we captured. 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; + } } /// @@ -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; diff --git a/app.manifest b/app.manifest index bcc1e280..2f0394a2 100644 --- a/app.manifest +++ b/app.manifest @@ -3,7 +3,7 @@ + version="2.3.6.8"/> True/PM diff --git a/changelog.txt b/changelog.txt index d2e1cca9..d1f47bea 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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. diff --git a/interface/FormAbout.resx b/interface/FormAbout.resx index 81c6b375..ca0b5d01 100644 --- a/interface/FormAbout.resx +++ b/interface/FormAbout.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Auto Screen Capture 2.3.6.7 ("Boombayah") + Auto Screen Capture 2.3.6.8 ("Boombayah") Developed by Gavin Kendall (2008 - 2021) SourceForge Project Site @@ -128,12 +128,13 @@ GitHub Project Site https://github.com/gavinkendall/autoscreen/ - 2.3.6.7 + 2.3.6.8 -Fixed bug with emailing screenshots from a one time schedule. +This version should no longer crash when Windows is locked while a screenshot is being taken. 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.