Ejemplo n.º 1
0
        public void NotifyAppBarEvent(AppBarWindow sender, AppBarEventReason reason)
        {
            AppBarEventArgs args = new AppBarEventArgs {
                Reason = reason
            };

            AppBarEvent?.Invoke(sender, args);
        }
Ejemplo n.º 2
0
        public int RegisterBar(AppBarWindow abWindow, double width, double height, AppBarEdge edge = AppBarEdge.Top)
        {
            lock (appBarLock)
            {
                APPBARDATA abd = new APPBARDATA();
                abd.cbSize = Marshal.SizeOf(typeof(APPBARDATA));
                abd.hWnd   = abWindow.Handle;

                if (!AppBars.Contains(abWindow))
                {
                    if (!EnvironmentHelper.IsAppRunningAsShell)
                    {
                        uCallBack            = RegisterWindowMessage("AppBarMessage");
                        abd.uCallbackMessage = uCallBack;

                        SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd);
                    }

                    AppBars.Add(abWindow);

                    ShellLogger.Debug($"AppBarManager: Created AppBar for handle {abWindow.Handle}");

                    if (!EnvironmentHelper.IsAppRunningAsShell)
                    {
                        ABSetPos(abWindow, width, height, edge, true);
                    }
                    else
                    {
                        SetWorkArea(abWindow.Screen);
                    }
                }
                else
                {
                    if (!EnvironmentHelper.IsAppRunningAsShell)
                    {
                        SHAppBarMessage((int)ABMsg.ABM_REMOVE, ref abd);
                    }

                    AppBars.Remove(abWindow);
                    ShellLogger.Debug($"AppBarManager: Removed AppBar for handle {abWindow.Handle}");

                    if (EnvironmentHelper.IsAppRunningAsShell)
                    {
                        SetWorkArea(abWindow.Screen);
                    }

                    return(0);
                }
            }

            return(uCallBack);
        }
Ejemplo n.º 3
0
        public void ABSetPos(AppBarWindow abWindow, double width, double height, AppBarEdge 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  = ScreenHelper.PrimaryMonitorDeviceSize.Width;
                int bottom = ScreenHelper.PrimaryMonitorDeviceSize.Height;

                int edgeOffset = 0;

                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 (!abWindow.RequiresScreenEdge)
                {
                    edgeOffset = Convert.ToInt32(GetAppBarEdgeWindowsHeight((AppBarEdge)abd.uEdge, abWindow.Screen));
                }

                if (abd.uEdge == (int)AppBarEdge.Left || abd.uEdge == (int)AppBarEdge.Right)
                {
                    abd.rc.Top    = top;
                    abd.rc.Bottom = bottom;
                    if (abd.uEdge == (int)AppBarEdge.Left)
                    {
                        abd.rc.Left  = left + edgeOffset;
                        abd.rc.Right = abd.rc.Left + sWidth;
                    }
                    else
                    {
                        abd.rc.Right = right - edgeOffset;
                        abd.rc.Left  = abd.rc.Right - sWidth;
                    }
                }
                else
                {
                    abd.rc.Left  = left;
                    abd.rc.Right = right;
                    if (abd.uEdge == (int)AppBarEdge.Top)
                    {
                        abd.rc.Top    = top + edgeOffset;
                        abd.rc.Bottom = abd.rc.Top + sHeight;
                    }
                    else
                    {
                        abd.rc.Bottom = bottom - edgeOffset;
                        abd.rc.Top    = abd.rc.Bottom - sHeight;
                    }
                }

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

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

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

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

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

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

                // 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)
                {
                    ShellLogger.Debug($"AppBarManager: {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.uEdge == (int)AppBarEdge.Top || abd.uEdge == (int)AppBarEdge.Bottom) && abd.rc.Bottom - abd.rc.Top < sHeight) ||
                    ((abd.uEdge == (int)AppBarEdge.Left || abd.uEdge == (int)AppBarEdge.Right) && abd.rc.Right - abd.rc.Left < sWidth))
                {
                    ABSetPos(abWindow, width, height, edge);
                }
            }
        }