Skip to content

Commit 385deb0

Browse files
author
neursh
committed
Add an option to destroy all yeeted processes
1 parent fe870ea commit 385deb0

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

HotkeysLoad.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ namespace tray_yeeter_sharp
88
{
99
internal partial class HotkeysLoad
1010
{
11-
private static readonly List<IntPtr> yeetedWindows = [];
12-
private static readonly List<IntPtr> enumWindowsResult = [];
13-
1411
private static readonly List<VirtualKey> modifierKeys = [
1512
VirtualKey.LeftControl,
1613
VirtualKey.RightControl,

Yeeter.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.Toolkit.Uwp.Notifications;
2+
using System.Diagnostics;
23
using System.Globalization;
34
using System.Runtime.InteropServices;
45
using static tray_yeeter_sharp.HotkeysLoad;
@@ -18,6 +19,7 @@ private void Yeeter_Load(object? sender, EventArgs e)
1819
notifyIcon1.ContextMenuStrip = new ContextMenuStrip();
1920
notifyIcon1.ContextMenuStrip.Items.Add("Reload", null, ReloadEvent);
2021
notifyIcon1.ContextMenuStrip.Items.Add("Quit", null, QuitEvent);
22+
notifyIcon1.ContextMenuStrip.Items.Add("Quit all", null, QuitAll);
2123
RegisterHotkeys(HotkeyEvent);
2224
}
2325

@@ -50,6 +52,23 @@ private static void QuitEvent(object? sender, EventArgs e)
5052
Application.Exit();
5153
}
5254

55+
private static void QuitAll(object? sender, EventArgs e)
56+
{
57+
if (yeetedWindows.Count > 0) {
58+
foreach (IntPtr hWnd in yeetedWindows)
59+
{
60+
try {
61+
GetWindowThreadProcessId(hWnd, out uint processId);
62+
if (processId == 0) continue;
63+
64+
Process process = Process.GetProcessById((int)processId);
65+
process.Kill();
66+
} catch { }
67+
}
68+
}
69+
Application.Exit();
70+
}
71+
5372
private static void HotkeyEvent(int Id)
5473
{
5574
if (Id == 0)
@@ -98,15 +117,18 @@ private static bool EnumWindowCallback(IntPtr hWnd, IntPtr lParam)
98117
return true;
99118
}
100119

101-
private static List<IntPtr> yeetedWindows = [];
102-
private static List<IntPtr> enumWindowsResult = [];
120+
private static readonly List<IntPtr> yeetedWindows = [];
121+
private static readonly List<IntPtr> enumWindowsResult = [];
103122

104123
const int SW_HIDE = 0;
105124
const int SW_SHOW = 5;
106125

107126
[LibraryImport("user32.dll")]
108127
private static partial IntPtr GetForegroundWindow();
109128

129+
[LibraryImport("user32.dll")]
130+
private static partial uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
131+
110132
[LibraryImport("user32.dll")]
111133
[return: MarshalAs(UnmanagedType.Bool)]
112134
private static partial bool ShowWindow(IntPtr hWnd, int nCmdShow);

0 commit comments

Comments
 (0)