1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Text ;
5+ using System . Threading . Tasks ;
6+ using System . Runtime . InteropServices ;
7+
8+ namespace AvatarLockpick . Revised . Utils
9+ {
10+ internal class WindowUtils
11+ {
12+ [ DllImport ( "kernel32.dll" , ExactSpelling = true ) ]
13+ private static extern IntPtr GetConsoleWindow ( ) ;
14+
15+ [ DllImport ( "user32.dll" ) ]
16+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
17+ private static extern bool IsWindowVisible ( IntPtr hWnd ) ;
18+
19+ [ DllImport ( "user32.dll" ) ]
20+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
21+ private static extern bool IsIconic ( IntPtr hWnd ) ;
22+
23+ [ DllImport ( "user32.dll" ) ]
24+ private static extern bool ShowWindow ( IntPtr hWnd , int nCmdShow ) ;
25+
26+ [ DllImport ( "user32.dll" ) ]
27+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
28+ private static extern bool SetForegroundWindow ( IntPtr hWnd ) ;
29+
30+ private const int SW_RESTORE = 9 ;
31+
32+ public static void BringConsoleToFrontIfVisible ( )
33+ {
34+ IntPtr consoleHandle = GetConsoleWindow ( ) ;
35+ if ( consoleHandle != IntPtr . Zero )
36+ {
37+ if ( IsWindowVisible ( consoleHandle ) )
38+ {
39+ if ( IsIconic ( consoleHandle ) )
40+ {
41+ ShowWindow ( consoleHandle , SW_RESTORE ) ;
42+ }
43+ SetForegroundWindow ( consoleHandle ) ;
44+ }
45+ }
46+ }
47+ }
48+ }
0 commit comments