コード例 #1
0
        public Rectangle GetWindowRect()
        {
            Rectangle rectangle;

            User32Methods.GetWindowRect(this.Handle, out rectangle);
            return(rectangle);
        }
コード例 #2
0
        private bool IsCursorInDraggableRegion(IntPtr hWnd, IntPtr lParam)
        {
            Point pt;

            pt.X = NativeMethods.LOWORD(lParam);
            pt.Y = NativeMethods.HIWORD(lParam);

            User32Methods.ClientToScreen(hWnd, ref pt);

            Rectangle rect;

            User32Methods.GetWindowRect(_parentHandle, out rect);

            // Mouse must be within Window
            if (!User32Methods.PtInRect(ref rect, pt))
            {
                return(false);
            }

            Rectangle draggableRegion = new Rectangle
            {
                Left   = rect.Left,
                Top    = rect.Top,
                Right  = rect.Right - _framelessOptions.NoDragWidth,
                Bottom = rect.Top + _framelessOptions.Height
            };

            // Mouse must be within draggable Region
            if (User32Methods.PtInRect(ref draggableRegion, pt))
            {
                return(true);
            }

            return(false);
        }
コード例 #3
0
ファイル: NativeWindow.cs プロジェクト: DaveCS1/Chromely
        /// <summary>
        /// The get window size.
        /// </summary>
        /// <returns>
        /// The <see cref="Size"/>.
        /// </returns>
        public Size GetWindowSize()
        {
            var size = new Size();

            if (Handle != IntPtr.Zero)
            {
                User32Methods.GetWindowRect(Handle, out var rectangle);
                size.Width  = rectangle.Width;
                size.Height = rectangle.Height;
            }

            return(size);
        }
コード例 #4
0
ファイル: NativeWindow.cs プロジェクト: DaveCS1/Chromely
        internal static IntPtr HitTestNCA(IntPtr hWnd, IntPtr wParam, IntPtr lParam)
        {
            // Get the point coordinates for the hit test.
            Point mousePoint = new Point(lParam.ToInt32() & 0xFFFF, lParam.ToInt32() >> 16);

            // Get the window rectangle.
            Rectangle rectWindow;

            User32Methods.GetWindowRect(hWnd, out rectWindow);

            // Get the frame rectangle, adjusted for the style without a caption.
            Rectangle rectFrame = new Rectangle(4, 4, 27, 4);

            User32Methods.AdjustWindowRectEx(ref rectFrame, WindowStyles.WS_OVERLAPPEDWINDOW & ~WindowStyles.WS_CAPTION, false, 0);
            ushort row = 1;
            ushort col = 1;
            bool   onTopResizeBorder = false;

            // Determine if the point is at the top or bottom of the window.
            if (mousePoint.Y >= rectWindow.Top && mousePoint.Y < rectWindow.Top + 27)
            {
                onTopResizeBorder = (mousePoint.Y < (rectWindow.Top - rectFrame.Top));
                row = 0;
            }
            else if (mousePoint.Y < rectWindow.Bottom && mousePoint.Y >= rectWindow.Bottom - 7)
            {
                row = 2;
            }

            // Determine if the point is at the left or right of the window.
            if (mousePoint.X >= rectWindow.Left && mousePoint.X < rectWindow.Left + 7)
            {
                col = 0;
            }
            else if (mousePoint.X < rectWindow.Right && mousePoint.X >= rectWindow.Right - 7)
            {
                col = 2;
            }

            // Defines the tests to determine what value to return for NCHITTEST
            int[,] hitTests =
            {
                { 13, onTopResizeBorder ? 12 : 2, 11 },
                { 10,                          0, 11 },
                { 16,                         15, 17 }
            };

            return((IntPtr)hitTests[row, col]);
        }
コード例 #5
0
        public void Tile(string selectedTag, int UIHeight)
        {
            List <Client> tiledClient = ClientList(selectedTag).Where(c => c.TileMode == TileMode.Tile).ToList( );

            if (tiledClient.Count == 0)
            {
                return;
            }
            var  master      = tiledClient.First( );
            var  masterWidth = Tag(selectedTag).MasterWidth;
            bool onlyOne     = tiledClient.Count == 1;

            masterWidth = onlyOne ? ScreenGeom.Width : masterWidth;
            ResizeClient(master, ScreenGeom.Left, ScreenGeom.Top + UIHeight,
                         masterWidth, ScreenGeom.Height - UIHeight);
            Logger.Info($"master {master.Title} : {master.Rect}");
            if (onlyOne)
            {
                return;
            }
            var winGeom    = ScreenGeom;
            var slaveList  = tiledClient.Skip(1).ToList( );
            int slaveCount = slaveList.Count;

            var x = master.Rect.X + master.Rect.Width;
            int y = winGeom.Top + UIHeight;
            var w = winGeom.Width - masterWidth;
            var h = (ScreenGeom.Height - UIHeight) / slaveCount;

            for (int i = 0; i < slaveCount; i++)
            {
                var  item      = slaveList[i];
                bool isLastOne = (i + 1 == slaveCount);
                var  height    = isLastOne ? winGeom.Top + winGeom.Height - y - 2 * item.Bw : h - 2 * item.Bw;
                ResizeClient(item, x, y, w - 2 * item.Bw, height);
                Logger.Info($"slave {item.Title} : {item.Rect}");
                User32Methods.GetWindowRect(item.Hwnd, out var rect);
                if (!isLastOne)
                {
                    y = item.Rect.Top + rect.Height;
                }
            }
        }
コード例 #6
0
 private void Resize(IntPtr parentHandle, int width, int height)
 {
     try
     {
         if (Panel.IsVisible && parentHandle != IntPtr.Zero && mProcess != null && mProcess.MainWindowHandle != IntPtr.Zero)
         {
             var curPoint   = PointToScreen(new System.Windows.Point(0, 0));
             int offsetLeft = 0;
             int offsetTop  = 0;
             if (User32Methods.GetWindowRect(parentHandle, out Rectangle rect))
             {
                 offsetLeft = (int)Math.Round(curPoint.X, 0) - rect.Left - 9;
                 offsetTop  = (int)Math.Round(curPoint.Y, 0) - rect.Top - 30;
                 User32Methods.MoveWindow(mProcess.MainWindowHandle, offsetLeft, offsetTop, width + 28, height + 28, true);
             }
         }
     }
     catch (Exception ex)
     {
         mLogger.Error($"{ID} -- Error while resizing window, due to:{ex}");
         this.Dispose();
     }
 }
コード例 #7
0
 public bool GetWindowRect(out Rectangle rectangle)
 {
     return(User32Methods.GetWindowRect(this.Handle, out rectangle));
 }
コード例 #8
0
        public static Rectangle GetWindowRect(IntPtr Hwnd)
        {
            var result = User32Methods.GetWindowRect(Hwnd, out Rectangle win_rectangle);

            return(win_rectangle);
        }