11using System ;
22using System . Collections . Generic ;
3+ using System . Diagnostics ;
34using System . Drawing ;
45using System . Runtime . InteropServices ;
56using System . Text ;
@@ -8,14 +9,16 @@ namespace WindowTool
89{
910 internal static class Window
1011 {
11- const short SWP_NOMOVE = 0X2 ;
12- const short SWP_NOSIZE = 1 ;
13- const short SWP_NOZORDER = 0X4 ;
12+ const int SWP_NOSIZE = 0x0001 ;
13+ const int SWP_NOMOVE = 0x0002 ;
14+ const int SWP_NOZORDER = 0x0004 ;
1415 const int SWP_SHOWWINDOW = 0x0040 ;
16+
17+ const int SW_RESTORE = 9 ;
1518
16- private const int GA_PARENT = 1 ; // Retrieves the parent window.This does not include the owner, as it does with the GetParent function.
17- private const int GA_ROOT = 2 ; // Retrieves the root window by walking the chain of parent windows.
18- private const int GA_ROOTOWNER = 3 ; // Retrieves the owned root window by walking the chain of parent and owner windows returned by GetParent.
19+ const int GA_PARENT = 1 ; // Retrieves the parent window.This does not include the owner, as it does with the GetParent function.
20+ const int GA_ROOT = 2 ; // Retrieves the root window by walking the chain of parent windows.
21+ const int GA_ROOTOWNER = 3 ; // Retrieves the owned root window by walking the chain of parent and owner windows returned by GetParent.
1922
2023 [ DllImport ( "user32.dll" ) ]
2124 private static extern IntPtr WindowFromPoint ( Point point ) ;
@@ -32,12 +35,27 @@ internal static class Window
3235 [ DllImport ( "user32.dll" ) ]
3336 private static extern bool SetForegroundWindow ( IntPtr hWnd ) ;
3437
38+ [ DllImport ( "user32.dll" ) ]
39+ static extern bool ShowWindow ( IntPtr hWnd , int wFlags ) ;
40+
41+ [ DllImport ( "user32.dll" ) ]
42+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
43+ static extern bool GetWindowPlacement ( IntPtr hWnd , ref WINDOWPLACEMENT lpwndpl ) ;
44+
45+ private struct WINDOWPLACEMENT
46+ {
47+ public int length ;
48+ public int flags ;
49+ public int showCmd ;
50+ public Point ptMinPosition ;
51+ public Point ptMaxPosition ;
52+ public Rectangle rcNormalPosition ;
53+ }
3554
3655 public static IntPtr GetWindow ( Point point )
3756 {
3857 IntPtr intPtr = WindowFromPoint ( point ) ;
3958 intPtr = GetAncestor ( intPtr , GA_ROOT ) ;
40-
4159 return intPtr ;
4260 }
4361
@@ -59,6 +77,17 @@ public static Rectangle GetWindowPosition(IntPtr hWnd)
5977 return rect ;
6078 }
6179
62-
80+ public static void HandleMaximizedWindow ( IntPtr hWnd )
81+ {
82+ WINDOWPLACEMENT windowPlacement = new ( ) ;
83+ GetWindowPlacement ( hWnd , ref windowPlacement ) ;
84+ if ( windowPlacement . showCmd == 3 )
85+ {
86+ Rectangle windowDimentions = GetWindowPosition ( hWnd ) ;
87+ ShowWindow ( hWnd , SW_RESTORE ) ;
88+ SetForegroundWindow ( hWnd ) ;
89+ SetWindowPos ( hWnd , 0 , windowDimentions . Top , windowDimentions . Right , windowDimentions . Width , windowDimentions . Height , SWP_SHOWWINDOW ) ;
90+ }
91+ }
6392 }
6493}
0 commit comments