@@ -46,14 +46,14 @@ public partial class MainForm : Form, IMessageFilter
4646 private string _listText ;
4747 private int _fps ;
4848 private decimal _scale ;
49- private object _lockObject ;
5049 private bool _refreshImage ;
5150 private bool _imageTab ;
5251 private bool _isRecording ;
5352 private bool _captureCursor ;
5453 private DateTime ? _startRecordingTime ;
55- private VideoFileWriter _videoWriter ;
5654 private Bitmap _image ;
55+ private readonly object _lockObject ;
56+ private readonly VideoFileWriter _videoWriter ;
5757
5858 private AccurateTimer _captureWindowTimer ;
5959 private AccurateTimer _updatePictureBoxTimer ;
@@ -67,10 +67,11 @@ public MainForm()
6767
6868 AppDomain . CurrentDomain . UnhandledException += OnCurrentDomainUnhandledException ;
6969 Application . ThreadException += OnThreadException ;
70+ using var currentProcess = Process . GetCurrentProcess ( ) ;
7071
7172 _lockObject = new object ( ) ;
7273 _isButtonTargetMouseDown = false ;
73- _processId = Process . GetCurrentProcess ( ) . Id ;
74+ _processId = currentProcess . Id ;
7475 _messageId = User32 . RegisterWindowMessage ( "WINDOW_TEXT_EXTRACTOR_HOOK" ) ;
7576 _64BitFilePath = string . Empty ;
7677 _informationFileName = string . Empty ;
@@ -132,8 +133,7 @@ protected override void OnLoad(EventArgs e)
132133 _64BitFilePath = Path . Combine ( directoryName , fileName ) ;
133134 if ( ! File . Exists ( _64BitFilePath ) )
134135 {
135- var message = string . Format ( "{0} is not found." , fileName ) ;
136- MessageBox . Show ( message , AssemblyUtils . AssemblyTitle , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
136+ MessageBox . Show ( $ "{ fileName } is not found.", AssemblyUtils . AssemblyTitle , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
137137 Close ( ) ;
138138 return ;
139139 }
@@ -345,7 +345,7 @@ private void menuItemSaveEnvironmentAs_Click(object sender, EventArgs e)
345345 var builder = new StringBuilder ( 1024 ) ;
346346 foreach ( var variableKey in variables . Keys )
347347 {
348- builder . AppendFormat ( $ "{ variableKey . PadRight ( paddingSize ) } : { variables [ variableKey ] } { Environment . NewLine } ") ;
348+ builder . AppendLine ( $ "{ variableKey , - paddingSize } : { variables [ variableKey ] } ") ;
349349 }
350350 content = builder . ToString ( ) ;
351351 }
@@ -357,10 +357,13 @@ private void menuItemSaveEnvironmentAs_Click(object sender, EventArgs e)
357357
358358 private void menuItemFont_Click ( object sender , EventArgs e )
359359 {
360- var dialog = new FontDialog ( ) ;
361- dialog . ShowHelp = false ;
362- dialog . ShowColor = false ;
363- dialog . Font = txtContent . Font ;
360+ var dialog = new FontDialog
361+ {
362+ ShowHelp = false ,
363+ ShowColor = false ,
364+ Font = txtContent . Font
365+ } ;
366+
364367 if ( dialog . ShowDialog ( ) != DialogResult . Cancel )
365368 {
366369 txtContent . Font = dialog . Font ;
@@ -644,7 +647,7 @@ public bool PreFilterMessage(ref Message m)
644647 return false ;
645648 }
646649
647- var process = Process . GetProcessById ( element . Current . ProcessId ) ;
650+ using var process = Process . GetProcessById ( element . Current . ProcessId ) ;
648651 if ( element . Current . IsPassword )
649652 {
650653 if ( process . ProcessName . ToLower ( ) == "iexplore" )
@@ -667,7 +670,7 @@ public bool PreFilterMessage(ref Message m)
667670 Process . Start ( new ProcessStartInfo
668671 {
669672 FileName = _64BitFilePath ,
670- Arguments = string . Format ( "{0} {1} {2}" , Handle . ToInt32 ( ) , element . Current . NativeWindowHandle , _messageId )
673+ Arguments = $ " { Handle . ToInt32 ( ) } { element . Current . NativeWindowHandle } { _messageId } "
671674 } ) ;
672675 }
673676 else
@@ -701,11 +704,9 @@ public bool PreFilterMessage(ref Message m)
701704 }
702705 else
703706 {
704- using ( var image = WindowUtils . CaptureWindow ( windowHandle , captureCursor ) )
705- {
706- var newImage = ImageUtils . ResizeImage ( image , ( int ) ( image . Width * scale ) , ( int ) ( image . Height * scale ) ) ;
707- FillImage ( newImage ) ;
708- }
707+ using var image = WindowUtils . CaptureWindow ( windowHandle , captureCursor ) ;
708+ var newImage = ImageUtils . ResizeImage ( image , ( int ) ( image . Width * scale ) , ( int ) ( image . Height * scale ) ) ;
709+ FillImage ( newImage ) ;
709710 }
710711 var windowInformation = WindowUtils . GetWindowInformation ( windowHandle , cursorPosition ) ;
711712 FillInformation ( windowInformation ) ;
@@ -776,10 +777,8 @@ private void CaptureWindowCallback()
776777 }
777778 else
778779 {
779- using ( var sourceImage = WindowUtils . CaptureWindow ( windowHandle , captureCursor ) )
780- {
781- newImage = ImageUtils . ResizeImage ( sourceImage , ( int ) ( sourceImage . Width * scale ) , ( int ) ( sourceImage . Height * scale ) ) ;
782- }
780+ using var sourceImage = WindowUtils . CaptureWindow ( windowHandle , captureCursor ) ;
781+ newImage = ImageUtils . ResizeImage ( sourceImage , ( int ) ( sourceImage . Width * scale ) , ( int ) ( sourceImage . Height * scale ) ) ;
783782 }
784783 }
785784 }
@@ -1028,8 +1027,7 @@ private void BindLanguages()
10281027
10291028 private void OnCurrentDomainUnhandledException ( object sender , UnhandledExceptionEventArgs e )
10301029 {
1031- var ex = e . ExceptionObject as Exception ;
1032- ex = ex ?? new Exception ( "OnCurrentDomainUnhandledException" ) ;
1030+ var ex = e . ExceptionObject as Exception ?? new Exception ( "OnCurrentDomainUnhandledException" ) ;
10331031 OnThreadException ( sender , new ThreadExceptionEventArgs ( ex ) ) ;
10341032 }
10351033
0 commit comments