@@ -26,6 +26,7 @@ public partial class MainForm : Form, IMessageFilter
2626 private string _informationFileName ;
2727 private string _textFileName ;
2828 private string _imageFileName ;
29+ private IntPtr _windowHandle ;
2930
3031 public MainForm ( )
3132 {
@@ -37,6 +38,7 @@ public MainForm()
3738 _informationFileName = string . Empty ;
3839 _textFileName = string . Empty ;
3940 _imageFileName = string . Empty ;
41+ _windowHandle = IntPtr . Zero ;
4042 }
4143
4244 protected override void OnLoad ( EventArgs e )
@@ -206,6 +208,17 @@ private void menuItemAbout_Click(object sender, EventArgs e)
206208 dialog . ShowDialog ( this ) ;
207209 }
208210
211+ private void btnShowHide_Click ( object sender , EventArgs e )
212+ {
213+ var button = ( Button ) sender ;
214+ var cmdShow = button . Text == "Show" ? ShowWindowCommands . SW_SHOW : ShowWindowCommands . SW_HIDE ;
215+ NativeMethods . ShowWindow ( _windowHandle , cmdShow ) ;
216+ button . Text = NativeMethods . IsWindowVisible ( _windowHandle ) ? "Hide" : "Show" ;
217+ var windowInformation = WindowUtils . GetWindowInformation ( _windowHandle ) ;
218+ FillInformation ( windowInformation ) ;
219+ }
220+
221+
209222 protected override void WndProc ( ref Message m )
210223 {
211224 switch ( m . Msg )
@@ -253,16 +266,16 @@ public bool PreFilterMessage(ref Message m)
253266 var element = AutomationElement . FromPoint ( new System . Windows . Point ( cursorPosition . X , cursorPosition . Y ) ) ;
254267 if ( element != null && element . Current . ProcessId != _processId )
255268 {
256- var windowHandle = new IntPtr ( element . Current . NativeWindowHandle ) ;
257- windowHandle = windowHandle == IntPtr . Zero ? NativeMethods . WindowFromPoint ( new Point ( cursorPosition . X , cursorPosition . Y ) ) : windowHandle ;
269+ _windowHandle = new IntPtr ( element . Current . NativeWindowHandle ) ;
270+ _windowHandle = _windowHandle == IntPtr . Zero ? NativeMethods . WindowFromPoint ( new Point ( cursorPosition . X , cursorPosition . Y ) ) : _windowHandle ;
258271 if ( element . Current . IsPassword )
259272 {
260273 var process = Process . GetProcessById ( element . Current . ProcessId ) ;
261274 if ( process . ProcessName . ToLower ( ) == "iexplore" )
262275 {
263- if ( windowHandle != IntPtr . Zero )
276+ if ( _windowHandle != IntPtr . Zero )
264277 {
265- var passwords = WindowUtils . GetPasswordsFromHtmlPage ( windowHandle ) ;
278+ var passwords = WindowUtils . GetPasswordsFromHtmlPage ( _windowHandle ) ;
266279 if ( passwords . Any ( ) )
267280 {
268281 txtContent . Text = passwords . Count > 1 ? string . Join ( Environment . NewLine , passwords . Select ( ( x , i ) => "Password " + ( i + 1 ) + ": " + x ) ) : passwords [ 0 ] ;
@@ -280,9 +293,9 @@ public bool PreFilterMessage(ref Message m)
280293 }
281294 else
282295 {
283- NativeMethods . SetHook ( Handle , windowHandle , _messageId ) ;
296+ NativeMethods . SetHook ( Handle , _windowHandle , _messageId ) ;
284297 NativeMethods . QueryPasswordEdit ( ) ;
285- NativeMethods . UnsetHook ( Handle , windowHandle ) ;
298+ NativeMethods . UnsetHook ( Handle , _windowHandle ) ;
286299 }
287300 }
288301 else
@@ -295,11 +308,18 @@ public bool PreFilterMessage(ref Message m)
295308 pbContent . Image . Dispose ( ) ;
296309 pbContent . Image = null ;
297310 }
298- pbContent . Image = WindowUtils . PrintWindow ( windowHandle ) ;
299- var windowInformation = WindowUtils . GetWindowInformation ( windowHandle ) ;
311+ pbContent . Image = WindowUtils . PrintWindow ( _windowHandle ) ;
312+ var windowInformation = WindowUtils . GetWindowInformation ( _windowHandle ) ;
300313 FillInformation ( windowInformation ) ;
301314 OnContentChanged ( ) ;
302315 }
316+
317+ btnShowHide . Text = NativeMethods . IsWindowVisible ( _windowHandle ) ? "Hide" : "Show" ;
318+ btnShowHide . Visible = true ;
319+ }
320+ else
321+ {
322+ btnShowHide . Visible = false ;
303323 }
304324 }
305325 }
0 commit comments