1
- using Microsoft . Win32 ;
1
+ using Microsoft . Win32 ;
2
2
using System ;
3
3
using System . Collections . Generic ;
4
4
using System . ComponentModel ;
7
7
using System . Drawing ;
8
8
using System . Linq ;
9
9
using System . Reflection ;
10
+ using System . Runtime . InteropServices ;
10
11
using System . Text ;
11
12
using System . Threading ;
12
13
using System . Windows . Forms ;
@@ -34,6 +35,11 @@ public MainClass(string[] args)
34
35
var optStartup = ( ToolStripMenuItem ) Menu1 . Items . Add ( "Startup" ) ;
35
36
var optExit = ( ToolStripMenuItem ) Menu1 . Items . Add ( "Exit" ) ;
36
37
optStartup . Checked = ToggleStartup ( true , true ) ;
38
+ optExit . Click += ( s , e ) => {
39
+ foreach ( var h in Handles . Keys )
40
+ Native32 . ShowActiveWindow ( h , true ) ;
41
+ Application . Exit ( ) ;
42
+ } ;
37
43
optStartup . Click += ( s , e ) => {
38
44
optStartup . Checked = ! optStartup . Checked ;
39
45
ToggleStartup ( optStartup . Checked ) ;
@@ -46,19 +52,22 @@ public MainClass(string[] args)
46
52
if ( wHandle == Handle ) return ;
47
53
var wInfo = Native32 . GetActiveWindowInfo ( wHandle , true ) ;
48
54
var wProc = wInfo [ 2 ] as Process ;
49
- if ( "explorer" == wProc . ProcessName && "Program Manager" == "" + wInfo [ 1 ] )
55
+ var wText = "" + wInfo [ 1 ] ;
56
+ var wIcon = wInfo [ 0 ] as Icon ;
57
+ if ( "explorer" == wProc . ProcessName && "Program Manager" == wText )
58
+ return ;
59
+ if ( "explorer" == wProc . ProcessName && "" == wText . Trim ( ) )
50
60
return ;
51
61
if ( Control . MouseButtons != MouseButtons . Middle )
52
62
return ;
53
63
if ( Handles . ContainsKey ( wHandle ) )
54
64
return ;
55
65
Handles . Add ( wHandle , wInfo ) ;
56
- var wText = "" + wInfo [ 1 ] ;
57
- var wIcon = wInfo [ 0 ] as Icon ;
58
66
string wTitle = wText ;
59
67
if ( wText . Length > 16 ) wTitle = wTitle . Substring ( 0 , 16 ) + "…" ;
60
68
var optSubWindow = ( ToolStripMenuItem ) optWindow . DropDownItems . Add ( wTitle ) ;
61
- try { optSubWindow . Image = wIcon . ToBitmap ( ) ; } catch { }
69
+ if ( null != wIcon )
70
+ try { optSubWindow . Image = wIcon . ToBitmap ( ) ; } catch { }
62
71
optSubWindow . Click += ( s2 , e2 ) => {
63
72
Handles . Remove ( wHandle ) ;
64
73
Native32 . ShowActiveWindow ( wHandle , true ) ;
0 commit comments