Skip to content

Commit c4a9fdf

Browse files
authored
Update MainClass.cs
1 parent 62672e2 commit c4a9fdf

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

MainClass.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.Win32;
1+
using Microsoft.Win32;
22
using System;
33
using System.Collections.Generic;
44
using System.ComponentModel;
@@ -7,6 +7,7 @@
77
using System.Drawing;
88
using System.Linq;
99
using System.Reflection;
10+
using System.Runtime.InteropServices;
1011
using System.Text;
1112
using System.Threading;
1213
using System.Windows.Forms;
@@ -34,6 +35,11 @@ public MainClass(string[] args)
3435
var optStartup = (ToolStripMenuItem)Menu1.Items.Add("Startup");
3536
var optExit = (ToolStripMenuItem)Menu1.Items.Add("Exit");
3637
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+
};
3743
optStartup.Click += (s, e) => {
3844
optStartup.Checked = !optStartup.Checked;
3945
ToggleStartup(optStartup.Checked);
@@ -46,19 +52,22 @@ public MainClass(string[] args)
4652
if (wHandle == Handle) return;
4753
var wInfo = Native32.GetActiveWindowInfo(wHandle, true);
4854
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())
5060
return;
5161
if (Control.MouseButtons != MouseButtons.Middle)
5262
return;
5363
if (Handles.ContainsKey(wHandle))
5464
return;
5565
Handles.Add(wHandle, wInfo);
56-
var wText = "" + wInfo[1];
57-
var wIcon = wInfo[0] as Icon;
5866
string wTitle = wText;
5967
if (wText.Length > 16) wTitle = wTitle.Substring(0, 16) + "…";
6068
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 { }
6271
optSubWindow.Click += (s2, e2) => {
6372
Handles.Remove(wHandle);
6473
Native32.ShowActiveWindow(wHandle, true);

0 commit comments

Comments
 (0)