Example #1
0
            public void Hide()
            {
                var appBarData = new NativeMethods.APPBARDATA(this.Handle, uEdge: NativeMethods.ABE.ABE_TOP);

                NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_QUERYPOS, ref appBarData);
                NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_SETPOS, ref appBarData);

                this.visible = false;
            }
Example #2
0
            public void Destroy()
            {
                // unregister as AppBar
                var appBarData = new NativeMethods.APPBARDATA(this.Handle);

                NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_REMOVE, ref appBarData);

                DestroyHandle();
            }
Example #3
0
        private static void InternalSetAutoHide(bool hide)
        {
            var data = new NativeMethods.APPBARDATA {
                lParam = hide ? NativeMethods.ABS.Autohide : NativeMethods.ABS.AlwaysOnTop
            };

            NativeMethods.SHAppBarMessage(NativeMethods.ABM.SetState, ref data);
            UpdateTaskbar();
        }
Example #4
0
 public static void AppBarWindowPosChanged(IntPtr hwnd)
 {
     NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA();
     abd.cbSize = (int)Marshal.SizeOf(typeof(NativeMethods.APPBARDATA));
     abd.hWnd   = hwnd;
     prepareForInterop();
     NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_WINDOWPOSCHANGED, ref abd);
     interopDone();
 }
Example #5
0
        public static void AppBarActivate(IntPtr hwnd)
        {
            NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA();
            abd.cbSize = (int)Marshal.SizeOf(typeof(NativeMethods.APPBARDATA));
            abd.hWnd   = hwnd;
            abd.lParam = (IntPtr)Convert.ToInt32(true);
            NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_ACTIVATE, ref abd);

            // apparently the taskbars like to pop up when app bars change
            if (Settings.EnableTaskbar)
            {
                SetSecondaryTaskbarVisibility(NativeMethods.WindowShowStyle.Hide);
            }
        }
Example #6
0
        /// <summary>
        /// Retrieves taskbar position and alignment.
        /// </summary>
        /// <returns>Taskbar position and alignment.</returns>
        public static TaskBarInfo GetTaskBarInfo()
        {
            // allocate appbardata structure
            NativeMethods.APPBARDATA abdata = new NativeMethods.APPBARDATA()
            {
                hWnd = IntPtr.Zero
            };
            abdata.cbSize = (uint)Marshal.SizeOf(abdata);

            // get task bar info
            IntPtr result = NativeMethods.SHAppBarMessage(NativeMethods.ABMsg.ABM_GETTASKBARPOS, ref abdata);

            // return null if the call failed
            if (result == IntPtr.Zero)
            {
                throw new Exception("Could not retrieve taskbar information.");
            }

            Rectangle position = abdata.rc;

            TaskBarAlignment alignment;

            switch (abdata.uEdge)
            {
            case NativeMethods.ABEdge.ABE_BOTTOM:
                alignment = TaskBarAlignment.Bottom;
                break;

            case NativeMethods.ABEdge.ABE_TOP:
                alignment = TaskBarAlignment.Top;
                break;

            case NativeMethods.ABEdge.ABE_LEFT:
                alignment = TaskBarAlignment.Left;
                break;

            case NativeMethods.ABEdge.ABE_RIGHT:
                alignment = TaskBarAlignment.Right;
                break;

            default:
                throw new ArgumentOutOfRangeException("Couldn't retrieve location of taskbar.");
            }

            return(new TaskBarInfo()
            {
                Position = position, Alignment = alignment
            });
        }
Example #7
0
        protected void Reposition(int width = 0)
        {
            if (this.IsRepositioning || !this.IsRegistered)
            {
                return;
            }

            try
            {
                this.IsRepositioning = true;

                if (width == 0)
                {
                    width = this.Width;
                }

                var workingArea = Screen.FromControl(this).Bounds;
                var edge        = (this.Location.X < workingArea.Width / 2 ? ABEdge.ABE_LEFT : ABEdge.ABE_RIGHT);
                var abd         = new NativeMethods.APPBARDATA();
                abd.cbSize    = Marshal.SizeOf(abd);
                abd.hWnd      = Handle;
                abd.uEdge     = (int)edge;
                abd.rc.top    = workingArea.Top;
                abd.rc.bottom = workingArea.Height;

                if (edge == ABEdge.ABE_LEFT)
                {
                    abd.rc.left  = workingArea.Left;
                    abd.rc.right = workingArea.Left + width;
                }
                else
                {
                    abd.rc.right = workingArea.Right;
                    abd.rc.left  = workingArea.Right - width;
                }

                NativeMethods.SHAppBarMessage((int)ABMsg.ABM_QUERYPOS, ref abd);
                if (edge == ABEdge.ABE_LEFT)
                {
                    abd.rc.right = abd.rc.left + width;
                }
                NativeMethods.SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref abd);
                this.Bounds = new Rectangle(abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top);
            }
            finally
            {
                this.IsRepositioning = false;
            }
        }
Example #8
0
        public static void SetWinTaskbarState(WinTaskbarState state)
        {
            NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA();
            abd.cbSize = (int)Marshal.SizeOf(typeof(NativeMethods.APPBARDATA));
            abd.hWnd   = NativeMethods.FindWindow("Shell_TrayWnd");

            if (NotificationArea.Instance.Handle != null && NotificationArea.Instance.Handle != IntPtr.Zero)
            {
                while (abd.hWnd == NotificationArea.Instance.Handle)
                {
                    abd.hWnd = NativeMethods.FindWindowEx(IntPtr.Zero, abd.hWnd, "Shell_TrayWnd", "");
                }
            }

            abd.lParam = (IntPtr)state;
            NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_SETSTATE, ref abd);
        }
Example #9
0
            public AppBarNativeWindow(int barHeight, bool topBar)
            {
                this.height = barHeight;
                visible     = false;
                isTopMost   = false;
                edge        = topBar ? NativeMethods.ABE.ABE_TOP : NativeMethods.ABE.ABE_BOTTOM;

                this.CreateHandle(new CreateParams {
                    Parent = NativeMethods.HWND_MESSAGE, ClassName = "Message"
                });

                callbackMessageNum = NativeMethods.WM_USER + count++;

                // register as AppBar
                var appBarData = new NativeMethods.APPBARDATA(this.Handle, callbackMessageNum);

                NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_NEW, ref appBarData);
            }
Example #10
0
        internal static void ShowHideWindowsTaskbar(bool showWindowsTaskbar)
        {
            var appBarData = new NativeMethods.APPBARDATA(SystemAndProcessInformation.taskbarHandle);
            var state      = (NativeMethods.ABS)(uint) NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_GETSTATE, ref appBarData);

            appBarData.lParam = (IntPtr)(showWindowsTaskbar ? state & ~NativeMethods.ABS.ABS_AUTOHIDE : state | NativeMethods.ABS.ABS_AUTOHIDE);
            NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_SETSTATE, ref appBarData);

            var showHide = showWindowsTaskbar ? NativeMethods.SW.SW_SHOWNA : NativeMethods.SW.SW_HIDE;

            NativeMethods.ShowWindow(SystemAndProcessInformation.taskbarHandle, showHide);
            if (SystemAndProcessInformation.isAtLeastVista)
            {
                NativeMethods.ShowWindow(SystemAndProcessInformation.startButtonHandle, showHide);
            }

            isWindowsTaskbarShown = showWindowsTaskbar;
        }
Example #11
0
            public bool SetPosition(Monitor monitor)
            {
                this.monitor = monitor;

                var appBarData = new NativeMethods.APPBARDATA(this.Handle, uEdge: edge, rc: new NativeMethods.RECT {
                    left = monitor.Bounds.Left, right = monitor.Bounds.Right
                });

                if (edge == NativeMethods.ABE.ABE_TOP)
                {
                    appBarData.rc.top    = monitor.Bounds.Top;
                    appBarData.rc.bottom = appBarData.rc.top + this.height;
                }
                else
                {
                    appBarData.rc.bottom = monitor.Bounds.Bottom;
                    appBarData.rc.top    = appBarData.rc.bottom - this.height;
                }

                NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_QUERYPOS, ref appBarData);

                if (edge == NativeMethods.ABE.ABE_TOP)
                {
                    appBarData.rc.bottom = appBarData.rc.top + this.height;
                }
                else
                {
                    appBarData.rc.top = appBarData.rc.bottom - this.height;
                }

                NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_SETPOS, ref appBarData);

                var changedPosition = appBarData.rc.bottom != rect.bottom || appBarData.rc.top != rect.top ||
                                      appBarData.rc.left != rect.left || appBarData.rc.right != rect.right;

                this.rect = appBarData.rc;

                this.visible = true;

                return(changedPosition);
            }
Example #12
0
        private void RegisterOrUnregisterBar(bool register)
        {
            if (this.IsRegistering)
            {
                return;
            }

            try
            {
                this.IsRegistering = true;

                var abd = new NativeMethods.APPBARDATA();
                abd.cbSize = Marshal.SizeOf(abd);
                abd.hWnd   = Handle;

                if (register == this.IsRegistered)
                {
                    return;
                }
                else if (register)
                {
                    abd.uCallbackMessage = this.callBackId;
                    NativeMethods.SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd);
                    this.IsRegistered = true;

                    this.Reposition();
                }
                else
                {
                    NativeMethods.SHAppBarMessage((int)ABMsg.ABM_REMOVE, ref abd);
                    this.IsRegistered = false;
                }
            }
            finally
            {
                this.IsRegistering = false;
            }
        }
Example #13
0
        //This file is from before r416
        public static int RegisterBar(IntPtr handle, Size size)
        {
            NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA();
            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd   = handle;
            if (!isBarRegistered)
            {
                uCallBack            = NativeMethods.RegisterWindowMessage("AppBarMessage" + Guid.NewGuid().ToString());
                abd.uCallbackMessage = uCallBack;

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

                ABSetPos(handle, size);
            }
            else
            {
                NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_REMOVE, ref abd);
                isBarRegistered = false;
            }

            return(uCallBack);
        }
Example #14
0
        private static void InvalidateInternal()
        {
            _handle = Interop.FindWindow("Shell_TrayWnd", null);

            var data = new NativeMethods.APPBARDATA(_handle);

            Interop.SHAppBarMessage(NativeMethods.ShellMessages.ABM_GETTASKBARPOS, ref data);

            _position = (TaskbarPosition)data.uEdge;
            _left     = data.rc.left;
            _top      = data.rc.top;
            _right    = data.rc.right;
            _bottom   = data.rc.bottom;

            data = new NativeMethods.APPBARDATA(_handle);

            var state = (NativeMethods.TaskbarState)Interop.SHAppBarMessage(NativeMethods.ShellMessages.ABM_GETSTATE, ref data).ToInt32();

            _alwaysOnTop = state == NativeMethods.TaskbarState.ABS_ALWAYSONTOP || Windows.IsWindows7OrHigher;
            _autoHide    = state == NativeMethods.TaskbarState.ABS_AUTOHIDE;

            _isCacheValid = true;
        }
Example #15
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);
        }
Example #16
0
            public void Hide()
            {
                var appBarData = new NativeMethods.APPBARDATA(this.Handle, uEdge: NativeMethods.ABE.ABE_TOP);

                NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_QUERYPOS, ref appBarData);
                NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_SETPOS, ref appBarData);

                this.visible = false;
            }
        /// <summary>
        /// Retrieves taskbar position and alignment.
        /// </summary>
        /// <returns>Taskbar position and alignment.</returns>
        public static TaskBarInfo GetTaskBarInfo()
        {
            // allocate appbardata structure
            NativeMethods.APPBARDATA abdata = new NativeMethods.APPBARDATA() { hWnd = IntPtr.Zero };
            abdata.cbSize = (uint)Marshal.SizeOf(abdata);

            // get task bar info
            IntPtr result = NativeMethods.SHAppBarMessage(NativeMethods.ABMsg.ABM_GETTASKBARPOS, ref abdata);

            // return null if the call failed
            if (result == IntPtr.Zero)
                throw new Exception("Could not retrieve taskbar information.");

            Rect position = abdata.rc;

            TaskBarAlignment alignment;

            switch (abdata.uEdge)
            {
                case NativeMethods.ABEdge.ABE_BOTTOM:
                    alignment = TaskBarAlignment.Bottom;
                    break;
                case NativeMethods.ABEdge.ABE_TOP:
                    alignment = TaskBarAlignment.Top;
                    break;
                case NativeMethods.ABEdge.ABE_LEFT:
                    alignment = TaskBarAlignment.Left;
                    break;
                case NativeMethods.ABEdge.ABE_RIGHT:
                    alignment = TaskBarAlignment.Right;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("Couldn't retrieve location of taskbar.");
            }

            return new TaskBarInfo() { Position = position, Alignment = alignment };
        }
Example #18
0
 public static extern IntPtr SHAppBarMessage([MarshalAs(UnmanagedType.U4)] NativeMethods.ShellMessages dwMessage, ref NativeMethods.APPBARDATA pData);
Example #19
0
        protected void Reposition(int width=0)
        {
            if (this.IsRepositioning || !this.IsRegistered)
                return;

            try
            {
                this.IsRepositioning = true;

                if (width == 0)
                    width = this.Width;

                var workingArea = Screen.FromControl(this).Bounds;
                var edge = (this.Location.X < workingArea.Width / 2 ? ABEdge.ABE_LEFT : ABEdge.ABE_RIGHT);
                var abd = new NativeMethods.APPBARDATA();
                abd.cbSize = Marshal.SizeOf(abd);
                abd.hWnd = Handle;
                abd.uEdge = (int)edge;
                abd.rc.top = workingArea.Top;
                abd.rc.bottom = workingArea.Height;

                if (edge == ABEdge.ABE_LEFT)
                {
                    abd.rc.left = workingArea.Left;
                    abd.rc.right = workingArea.Left + width;
                }
                else
                {
                    abd.rc.right = workingArea.Right;
                    abd.rc.left = workingArea.Right - width;
                }

                NativeMethods.SHAppBarMessage((int)ABMsg.ABM_QUERYPOS, ref abd);
                if (edge == ABEdge.ABE_LEFT)
                {
                    abd.rc.right = abd.rc.left + width;
                }
                NativeMethods.SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref abd);
                this.Bounds = new Rectangle(abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top);
            }
            finally
            {
                this.IsRepositioning = false;
            }
        }
Example #20
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);
            }
        }
Example #21
0
        public static void ABSetPos(IntPtr handle, Size size)
        {
            NativeMethods.APPBARDATA abd = new NativeMethods.APPBARDATA();
            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd   = handle;
            abd.uEdge  = (int)NativeMethods.ABEdge.ABE_TOP;

            if (abd.uEdge == (int)NativeMethods.ABEdge.ABE_LEFT || abd.uEdge == (int)NativeMethods.ABEdge.ABE_RIGHT)
            {
                abd.rc.top    = 0;
                abd.rc.bottom = PrimaryMonitorSize.Height;
                if (abd.uEdge == (int)NativeMethods.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)NativeMethods.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)NativeMethods.ABEdge.ABE_LEFT:
                abd.rc.right = abd.rc.left + size.Width;
                break;

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

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

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

            NativeMethods.SHAppBarMessage((int)NativeMethods.ABMsg.ABM_SETPOS, ref abd);
            Trace.WriteLineIf(abd.uEdge == (int)NativeMethods.ABEdge.ABE_TOP, "*** TOP EDGE - CX 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);
        }
Example #22
0
        private void RegisterOrUnregisterBar(bool register)
        {
            if (this.IsRegistering)
                return;

            try
            {
                this.IsRegistering = true;

                var abd = new NativeMethods.APPBARDATA();
                abd.cbSize = Marshal.SizeOf(abd);
                abd.hWnd = Handle;

                if (register == this.IsRegistered)
                {
                    return;
                }
                else if (register)
                {
                    abd.uCallbackMessage = this.callBackId;
                    NativeMethods.SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd);
                    this.IsRegistered = true;

                    this.Reposition();
                }
                else
                {
                    NativeMethods.SHAppBarMessage((int)ABMsg.ABM_REMOVE, ref abd);
                    this.IsRegistered = false;
                }
            }
            finally
            {
                this.IsRegistering = false;
            }
        }
Example #23
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);
            }
        }
Example #24
0
            public AppBarNativeWindow(int barHeight, bool topBar)
            {
                this.height = barHeight;
                visible = false;
                isTopMost = false;
                edge = topBar ? NativeMethods.ABE.ABE_TOP : NativeMethods.ABE.ABE_BOTTOM;

                this.CreateHandle(new CreateParams { Parent = NativeMethods.HWND_MESSAGE, ClassName = "Message" });

                callbackMessageNum = NativeMethods.WM_USER + count++;

                // register as AppBar
                var appBarData = new NativeMethods.APPBARDATA(this.Handle, callbackMessageNum);

                NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_NEW, ref appBarData);
            }
Example #25
0
            public void Destroy()
            {
                // unregister as AppBar
                var appBarData = new NativeMethods.APPBARDATA(this.Handle);

                NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_REMOVE, ref appBarData);

                DestroyHandle();
            }
Example #26
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);
                }
            }
        }
Example #27
0
        public static TaskbarLocation Detect()
        {
            var abd = new NativeMethods.APPBARDATA();

            abd.cbSize = Marshal.SizeOf(abd);

            Win32.NativeMethods.SHAppBarMessage(Win32.NativeMethods.ABM_GETTASKBARPOS, ref abd);

            var taskbar = (Rectangle)abd.rc;

            var p = new Point(
                abd.rc.left + (abd.rc.right - abd.rc.left) / 2,
                abd.rc.top + (abd.rc.bottom - abd.rc.top) / 2
                );

            var workArea = Screen.GetWorkingArea(p);

            // Windows 7 reports the work area as including the taskbar, but we need
            // it exclusing the taskbar. Correct.

            if (workArea.Contains(p))
            {
                var pMon = new Point(
                    workArea.Left + workArea.Width / 2,
                    workArea.Top + workArea.Height / 2
                    );

                // Whether the taskbar is horizontal or vertical.

                if ((abd.rc.right - abd.rc.left) > (abd.rc.bottom - abd.rc.top))
                {
                    // Whether the baskbar is at the top or the bottom.

                    if (p.Y < pMon.Y)
                    {
                        workArea = new Rectangle(
                            workArea.Left, abd.rc.bottom,
                            workArea.Width, workArea.Bottom - abd.rc.bottom
                            );
                    }
                    else
                    {
                        workArea = new Rectangle(
                            workArea.Left, workArea.Top,
                            workArea.Width, abd.rc.top
                            );
                    }
                }
                else
                {
                    // Whether the taskbar is at the left or right.

                    if (p.X < pMon.X)
                    {
                        workArea = new Rectangle(
                            abd.rc.right, workArea.Top,
                            workArea.Right - abd.rc.right, workArea.Height
                            );
                    }
                    else
                    {
                        workArea = new Rectangle(
                            workArea.Left, abd.rc.left,
                            workArea.Top, workArea.Height
                            );
                    }
                }
            }

            var pBar = new Point(
                taskbar.Left + taskbar.Width / 2,
                taskbar.Top + taskbar.Height / 2
                );

            TaskbarLocationEdge edge;

            if (pBar.X > workArea.Right)
            {
                edge = TaskbarLocationEdge.Right;
            }
            else if (pBar.X < workArea.Left)
            {
                edge = TaskbarLocationEdge.Left;
            }
            else if (pBar.Y > workArea.Bottom)
            {
                edge = TaskbarLocationEdge.Bottom;
            }
            else if (pBar.Y < workArea.Top)
            {
                edge = TaskbarLocationEdge.Top;
            }
            else
            {
                edge = TaskbarLocationEdge.Bottom;
            }

            return(new TaskbarLocation(taskbar, workArea, edge));
        }
Example #28
0
        internal static void ShowHideWindowsTaskbar(bool showWindowsTaskbar)
        {
            var appBarData = new NativeMethods.APPBARDATA(SystemAndProcessInformation.taskbarHandle);
            var state = (NativeMethods.ABS) (uint) NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_GETSTATE, ref appBarData);

            appBarData.lParam = (IntPtr) (showWindowsTaskbar ? state & ~NativeMethods.ABS.ABS_AUTOHIDE : state | NativeMethods.ABS.ABS_AUTOHIDE);
            NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_SETSTATE, ref appBarData);

            var showHide = showWindowsTaskbar ? NativeMethods.SW.SW_SHOWNA : NativeMethods.SW.SW_HIDE;

            NativeMethods.ShowWindow(SystemAndProcessInformation.taskbarHandle, showHide);
            if (SystemAndProcessInformation.isAtLeastVista)
            {
                NativeMethods.ShowWindow(SystemAndProcessInformation.startButtonHandle, showHide);
            }

            isWindowsTaskbarShown = showWindowsTaskbar;
        }
Example #29
0
        internal static IntPtr SHAppBarMessage(NativeMethods.ShellMessages dwMessage, ref NativeMethods.APPBARDATA pData)
        {
            Contract.Ensures(dwMessage != NativeMethods.ShellMessages.ABM_GETTASKBARPOS || Contract.Result <IntPtr>() != IntPtr.Zero);

            var result = UnsafeNativeMethods.SHAppBarMessage(dwMessage, ref pData);

            ThrowInvalidOperationException(dwMessage == NativeMethods.ShellMessages.ABM_GETTASKBARPOS && result == IntPtr.Zero);
            return(result);
        }
Example #30
0
            public bool SetPosition(Monitor monitor)
            {
                this.monitor = monitor;

                var appBarData = new NativeMethods.APPBARDATA(this.Handle, uEdge: edge, rc: new NativeMethods.RECT { left = monitor.Bounds.Left, right = monitor.Bounds.Right });

                if (edge == NativeMethods.ABE.ABE_TOP)
                {
                    appBarData.rc.top = monitor.Bounds.Top;
                    appBarData.rc.bottom = appBarData.rc.top + this.height;
                }
                else
                {
                    appBarData.rc.bottom = monitor.Bounds.Bottom;
                    appBarData.rc.top = appBarData.rc.bottom - this.height;
                }

                NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_QUERYPOS, ref appBarData);

                if (edge == NativeMethods.ABE.ABE_TOP)
                {
                    appBarData.rc.bottom = appBarData.rc.top + this.height;
                }
                else
                {
                    appBarData.rc.top = appBarData.rc.bottom - this.height;
                }

                NativeMethods.SHAppBarMessage(NativeMethods.ABM.ABM_SETPOS, ref appBarData);

                var changedPosition = appBarData.rc.bottom != rect.bottom || appBarData.rc.top != rect.top ||
                    appBarData.rc.left != rect.left || appBarData.rc.right != rect.right;

                this.rect = appBarData.rc;

                this.visible = true;

                return changedPosition;
            }
Example #31
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);
                }
            }
        }