public static void AdaptWindowToWorkingArea(this IntPtr windowHandle, int?taskbarHeight = null)
 {
     SEBWindowHandler.EditWindowByHandle(windowHandle, SEBWindowHandler.ShowWindowCommand.SW_SHOWNORMAL, false);
     if (taskbarHeight.HasValue)
     {
         IntPtr    hWnd   = windowHandle;
         int       X      = 0;
         int       Y      = 0;
         Rectangle bounds = Screen.PrimaryScreen.Bounds;
         int       width  = bounds.Width;
         bounds = Screen.PrimaryScreen.Bounds;
         int nHeight = bounds.Height - taskbarHeight.Value;
         int num     = 1;
         SEBWindowHandler.MoveWindow(hWnd, X, Y, width, nHeight, num != 0);
     }
     else
     {
         IntPtr    hWnd      = windowHandle;
         int       X         = 0;
         int       Y         = 0;
         Rectangle rectangle = Screen.PrimaryScreen.Bounds;
         int       width     = rectangle.Width;
         rectangle = Screen.PrimaryScreen.WorkingArea;
         int height = rectangle.Height;
         int num    = 1;
         SEBWindowHandler.MoveWindow(hWnd, X, Y, width, height, num != 0);
     }
     SEBWindowHandler.EditWindowByHandle(windowHandle, SEBWindowHandler.ShowWindowCommand.SW_SHOWMAXIMIZED, false);
 }
 private static SEBWindowHandler.WINDOWPLACEMENT GetPlacement(this IntPtr hwnd)
 {
     SEBWindowHandler.WINDOWPLACEMENT lpwndpl = new SEBWindowHandler.WINDOWPLACEMENT();
     lpwndpl.length = Marshal.SizeOf((object)lpwndpl);
     SEBWindowHandler.GetWindowPlacement(hwnd, ref lpwndpl);
     return(lpwndpl);
 }
 public static IDictionary <IntPtr, string> GetOpenWindows()
 {
     try
     {
         IntPtr lShellWindow = SEBWindowHandler.GetShellWindow();
         Dictionary <IntPtr, string> lWindows = new Dictionary <IntPtr, string>();
         SEBWindowHandler.EnumWindows((SEBWindowHandler.EnumWindowsProc)((hWnd, lParam) =>
         {
             if (hWnd == lShellWindow || !SEBWindowHandler.IsWindowVisible(hWnd))
             {
                 return(true);
             }
             int windowTextLength = SEBWindowHandler.GetWindowTextLength(hWnd);
             if (windowTextLength == 0)
             {
                 return(true);
             }
             StringBuilder text = new StringBuilder(windowTextLength);
             SEBWindowHandler.GetWindowText(hWnd, text, windowTextLength + 1);
             lWindows[hWnd] = text.ToString().ToLower();
             return(true);
         }), 0);
         return((IDictionary <IntPtr, string>)lWindows);
     }
     catch (Exception ex)
     {
         Logger.AddError("Unable to retrieve open windows", (object)null, ex, (string)null);
         return((IDictionary <IntPtr, string>) new Dictionary <IntPtr, string>());
     }
 }
 public static void RestoreHiddenWindows()
 {
     foreach (IntPtr hiddenWindowHandle in SEBWindowHandler._hiddenWindowHandles)
     {
         SEBWindowHandler.EditWindowByHandle(hiddenWindowHandle, SEBWindowHandler.ShowWindowCommand.SW_RESTORE, false);
     }
 }
 public static int GetWindowHeight(this IntPtr windowHandle)
 {
     SEBWindowHandler.RECT lpRect = new SEBWindowHandler.RECT();
     if (!SEBWindowHandler.GetWindowRect(new HandleRef((object)null, windowHandle), out lpRect))
     {
         return(0);
     }
     return(lpRect.Bottom - lpRect.Top);
 }
 private static void EditAllOpenWindows(SEBWindowHandler.ShowWindowCommand action)
 {
     foreach (KeyValuePair <IntPtr, string> openWindow in (IEnumerable <KeyValuePair <IntPtr, string> >)SEBWindowHandler.GetOpenWindows())
     {
         IntPtr key = openWindow.Key;
         if (!key.IsAllowed())
         {
             SEBWindowHandler.EditWindowByHandle(key, action, false);
         }
     }
 }
 public static void MinimizeAllOpenWindows(bool force = false)
 {
     if (force)
     {
         SEBWindowHandler.SendMessage(SEBWindowHandler.FindWindow("Shell_TrayWnd", (string)null), 273, (IntPtr)419, IntPtr.Zero);
     }
     else
     {
         SEBWindowHandler.EditAllOpenWindows(SEBWindowHandler.ShowWindowCommand.SW_SHOWMINIMIZED);
     }
 }
        public static void BringToTop(this IntPtr windowHandle, bool restoreIfMinimizedOrHidden = true)
        {
            SEBWindowHandler.SetForegroundWindow(windowHandle);
            SEBWindowHandler.BringWindowToTop(windowHandle);
            int showCmd = windowHandle.GetPlacement().showCmd;

            if (!restoreIfMinimizedOrHidden || showCmd != 2 && showCmd != 0)
            {
                return;
            }
            SEBWindowHandler.EditWindowByHandle(windowHandle, SEBWindowHandler.ShowWindowCommand.SW_RESTORE, false);
        }
 public static IntPtr GetWindowHandleByTitle(string title)
 {
     try
     {
         title = title.ToLower();
         return(SEBWindowHandler.GetOpenWindows().FirstOrDefault <KeyValuePair <IntPtr, string> >((Func <KeyValuePair <IntPtr, string>, bool>)(lWindow => lWindow.Value.Contains(title))).Key);
     }
     catch (Exception ex)
     {
         return(IntPtr.Zero);
     }
 }
 public static List <IntPtr> GetWindowHandlesByTitle(string title)
 {
     try
     {
         title = title.ToLower();
         return(SEBWindowHandler.GetOpenWindows().Where <KeyValuePair <IntPtr, string> >((Func <KeyValuePair <IntPtr, string>, bool>)(lWindow => lWindow.Value.Contains(title))).Select <KeyValuePair <IntPtr, string>, IntPtr>((Func <KeyValuePair <IntPtr, string>, IntPtr>)(lWindow => lWindow.Key)).ToList <IntPtr>());
     }
     catch (Exception ex)
     {
         Logger.AddError("Unable to GetWindowHandlesByTitle " + title, (object)null, ex, (string)null);
         return(new List <IntPtr>());
     }
 }
 public static Process GetProcess(this IntPtr windowHandle)
 {
     try
     {
         uint lpdwProcessId;
         int  windowThreadProcessId = (int)SEBWindowHandler.GetWindowThreadProcessId(windowHandle, out lpdwProcessId);
         return(Process.GetProcessById((int)lpdwProcessId));
     }
     catch (Exception ex)
     {
         Logger.AddError("Unable to get Process", (object)null, ex, (string)null);
         return((Process)null);
     }
 }
 public static string GetWindowTitle(this IntPtr windowHandle)
 {
     try
     {
         StringBuilder text = new StringBuilder(256);
         string        str  = "";
         if (SEBWindowHandler.GetWindowText(windowHandle, text, 256) > 0)
         {
             str = text.ToString();
         }
         return(str);
     }
     catch (Exception ex)
     {
         Logger.AddError("Unable to GetWindowTitle", (object)null, ex, (string)null);
         return("");
     }
 }
 public static void HideAllOpenWindows()
 {
     SEBWindowHandler.EditAllOpenWindows(SEBWindowHandler.ShowWindowCommand.SW_HIDE);
 }
 public static void HideWindow(this IntPtr handle)
 {
     SEBWindowHandler.EditWindowByHandle(handle, SEBWindowHandler.ShowWindowCommand.SW_HIDE, false);
 }
 private static void EditWindowByHandle(IntPtr windowHandle, SEBWindowHandler.ShowWindowCommand action, bool waitForShowingUp = false)
 {
     if (action == SEBWindowHandler.ShowWindowCommand.SW_HIDE)
     {
         SEBWindowHandler._hiddenWindowHandles.Add(windowHandle);
     }
     ThreadPool.QueueUserWorkItem((WaitCallback)(_param1 =>
     {
         try
         {
             if (action == SEBWindowHandler.ShowWindowCommand.SW_SHOWMINIMIZED & waitForShowingUp)
             {
                 Thread.Sleep(500);
             }
             if (!SEBWindowHandler.ShowWindowAsync(windowHandle, (int)action))
             {
                 if (action == SEBWindowHandler.ShowWindowCommand.SW_SHOWMINIMIZED)
                 {
                     SEBWindowHandler.SendMessage(windowHandle, 274, (IntPtr)61472, IntPtr.Zero);
                     Logger.AddInformation(string.Format("Window {0} minimized", (object)windowHandle.GetWindowTitle()), (object)null, (Exception)null, (string)null);
                 }
                 else if (action == SEBWindowHandler.ShowWindowCommand.SW_HIDE)
                 {
                     SEBWindowHandler.SendMessage(windowHandle, 274, (IntPtr)61536, IntPtr.Zero);
                     Logger.AddInformation(string.Format("Window {0} closed, because i was unable to hide it", (object)windowHandle.GetWindowTitle()), (object)null, (Exception)null, (string)null);
                 }
                 else
                 {
                     if (action != SEBWindowHandler.ShowWindowCommand.SW_SHOWMAXIMIZED)
                     {
                         return;
                     }
                     SEBWindowHandler.SendMessage(windowHandle, 274, (IntPtr)61488, IntPtr.Zero);
                     Logger.AddInformation(string.Format("Window {0} Maximized", (object)windowHandle.GetWindowTitle()), (object)null, (Exception)null, (string)null);
                 }
             }
             else
             {
                 Logger.AddInformation(string.Format("Window {0} {1}", (object)windowHandle.GetWindowTitle(), (object)action.ToString()), (object)null, (Exception)null, (string)null);
             }
         }
         catch
         {
             try
             {
                 if (action == SEBWindowHandler.ShowWindowCommand.SW_SHOWMINIMIZED)
                 {
                     SEBWindowHandler.SendMessage(windowHandle, 274, (IntPtr)61472, IntPtr.Zero);
                     Logger.AddInformation(string.Format("Window {0} minimized", (object)windowHandle.GetWindowTitle()), (object)null, (Exception)null, (string)null);
                 }
                 else if (action == SEBWindowHandler.ShowWindowCommand.SW_HIDE)
                 {
                     SEBWindowHandler.SendMessage(windowHandle, 274, (IntPtr)61536, IntPtr.Zero);
                     Logger.AddInformation(string.Format("Window {0} closed, because i was unable to hide it", (object)windowHandle.GetWindowTitle()), (object)null, (Exception)null, (string)null);
                 }
                 else
                 {
                     if (action != SEBWindowHandler.ShowWindowCommand.SW_SHOWMAXIMIZED)
                     {
                         return;
                     }
                     SEBWindowHandler.SendMessage(windowHandle, 274, (IntPtr)61488, IntPtr.Zero);
                     Logger.AddInformation(string.Format("Window {0} Maximized", (object)windowHandle.GetWindowTitle()), (object)null, (Exception)null, (string)null);
                 }
             }
             catch (Exception ex)
             {
             }
         }
     }));
 }
 public static void MinimizeWindow(this IntPtr windowHandle, bool waitForShowingUp = false)
 {
     SEBWindowHandler.EditWindowByHandle(windowHandle, SEBWindowHandler.ShowWindowCommand.SW_SHOWMINIMIZED, waitForShowingUp);
 }
 public static bool IsWindowAllowed(this Process process)
 {
     return(SEBWindowHandler.IsWindowAllowedByProcessName(process.GetExecutableName()));
 }
 public static void MaximizeWindow(this IntPtr windowHandle)
 {
     SEBWindowHandler.EditWindowByHandle(windowHandle, SEBWindowHandler.ShowWindowCommand.SW_SHOWMAXIMIZED, false);
 }
Esempio n. 19
0
 public static IEnumerable <KeyValuePair <IntPtr, string> > GetOpenWindows(this Process process)
 {
     return(SEBWindowHandler.GetOpenWindows()
            .Where(oW => oW.Key.GetProcess().GetExecutableName() == process.GetExecutableName()));
 }
 public static void CloseWindow(this IntPtr windowHandle)
 {
     SEBWindowHandler.SendMessage(windowHandle, 16, IntPtr.Zero, IntPtr.Zero);
 }