示例#1
0
        void Place_EndOfTaskbar(Rectangle taskbarRect)
        {
            // TODO: Implement Secondary Taskbar
            if (!Taskbar.IsPrimary)
            {
                Place_RightOfTaskButtons(taskbarRect);
                return;
            }

            IntPtr btnsHwnd = TaskbarUtils.GetPrimaryTaskButtonsHwnd(Taskbar.Handle);
            IntPtr trayHwnd = TaskbarUtils.GetPrimaryTaskTrayNotifyHwnd(Taskbar.Handle);

            int w = TargetSize.Width;

            // shrink the task bar buttons area
            if (NativeImports.GetWindowRect(btnsHwnd, out NativeImports.RECT btnsRect))
            {
                NativeImports.SetWindowPos(btnsHwnd, IntPtr.Zero, 0, 0, (btnsRect.Right - btnsRect.Left) - w, btnsRect.Bottom - btnsRect.Top, NativeImports.SetWindowPosFlags.SWP_NOMOVE | NativeImports.SetWindowPosFlags.SWP_NOREPOSITION);
            }

            // enlarge and move the tray area to the left
            if (NativeImports.GetWindowRect(trayHwnd, out NativeImports.RECT trayRect))
            {
                Rectangle clientRect = new Rectangle(trayRect.Left - taskbarRect.X, trayRect.Top - taskbarRect.Top, trayRect.Right - trayRect.Left, trayRect.Bottom - trayRect.Top);
                NativeImports.SetWindowPos(trayHwnd, IntPtr.Zero, clientRect.Left - w, clientRect.Top, clientRect.Width + w, clientRect.Height, NativeImports.SetWindowPosFlags.SWP_NOREPOSITION);

                ActualSize = new Size(TargetSize.Width, taskbarRect.Height);
                NativeImports.SetWindowLong(Handle, NativeImports.GWL_STYLE, NativeImports.GetWindowLong(Handle, NativeImports.GWL_STYLE) | NativeImports.WS_CHILD);
                NativeImports.SetParent(Handle, trayHwnd);
                NativeImports.SetWindowPos(Handle, IntPtr.Zero, clientRect.Width, 0, ActualSize.Width, ActualSize.Height, NativeImports.SetWindowPosFlags.SWP_NOREPOSITION);
            }

            // Listen for changes of the tray area
            Taskbar.RegisterObservableChild(trayHwnd);
        }
示例#2
0
        void Place_BetweenTrayAndClock(Rectangle taskbarRect)
        {
            if (!Taskbar.IsPrimary)
            {
                // there is no tray area on secondary taskbars
                // place normally
                Place_RightOfTaskButtons(taskbarRect);
                return;
            }

            IntPtr btnsHwnd = TaskbarUtils.GetPrimaryTaskButtonsHwnd(Taskbar.Handle);
            IntPtr trayHwnd = TaskbarUtils.GetPrimaryTaskTrayNotifyHwnd(Taskbar.Handle);

            int w = TargetSize.Width;

            // shrink the task bar buttons area
            if (NativeImports.GetWindowRect(btnsHwnd, out NativeImports.RECT btnsRect))
            {
                NativeImports.SetWindowPos(btnsHwnd, IntPtr.Zero, 0, 0, (btnsRect.Right - btnsRect.Left) - w, btnsRect.Bottom - btnsRect.Top, NativeImports.SetWindowPosFlags.SWP_NOMOVE | NativeImports.SetWindowPosFlags.SWP_NOREPOSITION);
            }

            // enlarge and move the tray area to the left
            if (NativeImports.GetWindowRect(trayHwnd, out NativeImports.RECT trayRect))
            {
                Rectangle clientRect = new Rectangle(trayRect.Left - taskbarRect.X, trayRect.Top - taskbarRect.Top, trayRect.Right - trayRect.Left, trayRect.Bottom - trayRect.Top);
                NativeImports.SetWindowPos(trayHwnd, IntPtr.Zero, clientRect.Left - w, clientRect.Top, clientRect.Width + w, clientRect.Height, NativeImports.SetWindowPosFlags.SWP_NOREPOSITION);
                // adjust
                trayRect.Left -= w;

                // move clock and other elements to the right
                var elements = TaskbarUtils.GetPrimaryTaskTrayElementsRightOfIcons(Taskbar.Handle);
                int initialX = -1;
                foreach (var elWnd in elements)
                {
                    if (NativeImports.GetWindowRect(elWnd, out NativeImports.RECT elementRect))
                    {
                        Rectangle elementClientRect = new Rectangle(elementRect.Left - trayRect.Left, elementRect.Top - trayRect.Top, elementRect.Right - elementRect.Left, elementRect.Bottom - elementRect.Top);
                        if (initialX == -1)
                        {
                            initialX = elementClientRect.X;
                        }

                        NativeImports.SetWindowPos(elWnd, IntPtr.Zero, elementClientRect.X + w, elementClientRect.Y, elementClientRect.Width, elementClientRect.Height, 0);
                    }
                }

                // place TaskbarWindow between icons and clock
                ActualSize = new Size(TargetSize.Width, clientRect.Height);
                NativeImports.SetWindowLong(Handle, NativeImports.GWL_STYLE, NativeImports.GetWindowLong(Handle, NativeImports.GWL_STYLE) | NativeImports.WS_CHILD);
                NativeImports.SetParent(Handle, trayHwnd);
                NativeImports.SetWindowPos(Handle, IntPtr.Zero, initialX, clientRect.Y, ActualSize.Width, ActualSize.Height, NativeImports.SetWindowPosFlags.SWP_NOREPOSITION);

                // listen for size changes of the tray area
                Taskbar.RegisterObservableChild(trayHwnd);
            }
        }
示例#3
0
        void Place_RightOfTaskButtons(Rectangle taskbarRect)
        {
            // place into the button bar
            // Set this window as child of the taskbar's button bar
            IntPtr btnsHwnd;

            if (Taskbar.IsPrimary)
            {
                btnsHwnd = TaskbarUtils.GetPrimaryTaskButtonsHwnd(Taskbar.Handle);
            }
            else
            {
                btnsHwnd = TaskbarUtils.GetSecondaryTaskButtonsHwnd(Taskbar.Handle);
            }

            NativeImports.SetWindowLong(Handle, NativeImports.GWL_STYLE, NativeImports.GetWindowLong(Handle, NativeImports.GWL_STYLE) | NativeImports.WS_CHILD);
            NativeImports.SetParent(Handle, btnsHwnd);

            // get the size of the button bar to place the window
            var taskBtnRect = WindowUtils.GetWindowBounds(btnsHwnd);

            switch (Taskbar.DockPosition)
            {
            case TaskbarDockPosition.Top:
            case TaskbarDockPosition.Bottom:
                ActualSize = new Size(TargetSize.Width, taskbarRect.Height);
                // place the component at the far right
                // we use SetWindowPos since setting Left and Top does not seem to work correctly
                NativeImports.SetWindowPos(Handle, IntPtr.Zero, taskBtnRect.Width - TargetSize.Width, 0, ActualSize.Width, ActualSize.Height, 0);
                break;

            case TaskbarDockPosition.Left:
            case TaskbarDockPosition.Right:
                ActualSize = new Size(taskbarRect.Width, TargetSize.Height);

                // place the component at the bottom
                // we use SetWindowPos since setting Left and Top does not seem to work correctly
                NativeImports.SetWindowPos(Handle, IntPtr.Zero, 0, taskBtnRect.Height - TargetSize.Height, ActualSize.Width, ActualSize.Height, 0);
                break;
            }

            // listen for size changes of the button area
            Taskbar.RegisterObservableChild(btnsHwnd);
        }