11using Microsoft . Toolkit . Uwp . Notifications ;
2+ using System . Diagnostics ;
23using System . Globalization ;
34using System . Runtime . InteropServices ;
45using 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