Exemple #1
0
        public static void ActivateAppBar(IntPtr hWnd)
        {
            APP_BAR_DATA abd = new APP_BAR_DATA();

            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd   = hWnd;
            SHAppBarMessage(ABM_ACTIVATE, ref abd);
        }
Exemple #2
0
        public static void WindowPosChanged(IntPtr hWnd)
        {
            APP_BAR_DATA abd = new APP_BAR_DATA();

            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd   = hWnd;
            SHAppBarMessage(ABM_WINDOWPOSCHANGED, ref abd);
        }
Exemple #3
0
        public static void UnregisterAppBar(IntPtr hWnd)
        {
            APP_BAR_DATA abd = new APP_BAR_DATA();

            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd   = hWnd;
            SHAppBarMessage(ABM_REMOVE, ref abd);
        }
Exemple #4
0
        public static Rectangle SetPos(IntPtr hWnd, QueryPosResult pos)
        {
            APP_BAR_DATA abd = new APP_BAR_DATA();

            abd.cbSize    = Marshal.SizeOf(abd);
            abd.hWnd      = hWnd;
            abd.uEdge     = pos.edge;
            abd.rc.top    = pos.rc.Top;
            abd.rc.bottom = pos.rc.Bottom;
            abd.rc.left   = pos.rc.Left;
            abd.rc.right  = pos.rc.Right;
            // Pass the final bounding rectangle to the system.
            SHAppBarMessage(ABM_SETPOS, ref abd);
            MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, true);
            return(new Rectangle(abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top));
        }
Exemple #5
0
        public static bool RegisterAppBar(IntPtr hWnd, int callback)
        {
            APP_BAR_DATA abd = new APP_BAR_DATA();

            abd.cbSize           = Marshal.SizeOf(abd);
            abd.hWnd             = hWnd;
            abd.uCallbackMessage = callback;

            int retVal = SHAppBarMessage(ABM_NEW, ref abd);

            if (retVal == 0)
            {
                //registration failed
                return(false);
            }
            return(true);
        }
Exemple #6
0
 public static extern UIntPtr SHAppBarMessage(int dwMessage, ref APP_BAR_DATA abd);
Exemple #7
0
        /// <summary>
        /// Sizes and Moves the AppBar to a screen edge.
        /// </summary>
        internal static void DockAppBar(IntPtr hWnd, int edge, Size idealSize)
        {
            APP_BAR_DATA abd = new APP_BAR_DATA();
            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd = hWnd;
            abd.uEdge = edge;

            Size monitorSize = Screen.FromHandle(hWnd).Bounds.Size;

            if (edge == ABE_LEFT || edge == ABE_RIGHT)
            {
                abd.rc.top = 0;
                abd.rc.bottom = monitorSize.Height;
                if (edge == ABE_LEFT)
                {
                    abd.rc.right = idealSize.Width;
                }
                else
                {
                    abd.rc.right = monitorSize.Width;
                    abd.rc.left = abd.rc.right - idealSize.Width;
                }

            }
            else
            {
                abd.rc.left = 0;
                abd.rc.right = monitorSize.Width;
                if (edge == ABE_TOP)
                {
                    abd.rc.bottom = idealSize.Height;
                }
                else
                {
                    abd.rc.bottom = monitorSize.Height;
                    abd.rc.top = abd.rc.bottom - idealSize.Height;
                }
            }

            // Query the system for an approved size and position.
            SHAppBarMessage(ABM_QUERYPOS, ref abd);

            // Adjust the rectangle, depending on the edge to which the
            // appbar is anchored.
            switch (edge)
            {
                case ABE_LEFT:
                    abd.rc.right = abd.rc.left + idealSize.Width;
                    break;
                case ABE_RIGHT:
                    abd.rc.left = abd.rc.right - idealSize.Width;
                    break;
                case ABE_TOP:
                    abd.rc.bottom = abd.rc.top + idealSize.Height;
                    break;
                case ABE_BOTTOM:
                    abd.rc.top = abd.rc.bottom - idealSize.Height;
                    break;
            }

            // Pass the final bounding rectangle to the system.
            SHAppBarMessage(ABM_SETPOS, ref abd);

            // Move and size the appbar so that it conforms to the
            // bounding rectangle passed to the system.
            MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, true);
        }
Exemple #8
0
 private static extern int SHAppBarMessage(int dwMessage, ref APP_BAR_DATA abd);
Exemple #9
0
 /// <summary>
 /// Unregisters the AppBar.
 /// </summary>
 internal static void UnregisterAppBar(IntPtr hWnd)
 {
     APP_BAR_DATA abd = new APP_BAR_DATA();
     abd.cbSize = Marshal.SizeOf(abd);
     abd.hWnd = hWnd;
     SHAppBarMessage(ABM_REMOVE, ref abd);
 }
Exemple #10
0
        /// <summary>
        /// Registers the AppBar and assigns the appropriate callback message value.
        /// </summary>
        internal static bool RegisterAppBar(IntPtr hWnd, int uCallbackMessage)
        {
            APP_BAR_DATA abd = new APP_BAR_DATA();
            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd = hWnd;
            abd.uCallbackMessage = uCallbackMessage;

            int retVal = SHAppBarMessage(ABM_NEW, ref abd);
            if (retVal == 0)
            {
                //registration failed
                return false;
            }
            return true;
        }
Exemple #11
0
        public static QueryPosResult QueryPos(IntPtr hWnd, Point idealLocation, Size idealSize)
        {
            APP_BAR_DATA abd = new APP_BAR_DATA();

            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd   = hWnd;
            // saved the proposed rectangle
            Rectangle R = new Rectangle(idealLocation, idealSize);

            abd.rc.left  = R.Left;
            abd.rc.right = R.Right;
            // then figure out which screen that rectangle would be on
            Screen S = Screen.FromRectangle(R);

            // make it full height
            abd.rc.top    = S.WorkingArea.Top;
            abd.rc.bottom = S.WorkingArea.Bottom;
            if (S.Bounds.Left != 0)                 // multiple monitors
            {
                R.Offset(-S.Bounds.Left, 0);
            }
            // see whether we are on the left or right side of the screen
            int centerX      = (R.Left + R.Right) >> 1;
            int centerScreen = S.Bounds.Width >> 1;

            if (centerX < 0)                 // multiple monitors
            {
                if (Math.Abs(centerX) < centerScreen)
                {
                    abd.uEdge = ABE_RIGHT;
                }
                else
                {
                    abd.uEdge = ABE_LEFT;
                }
            }
            else if (centerX > centerScreen)
            {
                abd.uEdge = ABE_RIGHT;
            }
            else
            {
                abd.uEdge = ABE_LEFT;
            }
            // once we've decided on an edge, align the rect cleanly to that edge
            switch (abd.uEdge)
            {
            case ABE_LEFT:
                abd.rc.left  = S.WorkingArea.Left;
                abd.rc.right = abd.rc.left + idealSize.Width;
                break;

            case ABE_RIGHT:
                abd.rc.right = S.WorkingArea.Right;
                abd.rc.left  = abd.rc.right - idealSize.Width;
                break;
            }

            // Query the system for an approved size and position.
            SHAppBarMessage(ABM_QUERYPOS, ref abd);
            QueryPosResult ret = new QueryPosResult();

            ret.edge = abd.uEdge;
            ret.rc   = new Rectangle(abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top);
            // return the approved position
            return(ret);
        }
Exemple #12
0
        /// <summary>
        /// Sizes and Moves the AppBar to a screen edge.
        /// </summary>
        internal static void DockAppBar(IntPtr hWnd, int edge, Size idealSize)
        {
            APP_BAR_DATA abd = new APP_BAR_DATA();

            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd   = hWnd;
            abd.uEdge  = edge;

            Size monitorSize = Screen.FromHandle(hWnd).Bounds.Size;

            if (edge == ABE_LEFT || edge == ABE_RIGHT)
            {
                abd.rc.top    = 0;
                abd.rc.bottom = monitorSize.Height;
                if (edge == ABE_LEFT)
                {
                    abd.rc.right = idealSize.Width;
                }
                else
                {
                    abd.rc.right = monitorSize.Width;
                    abd.rc.left  = abd.rc.right - idealSize.Width;
                }
            }
            else
            {
                abd.rc.left  = 0;
                abd.rc.right = monitorSize.Width;
                if (edge == ABE_TOP)
                {
                    abd.rc.bottom = idealSize.Height;
                }
                else
                {
                    abd.rc.bottom = monitorSize.Height;
                    abd.rc.top    = abd.rc.bottom - idealSize.Height;
                }
            }

            // Query the system for an approved size and position.
            SHAppBarMessage(ABM_QUERYPOS, ref abd);

            // Adjust the rectangle, depending on the edge to which the
            // appbar is anchored.
            switch (edge)
            {
            case ABE_LEFT:
                abd.rc.right = abd.rc.left + idealSize.Width;
                break;

            case ABE_RIGHT:
                abd.rc.left = abd.rc.right - idealSize.Width;
                break;

            case ABE_TOP:
                abd.rc.bottom = abd.rc.top + idealSize.Height;
                break;

            case ABE_BOTTOM:
                abd.rc.top = abd.rc.bottom - idealSize.Height;
                break;
            }

            // Pass the final bounding rectangle to the system.
            SHAppBarMessage(ABM_SETPOS, ref abd);

            // Move and size the appbar so that it conforms to the
            // bounding rectangle passed to the system.
            MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, true);
        }
Exemple #13
0
 private static extern int SHAppBarMessage(int dwMessage, ref APP_BAR_DATA abd);