Ejemplo n.º 1
0
        public static void SetAppBar(Window appbarWindow, ABEdge edge)
        {
            RegisterInfo info = GetRegisterInfo(appbarWindow);
            info.Edge = edge;

            APPBARDATA abd = new APPBARDATA();
            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd = new WindowInteropHelper(appbarWindow).Handle;

            if (edge == ABEdge.None) {
                if (info.IsRegistered) {
                    SHAppBarMessage((int)ABMsg.ABM_REMOVE, ref abd);
                    info.IsRegistered = false;
                }
                RestoreWindow(appbarWindow);
                return;
            }

            if (!info.IsRegistered) {
                info.IsRegistered = true;
                info.CallbackId = RegisterWindowMessage("AppBarMessage");
                abd.uCallbackMessage = info.CallbackId;

                uint ret = SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd);

                HwndSource source = HwndSource.FromHwnd(abd.hWnd);
                source.AddHook(new HwndSourceHook(info.WndProc));
            }

            appbarWindow.WindowStyle = WindowStyle.None;
            appbarWindow.ResizeMode = ResizeMode.NoResize;
            appbarWindow.Topmost = true;

            ABSetPos(info.Edge, appbarWindow);
        }
Ejemplo n.º 2
0
        public static int RegisterBar(Window abWindow, double width, double height, ABEdge edge = ABEdge.ABE_TOP)
        {
            NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA();
            abd.cbSize = Marshal.SizeOf(typeof(NativeMethods.APPBARDATA));
            IntPtr handle = new WindowInteropHelper(abWindow).Handle;

            abd.hWnd = handle;

            if (!appBars.Contains(handle))
            {
                uCallBack            = NativeMethods.RegisterWindowMessage("AppBarMessage");
                abd.uCallbackMessage = uCallBack;

                uint ret = NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_NEW, ref abd);
                appBars.Add(handle);
                Trace.WriteLine("Created AppBar for handle " + handle.ToString());

                ABSetPos(abWindow, width, height, edge);
            }
            else
            {
                NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_REMOVE, ref abd);
                appBars.Remove(handle);
                Trace.WriteLine("Removed AppBar for handle " + handle.ToString());

                return(0);
            }

            return(uCallBack);
        }
Ejemplo n.º 3
0
        public static double GetAppBarEdgeWindowsHeight(ABEdge edge, Screen screen)
        {
            double edgeHeight = 0;

            foreach (MenuBar menuBar in WindowManager.Instance.MenuBarWindows)
            {
                if (menuBar.requiresScreenEdge &&
                    menuBar.appBarEdge == edge &&
                    menuBar.Screen.DeviceName == screen.DeviceName)
                {
                    edgeHeight += menuBar.Height;
                }
            }

            foreach (Taskbar taskbar in WindowManager.Instance.TaskbarWindows)
            {
                if (taskbar.requiresScreenEdge &&
                    taskbar.appBarEdge == edge &&
                    taskbar.Screen.DeviceName == screen.DeviceName)
                {
                    edgeHeight += taskbar.Height;
                }
            }

            return(edgeHeight);
        }
Ejemplo n.º 4
0
        public static void SetAppBar(Window appbarWindow, ABEdge edge, FrameworkElement childElement = null, bool topMost = true)
        {
            var info = GetRegisterInfo(appbarWindow);

            info.Edge         = edge;
            info.ChildElement = childElement;

            var abd = new Interop.APPBARDATA();

            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd   = new WindowInteropHelper(appbarWindow).Handle;

            int renderPolicy;

            if (edge == ABEdge.None)
            {
                if (info.IsRegistered)
                {
                    Interop.SHAppBarMessage((int)Interop.ABMsg.ABM_REMOVE, ref abd);
                    info.IsRegistered = false;
                }
                RestoreWindow(appbarWindow);

                // Restore normal desktop window manager attributes
                renderPolicy = (int)Interop.DWMNCRenderingPolicy.UseWindowStyle;

                Interop.DwmSetWindowAttribute(abd.hWnd, (int)Interop.DWMWINDOWATTRIBUTE.DWMA_EXCLUDED_FROM_PEEK, ref renderPolicy, sizeof(int));
                Interop.DwmSetWindowAttribute(abd.hWnd, (int)Interop.DWMWINDOWATTRIBUTE.DWMA_DISALLOW_PEEK, ref renderPolicy, sizeof(int));

                return;
            }

            if (!info.IsRegistered)
            {
                info.IsRegistered    = true;
                info.CallbackId      = Interop.RegisterWindowMessage("AppBarMessage");
                abd.uCallbackMessage = info.CallbackId;

                var ret = Interop.SHAppBarMessage((int)Interop.ABMsg.ABM_NEW, ref abd);

                var source = HwndSource.FromHwnd(abd.hWnd);
                source.AddHook(info.WndProc);
            }

            appbarWindow.WindowStyle = WindowStyle.None;
            appbarWindow.ResizeMode  = ResizeMode.NoResize;
            appbarWindow.Topmost     = topMost;

            // Set desktop window manager attributes to prevent window
            // from being hidden when peeking at the desktop or when
            // the 'show desktop' button is pressed
            renderPolicy = (int)Interop.DWMNCRenderingPolicy.Enabled;

            Interop.DwmSetWindowAttribute(abd.hWnd, (int)Interop.DWMWINDOWATTRIBUTE.DWMA_EXCLUDED_FROM_PEEK, ref renderPolicy, sizeof(int));
            Interop.DwmSetWindowAttribute(abd.hWnd, (int)Interop.DWMWINDOWATTRIBUTE.DWMA_DISALLOW_PEEK, ref renderPolicy, sizeof(int));

            ABSetPos(info, appbarWindow, childElement);
        }
Ejemplo n.º 5
0
        private static void ABSetPos(ABEdge edge, Window appbarWindow)
        {
            APPBARDATA barData = new APPBARDATA();

            barData.cbSize = Marshal.SizeOf(barData);
            barData.hWnd   = new WindowInteropHelper(appbarWindow).Handle;
            barData.uEdge  = (int)edge;

            int leftOffset         = 0;
            int topOffset          = 0;
            int actualScreenWidth  = (int)SystemParameters.PrimaryScreenWidth;
            int actualScreenHeight = (int)SystemParameters.PrimaryScreenHeight;

            GetActualScreenData(edge, appbarWindow, ref leftOffset, ref topOffset, ref actualScreenWidth, ref actualScreenHeight);

            if (barData.uEdge == (int)ABEdge.Left || barData.uEdge == (int)ABEdge.Right)
            {
                barData.rc.top    = topOffset;
                barData.rc.bottom = actualScreenHeight;
                if (barData.uEdge == (int)ABEdge.Left)
                {
                    barData.rc.left  = leftOffset;
                    barData.rc.right = (int)Math.Round(appbarWindow.ActualWidth) + leftOffset;
                }
                else
                {
                    barData.rc.right = actualScreenWidth + leftOffset;
                    barData.rc.left  = barData.rc.right - (int)Math.Round(appbarWindow.ActualWidth);
                }
            }
            else
            {
                barData.rc.left  = leftOffset;
                barData.rc.right = actualScreenWidth + leftOffset;
                if (barData.uEdge == (int)ABEdge.Top)
                {
                    barData.rc.top    = topOffset;
                    barData.rc.bottom = (int)Math.Round(appbarWindow.ActualHeight) + topOffset;
                }
                else
                {
                    barData.rc.bottom = actualScreenHeight + topOffset;
                    barData.rc.top    = barData.rc.bottom - (int)Math.Round(appbarWindow.ActualHeight);
                }
            }

            SHAppBarMessage((int)ABMsg.ABM_QUERYPOS, ref barData);
            SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref barData);

            Rect rect = new Rect((double)barData.rc.left, (double)barData.rc.top,
                                 (double)(barData.rc.right - barData.rc.left), (double)(barData.rc.bottom - barData.rc.top));

            //This is done async, because WPF will send a resize after a new appbar is added.
            //if we size right away, WPFs resize comes last and overrides us.
            appbarWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                                                new ResizeDelegate(DoResize), appbarWindow, rect);
        }
Ejemplo n.º 6
0
        public static void SetAppBar(Window appbarWindow, ABEdge edge, FrameworkElement childElement = null)
        {
            var info = GetRegisterInfo(appbarWindow);
            info.Edge = edge;
            info.ChildElement = childElement;

            var abd = new Interop.APPBARDATA();
            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd = new WindowInteropHelper(appbarWindow).Handle;

            int renderPolicy;

            if (edge == ABEdge.None)
            {
                if (info.IsRegistered)
                {
                    Interop.SHAppBarMessage((int)Interop.ABMsg.ABM_REMOVE, ref abd);
                    info.IsRegistered = false;
                }
                RestoreWindow(appbarWindow);

                // Restore normal desktop window manager attributes
                renderPolicy = (int)Interop.DWMNCRenderingPolicy.UseWindowStyle;

                Interop.DwmSetWindowAttribute(abd.hWnd, (int)Interop.DWMWINDOWATTRIBUTE.DWMA_EXCLUDED_FROM_PEEK, ref renderPolicy, sizeof(int));
                Interop.DwmSetWindowAttribute(abd.hWnd, (int)Interop.DWMWINDOWATTRIBUTE.DWMA_DISALLOW_PEEK, ref renderPolicy, sizeof(int));

                return;
            }

            if (!info.IsRegistered)
            {
                info.IsRegistered = true;
                info.CallbackId = Interop.RegisterWindowMessage("AppBarMessage");
                abd.uCallbackMessage = info.CallbackId;

                var ret = Interop.SHAppBarMessage((int)Interop.ABMsg.ABM_NEW, ref abd);

                var source = HwndSource.FromHwnd(abd.hWnd);
                source.AddHook(info.WndProc);
            }

            appbarWindow.WindowStyle = WindowStyle.None;
            appbarWindow.ResizeMode = ResizeMode.NoResize;
            appbarWindow.Topmost = true;

            // Set desktop window manager attributes to prevent window
            // from being hidden when peeking at the desktop or when
            // the 'show desktop' button is pressed
            renderPolicy = (int)Interop.DWMNCRenderingPolicy.Enabled;

            Interop.DwmSetWindowAttribute(abd.hWnd, (int)Interop.DWMWINDOWATTRIBUTE.DWMA_EXCLUDED_FROM_PEEK, ref renderPolicy, sizeof(int));
            Interop.DwmSetWindowAttribute(abd.hWnd, (int)Interop.DWMWINDOWATTRIBUTE.DWMA_DISALLOW_PEEK, ref renderPolicy, sizeof(int));

            ABSetPos(info.Edge, appbarWindow, childElement);
        }
Ejemplo n.º 7
0
        public void CreateForm(Screen screen, ABEdge edge, int amount)
        {
            var abd = new APPBARDATA();

            abd.cbSize = Marshal.SizeOf(abd);

            var ff = new Form();

            ff.AutoScaleBaseSize = new Size(1, 1);
            ff.ClientSize        = new Size(100, 100);
            ff.FormBorderStyle   = FormBorderStyle.FixedToolWindow;
            ff.Opacity           = 0;
            ff.Name          = "AerialSpacer";
            ff.ShowInTaskbar = false;
            ff.Show();

            abd.hWnd = ff.Handle;

            abd.uEdge     = (int)edge;
            abd.rc.left   = screen.WorkingArea.Left;
            abd.rc.right  = screen.WorkingArea.Right;
            abd.rc.top    = screen.WorkingArea.Top;
            abd.rc.bottom = screen.WorkingArea.Bottom;

            SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd);
            Application.DoEvents();
            SHAppBarMessage((int)ABMsg.ABM_QUERYPOS, ref abd);
            Application.DoEvents();

            switch (edge)
            {
            case ABEdge.ABE_TOP:
                abd.rc.bottom = abd.rc.top + amount;
                break;

            case ABEdge.ABE_BOTTOM:
                abd.rc.top = abd.rc.bottom - amount;
                break;

            case ABEdge.ABE_LEFT:
                abd.rc.right = abd.rc.left + amount;
                break;

            case ABEdge.ABE_RIGHT:
                abd.rc.left = abd.rc.right - amount;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(edge));
            }

            SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref abd);
            Application.DoEvents();
            Thread.Sleep(150);
            Application.DoEvents();
        }
Ejemplo n.º 8
0
        private static void ABSetPos(ABEdge edge, ABEdge prevEdge, Window appbarWindow)
        {
            APPBARDATA barData = new APPBARDATA();

            barData.cbSize = Marshal.SizeOf(barData);
            barData.hWnd   = new WindowInteropHelper(appbarWindow).Handle;
            barData.uEdge  = (int)edge;
            RECT wa = new RECT(SystemParameters.WorkArea);

            tb.Refresh();
            switch (edge)
            {
            case ABEdge.Top:
                barData.rc.Left   = wa.Left - (prevEdge == ABEdge.Left ? (int)Math.Round(appbarWindow.ActualWidth) : 0);
                barData.rc.Right  = wa.Right + (prevEdge == ABEdge.Right ? (int)Math.Round(appbarWindow.ActualWidth) : 0);
                barData.rc.Top    = wa.Top - (prevEdge == ABEdge.Top ? (int)Math.Round(appbarWindow.ActualHeight) : 0) - ((tb.Position != TaskBarPosition.Top && tb.PreviousPosition == TaskBarPosition.Top) ? tb.Height : 0) + ((tb.Position == TaskBarPosition.Top && tb.PreviousPosition != TaskBarPosition.Top) ? tb.Height : 0);
                barData.rc.Bottom = barData.rc.Top + (int)Math.Round(appbarWindow.ActualHeight);
                break;

            case ABEdge.Bottom:
                barData.rc.Left   = wa.Left - (prevEdge == ABEdge.Left ? (int)Math.Round(appbarWindow.ActualWidth) : 0);
                barData.rc.Right  = wa.Right + (prevEdge == ABEdge.Right ? (int)Math.Round(appbarWindow.ActualWidth) : 0);
                barData.rc.Bottom = wa.Bottom + (prevEdge == ABEdge.Bottom ? (int)Math.Round(appbarWindow.ActualHeight) : 0) - 1 + ((tb.Position != TaskBarPosition.Bottom && tb.PreviousPosition == TaskBarPosition.Bottom) ? tb.Height : 0) - ((tb.Position == TaskBarPosition.Bottom && tb.PreviousPosition != TaskBarPosition.Bottom) ? tb.Height : 0);
                barData.rc.Top    = barData.rc.Bottom - (int)Math.Round(appbarWindow.ActualHeight);
                break;
            }

            SHAppBarMessage((int)ABMsg.ABM_QUERYPOS, ref barData);
            switch (barData.uEdge)
            {
            case (int)ABEdge.Bottom:
                if (tb.Position == TaskBarPosition.Bottom && tb.PreviousPosition == tb.Position)
                {
                    barData.rc.Top   += (tb.PreviousHeight - tb.Height);
                    barData.rc.Bottom = barData.rc.Top + (int)appbarWindow.ActualHeight;
                }
                break;

            case (int)ABEdge.Top:
                if (tb.Position == TaskBarPosition.Top && tb.PreviousPosition == tb.Position)
                {
                    if (tb.PreviousHeight - tb.Height > 0)
                    {
                        barData.rc.Top -= (tb.PreviousHeight - tb.Height);
                    }
                    barData.rc.Bottom = barData.rc.Top + (int)appbarWindow.ActualHeight;
                }
                break;
            }
            SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref barData);

            Rect rect = new Rect((double)barData.rc.Left, (double)barData.rc.Top, (double)(barData.rc.Right - barData.rc.Left), (double)(barData.rc.Bottom - barData.rc.Top));

            appbarWindow.Dispatcher.BeginInvoke(new ResizeDelegate(DoResize), DispatcherPriority.ApplicationIdle, appbarWindow, rect);
        }
Ejemplo n.º 9
0
        public static void ABSetPos(Window appbarWindow, ABEdge edge)
        {
            APPBARDATA barData = new APPBARDATA();
            barData.cbSize = Marshal.SizeOf(barData);
            barData.hWnd = new WindowInteropHelper(appbarWindow).Handle;
            barData.uEdge = (int)edge;

            int leftOffset = 0;
            int topOffset = 0;
            int actualScreenWidth = (int)SystemParameters.PrimaryScreenWidth;
            int actualScreenHeight = (int)SystemParameters.PrimaryScreenHeight;

            GetActualScreenData(edge, appbarWindow, ref leftOffset, ref topOffset, ref actualScreenWidth, ref actualScreenHeight);

            if (barData.uEdge == (int)ABEdge.Left || barData.uEdge == (int)ABEdge.Right)
            {
                barData.rc.top = topOffset;
                barData.rc.bottom = actualScreenHeight;
                if (barData.uEdge == (int)ABEdge.Left)
                {
                    barData.rc.left = leftOffset;
                    barData.rc.right = (int)Math.Round(appbarWindow.ActualWidth) + leftOffset;
                }
                else
                {
                    barData.rc.right = actualScreenWidth + leftOffset;
                    barData.rc.left = barData.rc.right - (int)Math.Round(appbarWindow.ActualWidth);
                }
            }
            else
            {
                barData.rc.left = leftOffset;
                barData.rc.right = actualScreenWidth + leftOffset;
                if (barData.uEdge == (int)ABEdge.Top)
                {
                    barData.rc.top = topOffset;
                    barData.rc.bottom = (int)Math.Round(appbarWindow.ActualHeight) + topOffset;
                }
                else
                {
                    barData.rc.bottom = actualScreenHeight + topOffset;
                    barData.rc.top = barData.rc.bottom - (int)Math.Round(appbarWindow.ActualHeight);
                }
            }

            SHAppBarMessage((int)ABMsg.ABM_QUERYPOS, ref barData);
            SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref barData);

            Rect rect = new Rect((double)barData.rc.left, (double)barData.rc.top,
                (double)(barData.rc.right - barData.rc.left), (double)(barData.rc.bottom - barData.rc.top));
            //This is done async, because WPF will send a resize after a new appbar is added.
            //if we size right away, WPFs resize comes last and overrides us.
            appbarWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                new ResizeDelegate(DoResize), appbarWindow, rect);
        }
Ejemplo n.º 10
0
        public static void SetAppBar(Window appbarWindow, ABEdge edge, int screen)
        {
            RegisterInfo info = GetRegisterInfo(appbarWindow);

            info.Edge = edge;

            APPBARDATA abd = new APPBARDATA();

            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd   = new WindowInteropHelper(appbarWindow).Handle;

            //int renderPolicy;
            if (edge == ABEdge.None)
            {
                if (info.IsRegistered)
                {
                    SHAppBarMessage((int)ABMsg.ABM_REMOVE, ref abd);
                    info.IsRegistered = false;
                }
                RestoreWindow(appbarWindow);
                return;
            }

            if (!info.IsRegistered)
            {
                info.IsRegistered    = true;
                info.CallbackId      = RegisterWindowMessage("AppBarMessage");
                abd.uCallbackMessage = info.CallbackId;

                uint ret = SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd);

                HwndSource source = HwndSource.FromHwnd(abd.hWnd);
                source.AddHook(new HwndSourceHook(info.WndProc));
            }

            appbarWindow.WindowStyle = WindowStyle.None;
            appbarWindow.ResizeMode  = ResizeMode.NoResize;
            appbarWindow.Topmost     = true;

            AppBarWindow = appbarWindow;
            Edge         = edge;
            ScreenNum    = screen;

            appbarWindow.SizeChanged += appbarWindow_SizeChanged;
            ABSetPos(info.Edge, appbarWindow, screen);
        }
Ejemplo n.º 11
0
        private static void GetActualScreenData(ABEdge edge, Window appbarWindow, ref int leftOffset, ref int topOffset, ref int actualScreenWidth, ref int actualScreenHeight)
        {
            IntPtr handle        = new WindowInteropHelper(appbarWindow).Handle;
            IntPtr monitorHandle = MonitorFromWindow(handle, MONITOR_DEFAULTTONEAREST);

            MONITORINFO mi = new MONITORINFO();

            mi.cbSize = Marshal.SizeOf(mi);

            if (GetMonitorInfo(monitorHandle, ref mi))
            {
                if (mi.dwFlags == MONITORINFOF_PRIMARY)
                {
                    return;
                }
                leftOffset         = mi.rcWork.left;
                topOffset          = mi.rcWork.top;
                actualScreenWidth  = mi.rcWork.right - leftOffset;
                actualScreenHeight = mi.rcWork.bottom - mi.rcWork.top;
            }
        }
Ejemplo n.º 12
0
        public static void ABSetPos(AppBarWindow abWindow, Screen screen, double width, double height, ABEdge edge, bool isCreate = false)
        {
            lock (appBarLock)
            {
                NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA();
                abd.cbSize = Marshal.SizeOf(typeof(NativeMethods.APPBARDATA));
                IntPtr handle = new WindowInteropHelper(abWindow).Handle;
                abd.hWnd  = handle;
                abd.uEdge = (int)edge;
                int sWidth  = (int)width;
                int sHeight = (int)height;

                int top    = 0;
                int left   = 0;
                int right  = WindowManager.PrimaryMonitorDeviceSize.Width;
                int bottom = WindowManager.PrimaryMonitorDeviceSize.Height;

                /*PresentationSource ps = PresentationSource.FromVisual(abWindow);
                 *
                 * if (ps == null)
                 * {
                 *  // if we are racing with screen setting changes, this will be null
                 *  CairoLogger.Instance.Debug("AppBarHelper: Aborting ABSetPos due to window destruction");
                 *  return;
                 * }
                 *
                 * double dpiScale = ps.CompositionTarget.TransformToDevice.M11;*/

                if (screen != null)
                {
                    top    = screen.Bounds.Y;
                    left   = screen.Bounds.X;
                    right  = screen.Bounds.Right;
                    bottom = screen.Bounds.Bottom;
                }

                if (abd.uEdge == (int)ABEdge.ABE_LEFT || abd.uEdge == (int)ABEdge.ABE_RIGHT)
                {
                    abd.rc.top    = top;
                    abd.rc.bottom = bottom;
                    if (abd.uEdge == (int)ABEdge.ABE_LEFT)
                    {
                        abd.rc.left  = left;
                        abd.rc.right = abd.rc.left + sWidth;
                    }
                    else
                    {
                        abd.rc.right = right;
                        abd.rc.left  = abd.rc.right - sWidth;
                    }
                }
                else
                {
                    abd.rc.left  = left;
                    abd.rc.right = right;
                    if (abd.uEdge == (int)ABEdge.ABE_TOP)
                    {
                        if (!abWindow.requiresScreenEdge)
                        {
                            abd.rc.top = top + Convert.ToInt32(GetAppBarEdgeWindowsHeight((ABEdge)abd.uEdge, screen));
                        }
                        else
                        {
                            abd.rc.top = top;
                        }
                        abd.rc.bottom = abd.rc.top + sHeight;
                    }
                    else
                    {
                        if (!abWindow.requiresScreenEdge)
                        {
                            abd.rc.bottom = bottom - Convert.ToInt32(GetAppBarEdgeWindowsHeight((ABEdge)abd.uEdge, screen));
                        }
                        else
                        {
                            abd.rc.bottom = bottom;
                        }
                        abd.rc.top = abd.rc.bottom - sHeight;
                    }
                }

                prepareForInterop();
                NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_QUERYPOS, ref abd);
                interopDone();

                // system doesn't adjust all edges for us, do some adjustments
                switch (abd.uEdge)
                {
                case (int)ABEdge.ABE_LEFT:
                    abd.rc.right = abd.rc.left + sWidth;
                    break;

                case (int)ABEdge.ABE_RIGHT:
                    abd.rc.left = abd.rc.right - sWidth;
                    break;

                case (int)ABEdge.ABE_TOP:
                    abd.rc.bottom = abd.rc.top + sHeight;
                    break;

                case (int)ABEdge.ABE_BOTTOM:
                    abd.rc.top = abd.rc.bottom - sHeight;
                    break;
                }

                prepareForInterop();
                NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_SETPOS, ref abd);
                interopDone();

                // check if new coords
                bool isSameCoords = false;
                if (!isCreate)
                {
                    isSameCoords = abd.rc.top == (abWindow.Top * abWindow.dpiScale) && abd.rc.left == (abWindow.Left * abWindow.dpiScale) && abd.rc.bottom == (abWindow.Top * abWindow.dpiScale) + sHeight && abd.rc.right == (abWindow.Left * abWindow.dpiScale) + sWidth;
                }

                if (!isSameCoords)
                {
                    CairoLogger.Instance.Debug(string.Format("AppBarHelper: {0} changing position (TxLxBxR) to {1}x{2}x{3}x{4} from {5}x{6}x{7}x{8}", abWindow.Name, abd.rc.top, abd.rc.left, abd.rc.bottom, abd.rc.right, (abWindow.Top * abWindow.dpiScale), (abWindow.Left * abWindow.dpiScale), (abWindow.Top * abWindow.dpiScale) + sHeight, (abWindow.Left * abWindow.dpiScale) + sWidth));
                    abWindow.setAppBarPosition(abd.rc);
                }

                abWindow.afterAppBarPos(isSameCoords, abd.rc);

                if (abd.rc.bottom - abd.rc.top < sHeight)
                {
                    ABSetPos(abWindow, screen, width, height, edge);
                }
            }
        }
Ejemplo n.º 13
0
        public static void ABSetPos(Window abWindow, double width, double height, ABEdge edge)
        {
            NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA();
            abd.cbSize = Marshal.SizeOf(typeof(NativeMethods.APPBARDATA));
            IntPtr handle = new WindowInteropHelper(abWindow).Handle;

            abd.hWnd  = handle;
            abd.uEdge = (int)edge;
            int sWidth;
            int sHeight;

            // adjust size for dpi
            TransformToPixels(width, height, out sWidth, out sHeight);

            if (abd.uEdge == (int)ABEdge.ABE_LEFT || abd.uEdge == (int)ABEdge.ABE_RIGHT)
            {
                abd.rc.top    = 0;
                abd.rc.bottom = SystemInformation.WorkingArea.Bottom;
                if (abd.uEdge == (int)ABEdge.ABE_LEFT)
                {
                    abd.rc.left  = SystemInformation.WorkingArea.Left;
                    abd.rc.right = abd.rc.left + sWidth;
                }
                else
                {
                    abd.rc.right = SystemInformation.WorkingArea.Right;
                    abd.rc.left  = abd.rc.right - sWidth;
                }
            }
            else
            {
                abd.rc.left  = SystemInformation.WorkingArea.Left;
                abd.rc.right = SystemInformation.WorkingArea.Right;
                if (abd.uEdge == (int)ABEdge.ABE_TOP)
                {
                    abd.rc.top    = 0;
                    abd.rc.bottom = abd.rc.top + sHeight;
                }
                else
                {
                    abd.rc.bottom = SystemInformation.WorkingArea.Bottom;
                    abd.rc.top    = abd.rc.bottom - sHeight;
                }
            }

            NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_QUERYPOS, ref abd);

            // system doesn't adjust all edges for us, do some adjustments
            switch (abd.uEdge)
            {
            case (int)ABEdge.ABE_LEFT:
                abd.rc.right = abd.rc.left + sWidth;
                break;

            case (int)ABEdge.ABE_RIGHT:
                abd.rc.left = abd.rc.right - sWidth;
                break;

            case (int)ABEdge.ABE_TOP:
                abd.rc.bottom = abd.rc.top + sHeight;
                break;

            case (int)ABEdge.ABE_BOTTOM:
                abd.rc.top = abd.rc.bottom - sHeight;
                break;
            }

            NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_SETPOS, ref abd);

            // tracing
            int h = abd.rc.bottom - abd.rc.top;

            Trace.WriteLineIf(abd.uEdge == (int)ABEdge.ABE_TOP, "Top AppBar height is " + h.ToString());
            Trace.WriteLineIf(abd.uEdge == (int)ABEdge.ABE_BOTTOM, "Bottom AppBar height is " + h.ToString());

            abWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                                            new ResizeDelegate(DoResize), abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top);

            if (h < sHeight)
            {
                ABSetPos(abWindow, width, height, edge);
            }
        }
Ejemplo n.º 14
0
        private static void GetActualScreenData(ABEdge edge, Window appbarWindow, ref int leftOffset, ref int topOffset, ref int actualScreenWidth, ref int actualScreenHeight)
        {
            IntPtr handle = new WindowInteropHelper(appbarWindow).Handle;
            IntPtr monitorHandle = MonitorFromWindow(handle, MONITOR_DEFAULTTONEAREST);

            MONITORINFO mi = new MONITORINFO();
            mi.cbSize = Marshal.SizeOf(mi);

            if (GetMonitorInfo(monitorHandle, ref mi))
            {
                if (mi.dwFlags == MONITORINFOF_PRIMARY)
                {
                    return;
                }
                leftOffset = mi.rcWork.left;
                topOffset = mi.rcWork.top;
                actualScreenWidth = mi.rcWork.right - leftOffset;
                actualScreenHeight = mi.rcWork.bottom - mi.rcWork.top;
            }
        }
Ejemplo n.º 15
0
        private static void ABSetPos(ABEdge edge, Window appbarWindow, FrameworkElement childElement)
        {
            var barData = new Interop.APPBARDATA();
            barData.cbSize = Marshal.SizeOf(barData);
            barData.hWnd = new WindowInteropHelper(appbarWindow).Handle;
            barData.uEdge = (int)edge;

            // Transforms a coordinate from WPF space to Screen space
            var toPixel = PresentationSource.FromVisual(appbarWindow).CompositionTarget.TransformToDevice;
            // Transforms a coordinate from Screen space to WPF space
            var toWpfUnit = PresentationSource.FromVisual(appbarWindow).CompositionTarget.TransformFromDevice;

            // Transform window size from wpf units (1/96 ") to real pixels, for win32 usage
            var sizeInPixels = (childElement != null ?
                toPixel.Transform(new Vector(childElement.ActualWidth, childElement.ActualHeight)) :
                toPixel.Transform(new Vector(appbarWindow.ActualWidth, appbarWindow.ActualHeight)));
            // Even if the documentation says SystemParameters.PrimaryScreen{Width, Height} return values in
            // "pixels", they return wpf units instead.
            var screenSizeInPixels =
                toPixel.Transform(new Vector(SystemParameters.WorkArea.Width, SystemParameters.WorkArea.Height));

            if (barData.uEdge == (int)ABEdge.Left || barData.uEdge == (int)ABEdge.Right)
            {
                barData.rc.top = 0;
                barData.rc.bottom = (int)screenSizeInPixels.Y;
                if (barData.uEdge == (int)ABEdge.Left)
                {
                    barData.rc.left = 0;
                    barData.rc.right = (int)Math.Round(sizeInPixels.X);
                }
                else {
                    barData.rc.right = (int)screenSizeInPixels.X;
                    barData.rc.left = barData.rc.right - (int)Math.Round(sizeInPixels.X);
                }
            }
            else
            {
                barData.rc.left = 0;
                barData.rc.right = (int)screenSizeInPixels.X;
                if (barData.uEdge == (int)ABEdge.Top)
                {
                    barData.rc.top = 0;
                    barData.rc.bottom = (int)Math.Round(sizeInPixels.Y);
                }
                else {
                    barData.rc.bottom = (int)screenSizeInPixels.Y;
                    barData.rc.top = barData.rc.bottom - (int)Math.Round(sizeInPixels.Y);
                }
            }

            Interop.SHAppBarMessage((int)Interop.ABMsg.ABM_QUERYPOS, ref barData);
            Interop.SHAppBarMessage((int)Interop.ABMsg.ABM_SETPOS, ref barData);

            // transform back to wpf units, for wpf window resizing in DoResize.
            var location = toWpfUnit.Transform(new Point(barData.rc.left, barData.rc.top));
            var dimension = toWpfUnit.Transform(new Vector(barData.rc.right - barData.rc.left,
                barData.rc.bottom - barData.rc.top));

            var rect = new Rect(location, new Size(dimension.X, dimension.Y));

            //This is done async, because WPF will send a resize after a new appbar is added.
            //if we size right away, WPFs resize comes last and overrides us.
            appbarWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                new ResizeDelegate(DoResize), appbarWindow, rect);
        }
Ejemplo n.º 16
0
        public static int RegisterBar(IntPtr handle, Size size, ABEdge edge = ABEdge.ABE_TOP)
        {
            NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA();
            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd = handle;

            if (!appBars.Contains(handle))
            {
                uCallBack = NativeMethods.RegisterWindowMessage("AppBarMessage" + Guid.NewGuid().ToString());
                abd.uCallbackMessage = uCallBack;

                uint ret = NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_NEW, ref abd);
                appBars.Add(handle);

                ABSetPos(handle, size, edge);
            }
            else
            {
                NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_REMOVE, ref abd);
                appBars.Remove(handle);
            }

            return uCallBack;
        }
Ejemplo n.º 17
0
 private static void GetActualScreenData(ABEdge edge, Window appbarWindow, ref int leftOffset, ref int topOffset, ref int actualScreenWidth, ref int actualScreenHeight)
 {
     var secondaryScreen = System.Windows.Forms.Screen.AllScreens.LastOrDefault(s => !s.Primary);
     if (secondaryScreen == null) return;
     var workingArea = secondaryScreen.WorkingArea;
     leftOffset = workingArea.Left;
     topOffset = workingArea.Top;
     actualScreenWidth = workingArea.Width;
     actualScreenHeight = workingArea.Height;
 }
Ejemplo n.º 18
0
        public static int RegisterBar(Window abWindow, Screen screen, double width, double height, ABEdge edge = ABEdge.ABE_TOP)
        {
            lock (appBarLock)
            {
                APPBARDATA abd = new APPBARDATA();
                abd.cbSize = Marshal.SizeOf(typeof(APPBARDATA));
                IntPtr handle = new WindowInteropHelper(abWindow).Handle;
                abd.hWnd = handle;

                uCallBack            = RegisterWindowMessage("AppBarMessage");
                abd.uCallbackMessage = uCallBack;

                uint ret = SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd);

                ABSetPos(abWindow, screen, width, height, edge);
            }

            return(uCallBack);
        }
Ejemplo n.º 19
0
        private static void ABSetPos(ABEdge edge, Window appbarWindow, int screen)
        {
            APPBARDATA barData = new APPBARDATA();

            barData.cbSize = Marshal.SizeOf(barData);
            barData.hWnd   = new WindowInteropHelper(appbarWindow).Handle;
            barData.uEdge  = (int)edge;

            foreach (Screen s in Screen.AllScreens)
            {
                Trace.WriteLine(s.Bounds.ToString());
                Trace.WriteLine(Screen.AllScreens[screen].WorkingArea.ToString());
            }
            System.Drawing.Rectangle screenBounds;
            if (Screen.AllScreens.Count() > screen)
            {
                screenBounds = Screen.AllScreens[screen].Bounds;
            }
            else
            {
                screenBounds = Screen.PrimaryScreen.Bounds;
            }

            Window             MainWindow = System.Windows.Application.Current.MainWindow;
            PresentationSource MainWindowPresentationSource = PresentationSource.FromVisual(MainWindow);
            Matrix             m = MainWindowPresentationSource.CompositionTarget.TransformToDevice;
            double             thisDpiWidthFactor  = m.M11;
            double             thisDpiHeightFactor = m.M22;

            if (UsersDockingCalculationMode == DockingCalculationMode.Surface)
            {
                Trace.WriteLine("Docking in Surface Mode");
                // following is needed for Surface for some reason
                barData.rc.right  = (int)(screenBounds.Right * thisDpiWidthFactor);
                barData.rc.top    = (int)(screenBounds.Top * thisDpiHeightFactor);
                barData.rc.bottom = (int)(screenBounds.Bottom * thisDpiHeightFactor);
                barData.rc.left   = (int)(screenBounds.Left * thisDpiWidthFactor);
                if (barData.uEdge == (int)ABEdge.Left)
                {
                    barData.rc.right = barData.rc.left + (int)(appbarWindow.ActualWidth * thisDpiWidthFactor);
                }
                else if (barData.uEdge == (int)ABEdge.Right)
                {
                    barData.rc.left = barData.rc.right - (int)(appbarWindow.ActualWidth * thisDpiWidthFactor);
                }
                else if (barData.uEdge == (int)ABEdge.Top)
                {
                    barData.rc.bottom = barData.rc.top + (int)(appbarWindow.ActualHeight * thisDpiHeightFactor);
                }
                else if (barData.uEdge == (int)ABEdge.Bottom)
                {
                    barData.rc.top = barData.rc.bottom - (int)(appbarWindow.ActualHeight * thisDpiHeightFactor);
                }
            }
            else if (UsersDockingCalculationMode == DockingCalculationMode.Standard)
            {
                // if !Surface
                Trace.WriteLine("Docking in Standard Mode");
                barData.rc.right  = (int)(screenBounds.Right / thisDpiWidthFactor);
                barData.rc.bottom = (int)(screenBounds.Bottom / thisDpiHeightFactor);
                barData.rc.left   = (int)(screenBounds.Left / thisDpiWidthFactor);
                barData.rc.top    = (int)(screenBounds.Top / thisDpiHeightFactor);
                if (barData.uEdge == (int)ABEdge.Left)
                {
                    barData.rc.right = barData.rc.left + (int)(appbarWindow.ActualWidth);
                }
                else if (barData.uEdge == (int)ABEdge.Right)
                {
                    barData.rc.left = barData.rc.right - (int)(appbarWindow.ActualWidth);
                }
                else if (barData.uEdge == (int)ABEdge.Top)
                {
                    barData.rc.bottom = barData.rc.top + (int)(appbarWindow.ActualHeight);
                }
                else if (barData.uEdge == (int)ABEdge.Bottom)
                {
                    barData.rc.top = barData.rc.bottom - (int)(appbarWindow.ActualHeight);
                }
            }
            uint ret;

            ret = SHAppBarMessage((int)ABMsg.ABM_QUERYPOS, ref barData);
            ret = SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref barData);
            //barData.lParam = (IntPtr)1;
            //ret = SHAppBarMessage((int)ABMsg.ABM_SETAUTOHIDEBAR, ref barData);
            //ret = SHAppBarMessage((int)ABMsg.ABM_GETAUTOHIDEBAR, ref barData);

            if (UsersDockingCalculationMode == DockingCalculationMode.Surface)
            {
                // if Surface = Really not sure why its different on the surface
                barData.rc.top    = (int)(barData.rc.top / thisDpiWidthFactor);
                barData.rc.bottom = (int)(barData.rc.bottom / thisDpiWidthFactor);
                barData.rc.left   = (int)(barData.rc.left / thisDpiWidthFactor);
                barData.rc.right  = (int)(barData.rc.right / thisDpiWidthFactor);
            }
            else if (UsersDockingCalculationMode == DockingCalculationMode.Standard)
            {
                // if !Surface
                if (barData.uEdge == (int)ABEdge.Left)
                {
                    barData.rc.right = barData.rc.left + (int)appbarWindow.ActualWidth;
                }
                else if (barData.uEdge == (int)ABEdge.Right)
                {
                    barData.rc.left = barData.rc.right - (int)appbarWindow.ActualWidth;
                }
                else if (barData.uEdge == (int)ABEdge.Top)
                {
                    barData.rc.bottom = barData.rc.top + (int)appbarWindow.ActualHeight;
                }
                else if (barData.uEdge == (int)ABEdge.Bottom)
                {
                    barData.rc.top = barData.rc.bottom - (int)appbarWindow.ActualHeight;
                }
            }

            //This is done async, because WPF will send a resize after a new appbar is added.
            //if we size right away, WPFs resize comes last and overrides us.
            appbarWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                                                new ResizeDelegate(DoResize), appbarWindow, barData.rc);
        }
Ejemplo n.º 20
0
        public static void ABSetPos(Window abWindow, Screen screen, double width, double height, ABEdge edge, bool isCreate = false)
        {
            lock (appBarLock)
            {
                NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA();
                abd.cbSize = Marshal.SizeOf(typeof(NativeMethods.APPBARDATA));
                IntPtr handle = new WindowInteropHelper(abWindow).Handle;
                abd.hWnd  = handle;
                abd.uEdge = (int)edge;
                int sWidth  = (int)width;
                int sHeight = (int)height;

                int top    = 0;
                int left   = SystemInformation.WorkingArea.Left;
                int right  = SystemInformation.WorkingArea.Right;
                int bottom = PrimaryMonitorDeviceSize.Height;

                double dpiScale = PresentationSource.FromVisual(abWindow).CompositionTarget.TransformToDevice.M11;

                if (screen != null)
                {
                    top    = screen.Bounds.Y;
                    left   = screen.WorkingArea.Left;
                    right  = screen.WorkingArea.Right;
                    bottom = screen.Bounds.Bottom;
                }

                if (abd.uEdge == (int)ABEdge.ABE_LEFT || abd.uEdge == (int)ABEdge.ABE_RIGHT)
                {
                    abd.rc.top    = top;
                    abd.rc.bottom = bottom;
                    if (abd.uEdge == (int)ABEdge.ABE_LEFT)
                    {
                        abd.rc.left  = left;
                        abd.rc.right = abd.rc.left + sWidth;
                    }
                    else
                    {
                        abd.rc.right = right;
                        abd.rc.left  = abd.rc.right - sWidth;
                    }
                }
                else
                {
                    abd.rc.left  = left;
                    abd.rc.right = right;
                    if (abd.uEdge == (int)ABEdge.ABE_TOP)
                    {
                        if (abWindow is Taskbar)
                        {
                            abd.rc.top = top + Convert.ToInt32(Startup.MenuBarWindow.Height);
                        }
                        else
                        {
                            abd.rc.top = top;
                        }
                        abd.rc.bottom = abd.rc.top + sHeight;
                    }
                    else
                    {
                        abd.rc.bottom = bottom;
                        abd.rc.top    = abd.rc.bottom - sHeight;
                    }
                }

                prepareForInterop();
                NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_QUERYPOS, ref abd);
                interopDone();

                // system doesn't adjust all edges for us, do some adjustments
                switch (abd.uEdge)
                {
                case (int)ABEdge.ABE_LEFT:
                    abd.rc.right = abd.rc.left + sWidth;
                    break;

                case (int)ABEdge.ABE_RIGHT:
                    abd.rc.left = abd.rc.right - sWidth;
                    break;

                case (int)ABEdge.ABE_TOP:
                    abd.rc.bottom = abd.rc.top + sHeight;
                    break;

                case (int)ABEdge.ABE_BOTTOM:
                    abd.rc.top = abd.rc.bottom - sHeight;
                    break;
                }

                prepareForInterop();
                NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_SETPOS, ref abd);
                interopDone();

                // tracing
                bool isSameCoords = false;
                if (!isCreate)
                {
                    isSameCoords = abd.rc.top == (abWindow.Top * dpiScale) && abd.rc.left == (abWindow.Left * dpiScale) && abd.rc.bottom == (abWindow.Top * dpiScale) + sHeight && abd.rc.right == (abWindow.Left * dpiScale) + sWidth;
                }
                int h = abd.rc.bottom - abd.rc.top;
                if (!isSameCoords)
                {
                    CairoLogger.Instance.Debug(abWindow.Name + " AppBar height is " + h.ToString());
                }

                abWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                                                new ResizeDelegate(DoResize), abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, isSameCoords);

                if (h < sHeight)
                {
                    ABSetPos(abWindow, screen, width, height, edge);
                }
            }
        }
Ejemplo n.º 21
0
        public static void ABSetPos(AppBarWindow abWindow, double width, double height, ABEdge edge, bool isCreate = false)
        {
            lock (appBarLock)
            {
                APPBARDATA abd = new APPBARDATA
                {
                    cbSize = Marshal.SizeOf(typeof(APPBARDATA)),
                    hWnd   = abWindow.Handle,
                    uEdge  = (int)edge
                };

                int sWidth  = (int)width;
                int sHeight = (int)height;

                int top    = 0;
                int left   = 0;
                int right  = WindowManager.PrimaryMonitorDeviceSize.Width;
                int bottom = WindowManager.PrimaryMonitorDeviceSize.Height;

                if (abWindow.Screen != null)
                {
                    top    = abWindow.Screen.Bounds.Y;
                    left   = abWindow.Screen.Bounds.X;
                    right  = abWindow.Screen.Bounds.Right;
                    bottom = abWindow.Screen.Bounds.Bottom;
                }

                if (abd.uEdge == (int)ABEdge.ABE_LEFT || abd.uEdge == (int)ABEdge.ABE_RIGHT)
                {
                    abd.rc.Top    = top;
                    abd.rc.Bottom = bottom;
                    if (abd.uEdge == (int)ABEdge.ABE_LEFT)
                    {
                        abd.rc.Left  = left;
                        abd.rc.Right = abd.rc.Left + sWidth;
                    }
                    else
                    {
                        abd.rc.Right = right;
                        abd.rc.Left  = abd.rc.Right - sWidth;
                    }
                }
                else
                {
                    abd.rc.Left  = left;
                    abd.rc.Right = right;
                    if (abd.uEdge == (int)ABEdge.ABE_TOP)
                    {
                        if (!abWindow.requiresScreenEdge)
                        {
                            abd.rc.Top = top + Convert.ToInt32(GetAppBarEdgeWindowsHeight((ABEdge)abd.uEdge, abWindow.Screen));
                        }
                        else
                        {
                            abd.rc.Top = top;
                        }

                        abd.rc.Bottom = abd.rc.Top + sHeight;
                    }
                    else
                    {
                        if (!abWindow.requiresScreenEdge)
                        {
                            abd.rc.Bottom = bottom - Convert.ToInt32(GetAppBarEdgeWindowsHeight((ABEdge)abd.uEdge, abWindow.Screen));
                        }
                        else
                        {
                            abd.rc.Bottom = bottom;
                        }

                        abd.rc.Top = abd.rc.Bottom - sHeight;
                    }
                }

                PrepareForInterop();
                SHAppBarMessage((int)ABMsg.ABM_QUERYPOS, ref abd);
                InteropDone();

                // system doesn't adjust all edges for us, do some adjustments
                switch (abd.uEdge)
                {
                case (int)ABEdge.ABE_LEFT:
                    abd.rc.Right = abd.rc.Left + sWidth;
                    break;

                case (int)ABEdge.ABE_RIGHT:
                    abd.rc.Left = abd.rc.Right - sWidth;
                    break;

                case (int)ABEdge.ABE_TOP:
                    abd.rc.Bottom = abd.rc.Top + sHeight;
                    break;

                case (int)ABEdge.ABE_BOTTOM:
                    abd.rc.Top = abd.rc.Bottom - sHeight;
                    break;
                }

                PrepareForInterop();
                SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref abd);
                InteropDone();

                // check if new coords
                bool isSameCoords = false;
                if (!isCreate)
                {
                    bool topUnchanged    = abd.rc.Top == (abWindow.Top * abWindow.dpiScale);
                    bool leftUnchanged   = abd.rc.Left == (abWindow.Left * abWindow.dpiScale);
                    bool bottomUnchanged = abd.rc.Bottom == (abWindow.Top * abWindow.dpiScale) + sHeight;
                    bool rightUnchanged  = abd.rc.Right == (abWindow.Left * abWindow.dpiScale) + sWidth;

                    isSameCoords = topUnchanged &&
                                   leftUnchanged &&
                                   bottomUnchanged &&
                                   rightUnchanged;
                }

                if (!isSameCoords)
                {
                    CairoLogger.Instance.Debug($"AppBarHelper: {abWindow.Name} changing position (TxLxBxR) to {abd.rc.Top}x{abd.rc.Left}x{abd.rc.Bottom}x{ abd.rc.Right} from {abWindow.Top * abWindow.dpiScale}x{abWindow.Left * abWindow.dpiScale}x{(abWindow.Top * abWindow.dpiScale) + sHeight}x{ (abWindow.Left * abWindow.dpiScale) + sWidth}");
                    abWindow.SetAppBarPosition(abd.rc);
                }

                abWindow.AfterAppBarPos(isSameCoords, abd.rc);

                if (abd.rc.Bottom - abd.rc.Top < sHeight)
                {
                    ABSetPos(abWindow, width, height, edge);
                }
            }
        }
Ejemplo n.º 22
0
        public static void ABSetPos(IntPtr handle, Size size, ABEdge edge)
        {
            NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA();
            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd = handle;
            abd.uEdge = (int)edge;

            if (abd.uEdge == (int)ABEdge.ABE_LEFT || abd.uEdge == (int)ABEdge.ABE_RIGHT)
            {
                abd.rc.top = 0;
                abd.rc.bottom = PrimaryMonitorSize.Height;
                if (abd.uEdge == (int)ABEdge.ABE_LEFT)
                {
                    abd.rc.left = 0;
                    abd.rc.right = size.Width;
                }
                else
                {
                    abd.rc.right = PrimaryMonitorSize.Width;
                    abd.rc.left = abd.rc.right - size.Width;
                }

            }
            else
            {
                abd.rc.left = 0;
                abd.rc.right = PrimaryMonitorSize.Width;
                if (abd.uEdge == (int)ABEdge.ABE_TOP)
                {
                    abd.rc.top = 0;
                    abd.rc.bottom = size.Height;
                }
                else
                {
                    abd.rc.bottom = PrimaryMonitorSize.Height;
                    abd.rc.top = abd.rc.bottom - size.Height;
                }
            }

            NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_QUERYPOS, ref abd);

            switch (abd.uEdge)
            {
                case (int)ABEdge.ABE_LEFT:
                    abd.rc.right = abd.rc.left + size.Width;
                    break;
                case (int)ABEdge.ABE_RIGHT:
                    abd.rc.left = abd.rc.right - size.Width;
                    break;
                case (int)ABEdge.ABE_TOP:
                    abd.rc.bottom = abd.rc.top + size.Height;
                    break;
                case (int)ABEdge.ABE_BOTTOM:
                    abd.rc.top = abd.rc.bottom - size.Height;
                    break;
            }

            NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_SETPOS, ref abd);

            // tracing
            Trace.WriteLineIf(abd.uEdge == (int)ABEdge.ABE_TOP, "Top AppBar height is " + (abd.rc.bottom - abd.rc.top).ToString());
            Trace.WriteLineIf(abd.uEdge == (int)ABEdge.ABE_BOTTOM, "Bottom AppBar height is " + (abd.rc.bottom - abd.rc.top).ToString());

            NativeMethods.MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, true);
        }
Ejemplo n.º 23
0
 private void SetAsAppBar(ABEdge edge)
 {
     _currentAppBarEdge = edge;
     AppBarFunctions.SetAppBar(this, edge, topMost: Settings.Topmost);
 }
 private void SetAsAppBar(ABEdge edge) => AppBarFunctions.SetAppBar(this, edge, topMost: Settings.Topmost);
Ejemplo n.º 25
0
        private static void ABSetPos(ABEdge edge, Window appbarWindow)
        {
            var barData = new Interop.APPBARDATA();

            barData.cbSize = Marshal.SizeOf(barData);
            barData.hWnd   = new WindowInteropHelper(appbarWindow).Handle;
            barData.uEdge  = (int)edge;

            // Transforms a coordinate from WPF space to Screen space
            var toPixel = PresentationSource.FromVisual(appbarWindow).CompositionTarget.TransformToDevice;
            // Transforms a coordinate from Screen space to WPF space
            var toWpfUnit = PresentationSource.FromVisual(appbarWindow).CompositionTarget.TransformFromDevice;

            // Transform window size from wpf units (1/96 ") to real pixels, for win32 usage
            var sizeInPixels = toPixel.Transform(new Vector(appbarWindow.ActualWidth, appbarWindow.ActualHeight));
            // Even if the documentation says SystemParameters.PrimaryScreen{Width, Height} return values in
            // "pixels", they return wpf units instead.
            var screenSizeInPixels =
                toPixel.Transform(new Vector(SystemParameters.PrimaryScreenWidth, SystemParameters.PrimaryScreenHeight));

            if (barData.uEdge == (int)ABEdge.Left || barData.uEdge == (int)ABEdge.Right)
            {
                barData.rc.top    = 0;
                barData.rc.bottom = (int)screenSizeInPixels.Y;
                if (barData.uEdge == (int)ABEdge.Left)
                {
                    barData.rc.left  = 0;
                    barData.rc.right = (int)Math.Round(sizeInPixels.X);
                }
                else
                {
                    barData.rc.right = (int)screenSizeInPixels.X;
                    barData.rc.left  = barData.rc.right - (int)Math.Round(sizeInPixels.X);
                }
            }
            else
            {
                barData.rc.left  = 0;
                barData.rc.right = (int)screenSizeInPixels.X;
                if (barData.uEdge == (int)ABEdge.Top)
                {
                    barData.rc.top    = 0;
                    barData.rc.bottom = (int)Math.Round(sizeInPixels.Y);
                }
                else
                {
                    barData.rc.bottom = (int)screenSizeInPixels.Y;
                    barData.rc.top    = barData.rc.bottom - (int)Math.Round(sizeInPixels.Y);
                }
            }

            Interop.SHAppBarMessage((int)Interop.ABMsg.ABM_QUERYPOS, ref barData);
            Interop.SHAppBarMessage((int)Interop.ABMsg.ABM_SETPOS, ref barData);

            // transform back to wpf units, for wpf window resizing in DoResize.
            var location  = toWpfUnit.Transform(new Point(barData.rc.left, barData.rc.top));
            var dimension = toWpfUnit.Transform(new Vector(barData.rc.right - barData.rc.left,
                                                           barData.rc.bottom - barData.rc.top));

            var rect = new Rect(location, new Size(dimension.X, dimension.Y));

            //This is done async, because WPF will send a resize after a new appbar is added.
            //if we size right away, WPFs resize comes last and overrides us.
            appbarWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                                                new ResizeDelegate(DoResize), appbarWindow, rect);
        }
Ejemplo n.º 26
0
        public static void ABSetPos(Window abWindow, Screen screen, double width, double height, ABEdge edge)
        {
            lock (appBarLock)
            {
                APPBARDATA abd = new APPBARDATA();
                abd.cbSize = Marshal.SizeOf(typeof(APPBARDATA));
                IntPtr handle = new WindowInteropHelper(abWindow).Handle;
                abd.hWnd  = handle;
                abd.uEdge = (int)edge;
                int sWidth  = (int)width;
                int sHeight = (int)height;

                int top    = 0;
                int left   = SystemInformation.PrimaryMonitorSize.Width;  //TODO
                int right  = SystemInformation.PrimaryMonitorSize.Height; //TODO
                int bottom = (int)Math.Floor(42 * App.DPI);               //BIGTODO TODO

                if (screen != null)
                {
                    top    = screen.Bounds.Y;
                    left   = screen.Bounds.Left;
                    right  = screen.Bounds.Right;
                    bottom = screen.Bounds.Bottom;
                }

                if (abd.uEdge == (int)ABEdge.ABE_LEFT || abd.uEdge == (int)ABEdge.ABE_RIGHT)
                {
                    abd.rc.Top    = top;
                    abd.rc.Bottom = bottom;
                    if (abd.uEdge == (int)ABEdge.ABE_LEFT)
                    {
                        abd.rc.Left  = left;
                        abd.rc.Right = abd.rc.Left + sWidth;
                    }
                    else
                    {
                        abd.rc.Right = right;
                        abd.rc.Left  = abd.rc.Right - sWidth;
                    }
                }
                else
                {
                    abd.rc.Left  = left;
                    abd.rc.Right = right;
                    if (abd.uEdge == (int)ABEdge.ABE_TOP)
                    {
                        if (abWindow is TaskbarWindow)
                        {
                            abd.rc.Top = top + Convert.ToInt32(24 * App.DPI); //BIGTODO TODO
                        }
                        else
                        {
                            abd.rc.Top = top;
                        }
                        abd.rc.Bottom = abd.rc.Top + sHeight;
                    }
                    else
                    {
                        abd.rc.Bottom = bottom;
                        abd.rc.Top    = abd.rc.Bottom - sHeight;
                    }
                }

                SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref abd);

                int h = abd.rc.Bottom - abd.rc.Top;

                abWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                                                new ResizeDelegate(DoResize), abd.hWnd, abd.rc.Left, abd.rc.Top,
                                                abd.rc.Right - abd.rc.Left, abd.rc.Bottom - abd.rc.Top);

                if (h < sHeight)
                {
                    ABSetPos(abWindow, screen, width, height, edge);
                }
            }
        }
Ejemplo n.º 27
0
        public static int RegisterBar(Window abWindow, Screen screen, double width, double height, ABEdge edge = ABEdge.ABE_TOP)
        {
            lock (appBarLock)
            {
                NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA();
                abd.cbSize = Marshal.SizeOf(typeof(NativeMethods.APPBARDATA));
                IntPtr handle = new WindowInteropHelper(abWindow).Handle;
                abd.hWnd = handle;

                if (!appBars.Contains(handle))
                {
                    uCallBack            = NativeMethods.RegisterWindowMessage("AppBarMessage");
                    abd.uCallbackMessage = uCallBack;

                    prepareForInterop();
                    uint ret = NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_NEW, ref abd);
                    interopDone();
                    appBars.Add(handle);
                    CairoLogger.Instance.Debug("Created AppBar for handle " + handle.ToString());

                    ABSetPos(abWindow, screen, width, height, edge, true);
                }
                else
                {
                    prepareForInterop();
                    NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_REMOVE, ref abd);
                    interopDone();
                    appBars.Remove(handle);
                    CairoLogger.Instance.Debug("Removed AppBar for handle " + handle.ToString());

                    return(0);
                }
            }

            return(uCallBack);
        }
Ejemplo n.º 28
0
        public static void ABSetPos(Window abWindow, Screen screen, double width, double height, ABEdge edge)
        {
            NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA();
            abd.cbSize = Marshal.SizeOf(typeof(NativeMethods.APPBARDATA));
            IntPtr handle = new WindowInteropHelper(abWindow).Handle;

            abd.hWnd  = handle;
            abd.uEdge = (int)edge;
            int sWidth  = (int)width;
            int sHeight = (int)height;

            int top    = 0;
            int left   = SystemInformation.WorkingArea.Left;
            int right  = SystemInformation.WorkingArea.Right;
            int bottom = PrimaryMonitorDeviceSize.Height;

            if (screen != null)
            {
                top    = screen.Bounds.Y;
                left   = screen.WorkingArea.Left;
                right  = screen.WorkingArea.Right;
                bottom = screen.Bounds.Bottom;
            }

            if (abd.uEdge == (int)ABEdge.ABE_LEFT || abd.uEdge == (int)ABEdge.ABE_RIGHT)
            {
                abd.rc.top    = top;
                abd.rc.bottom = bottom;
                if (abd.uEdge == (int)ABEdge.ABE_LEFT)
                {
                    abd.rc.left  = left;
                    abd.rc.right = abd.rc.left + sWidth;
                }
                else
                {
                    abd.rc.right = right;
                    abd.rc.left  = abd.rc.right - sWidth;
                }
            }
            else
            {
                abd.rc.left  = left;
                abd.rc.right = right;
                if (abd.uEdge == (int)ABEdge.ABE_TOP)
                {
                    if (abWindow is Taskbar)
                    {
                        abd.rc.top = top + Convert.ToInt32(Startup.MenuBarWindow.Height);
                    }
                    else
                    {
                        abd.rc.top = top;
                    }
                    abd.rc.bottom = abd.rc.top + sHeight;
                }
                else
                {
                    abd.rc.bottom = bottom;
                    abd.rc.top    = abd.rc.bottom - sHeight;
                }
            }

            NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_QUERYPOS, ref abd);

            // system doesn't adjust all edges for us, do some adjustments
            switch (abd.uEdge)
            {
            case (int)ABEdge.ABE_LEFT:
                abd.rc.right = abd.rc.left + sWidth;
                break;

            case (int)ABEdge.ABE_RIGHT:
                abd.rc.left = abd.rc.right - sWidth;
                break;

            case (int)ABEdge.ABE_TOP:
                abd.rc.bottom = abd.rc.top + sHeight;
                break;

            case (int)ABEdge.ABE_BOTTOM:
                abd.rc.top = abd.rc.bottom - sHeight;
                break;
            }

            NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_SETPOS, ref abd);

            // tracing
            int h = abd.rc.bottom - abd.rc.top;

            Trace.WriteLineIf(abd.uEdge == (int)ABEdge.ABE_TOP, "Top AppBar height is " + h.ToString());
            Trace.WriteLineIf(abd.uEdge == (int)ABEdge.ABE_BOTTOM, "Bottom AppBar height is " + h.ToString());

            abWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                                            new ResizeDelegate(DoResize), abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top);

            if (h < sHeight)
            {
                ABSetPos(abWindow, screen, width, height, edge);
            }
        }