Beispiel #1
0
        private Rectangle GetWindowBounds()
        {
            if (this.hWnd == IntPtr.Zero)
            {
                throw new TrackingException("Window handle is not specified.");
            }
            WindowInterop.WINDOWINFO      wi   = new WindowInterop.WINDOWINFO(null);
            WindowInterop.WINDOWPLACEMENT wp   = WindowInterop.WINDOWPLACEMENT.Default;
            WindowInterop.RECT            rect = new WindowInterop.RECT();
            bool windowAccessible = false;
            bool isNotVisible     = false;

            if (WindowInterop.GetWindowInfo(this.hWnd, ref wi))
            {
                if (WindowInterop.GetWindowPlacement(hWnd, out wp))
                {
                    if (wp.ShowCmd == WindowInterop.ShowWindowCommands.Maximize ||
                        wp.ShowCmd == WindowInterop.ShowWindowCommands.Normal ||
                        wp.ShowCmd == WindowInterop.ShowWindowCommands.Show)
                    {
                        if (WindowInterop.GetWindowRect(hWnd, out rect))
                        {
                            windowAccessible = true;
                        }
                    }
                    else
                    {
                        isNotVisible = true;
                    }
                }
            }
            if (!windowAccessible)
            {
                string message = string.Format(
                    "Specified window (0x{0:X8}) is not accessible. It is either closed, minimized or hidden.",
                    hWnd.ToInt32());
                if (isNotVisible)
                {
                    throw new TrackingException(message);
                }
                else
                {
                    throw new TrackingException(message, new Win32Exception());
                }
            }
            Rectangle bounds;

            if (wp.ShowCmd == WindowInterop.ShowWindowCommands.Maximize)
            {
                rect.left   += (int)wi.cxWindowBorders;
                rect.top    += (int)wi.cyWindowBorders;
                rect.right  -= (int)wi.cxWindowBorders;
                rect.bottom -= (int)wi.cyWindowBorders;;
                bounds       = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
            }
            else
            {
                bounds = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
            }
            return(PreviewBounds(bounds));
        }
Beispiel #2
0
 private Rectangle GetWindowBounds()
 {
     if (this.hWnd == IntPtr.Zero) {
     throw new TrackingException("Window handle is not specified.");
      }
      WindowInterop.WINDOWINFO wi = new WindowInterop.WINDOWINFO(null);
      WindowInterop.WINDOWPLACEMENT wp = WindowInterop.WINDOWPLACEMENT.Default;
      WindowInterop.RECT rect = new WindowInterop.RECT();
      bool windowAccessible = false;
      bool isNotVisible = false;
      if (WindowInterop.GetWindowInfo(this.hWnd, ref wi)) {
     if (WindowInterop.GetWindowPlacement(hWnd, out wp)) {
        if (wp.ShowCmd == WindowInterop.ShowWindowCommands.Maximize ||
            wp.ShowCmd == WindowInterop.ShowWindowCommands.Normal ||
            wp.ShowCmd == WindowInterop.ShowWindowCommands.Show) {
           if (WindowInterop.GetWindowRect(hWnd, out rect)) {
              windowAccessible = true;
           }
        }
        else {
           isNotVisible = true;
        }
     }
      }
      if (!windowAccessible) {
     string message = string.Format(
        "Specified window (0x{0:X8}) is not accessible. It is either closed, minimized or hidden.",
        hWnd.ToInt32());
     if (isNotVisible) {
        throw new TrackingException(message);
     }
     else {
        throw new TrackingException(message, new Win32Exception());
     }
      }
      Rectangle bounds;
      if (wp.ShowCmd == WindowInterop.ShowWindowCommands.Maximize) {
     rect.left += (int)wi.cxWindowBorders;
     rect.top += (int)wi.cyWindowBorders;
     rect.right -= (int)wi.cxWindowBorders;
     rect.bottom -= (int)wi.cyWindowBorders; ;
     bounds = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
      }
      else {
     bounds = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
      }
      return PreviewBounds(bounds);
 }