Ejemplo n.º 1
0
        private void ExpandWindowToHalfScreen(IntPtr hWnd, Screen screen, bool toLeft)
        {
            //Note: should use Aero Snap, but there is no API for it...
            Rectangle screenArea = screen.WorkingArea;

            WinAPI.RectInter newPos = new WinAPI.RectInter();
            if (toLeft)
            {
                newPos.left = screenArea.Left; newPos.right = screenArea.Right / 2;
            }
            else
            {
                newPos.left = screenArea.Left + screenArea.Right / 2; newPos.right = screenArea.Right;
            }
            newPos.top = screenArea.Top; newPos.bottom = screenArea.Bottom;
            WinAPI.AdjustWindowRectEx(ref newPos, WinAPI.GetWindowLong(hWnd, WinAPI.GWL_STYLE), false, WinAPI.GetWindowLong(hWnd, WinAPI.GWL_EXSTYLE));
            newPos.bottom--;
            WinAPI.SetWindowPos(hWnd, IntPtr.Zero, newPos.left, screenArea.Top, newPos.right - newPos.left, newPos.bottom - screenArea.Top, WinAPI.SWP_ASYNCWINDOWPOS | WinAPI.SWP_NOZORDER);
        }
Ejemplo n.º 2
0
        private void DropBar_Shown(object sender, EventArgs e)
        {
            SetMagnify(true);  //Reset magnification.
            //Set location near cursor position:
            WinAPI.GetCursorPos(out WinAPI.PointInter _pos);  Point pos = (Point)_pos;
            Screen    screen      = Screen.FromPoint(pos);
            Rectangle workingArea = screen.WorkingArea;
            Point     newLocation = new Point(pos.X - Width / 2, pos.Y + DisplayMargin);
            //Adjust location to stay into working area:
            Point delta = screen.Primary ? Point.Empty : GetBottomScreenDelta();

            if (pos.Y + DisplayMargin + Height > delta.Y + workingArea.Height)
            {
                newLocation.Y = pos.Y - Screen.PrimaryScreen.WorkingArea.Top - DisplayMargin - Height;
            }
            if (pos.X - Width / 2 < delta.X)
            {
                newLocation.X = delta.X;
            }
            else if (pos.X + Width / 2 > delta.X + workingArea.Width)
            {
                newLocation.X = delta.X + workingArea.Width - Width;
            }
            DesktopLocation = newLocation;
            //Set TopMost:
            WinAPI.SetWindowPos(Handle, (IntPtr)WinAPI.HWND_TOPMOST, 0, 0, 0, 0, WinAPI.SWP_NOMOVE | WinAPI.SWP_NOSIZE | WinAPI.SWP_NOACTIVATE);
            //Initialize button's bitmap:
            switch (windowPos)
            {
            case WindowPosType.OnBottom:
                toLocation.Image = Properties.Resources.ToTopNone;
                onLocation.Image = Properties.Resources.OnBottomNone;
                break;
            }
            //Shrink the bar:
            UpdateMagnify(PointToClient(pos));
        }