@@ -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 }
0 commit comments