Exemplo n.º 1
0
        public Task SetTaskbarJumpListAsync(IntPtr windowPointer, Dictionary <string, List <TaskbarSiteItem> > additionalJumpListItems)
        {
            var task = Task.Factory.StartNew(new Action(() =>
            {
                Dictionary <string, List <TaskbarSiteItem> > jumpListItems = new Dictionary <string, List <TaskbarSiteItem> >();

                AddStandartJumpList(jumpListItems);


                if (additionalJumpListItems != null && additionalJumpListItems.Count > 0)
                {
                    foreach (var item in additionalJumpListItems)
                    {
                        if (jumpListItems.ContainsKey(item.Key))
                        {
                            jumpListItems[item.Key].AddRange(additionalJumpListItems[item.Key]);
                        }
                        else
                        {
                            jumpListItems.Add(item.Key, item.Value);
                        }
                    }
                }

                TaskbarUtils.SetTaskbarJumpListLink(windowPointer, jumpListItems);
            }));

            task.Start();

            return(task);
        }
Exemplo n.º 2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // create a clock window for each secondary taskbar
            taskbars = TaskbarUtils.ListTaskbars().Where(x => !x.IsPrimary).ToList();

            if (taskbars.Count > 0)
            {
                // add a clock to each secondary taskbar
                var viewModel = new ViewModels.ClockViewModel();
                foreach (var taskbar in taskbars)
                {
                    var f = new ClockWindow(taskbar, viewModel);
                    f.Show();
                }

                // install a win event hook to track taskbar resize/movement
                var hook = WinEventHook.SetHook(WinEventHook.EVENT_OBJECT_LOCATIONCHANGE, WinEventProc);

                Application.ApplicationExit += (s, e) =>
                {
                    WinEventHook.RemoveHook(hook);
                };

                Application.Run();
            }
            else
            {
                MessageBox.Show("SecondaryTaskbarClock", "No secondary taskbars found. Application will terminate.");
            }
        }
Exemplo n.º 3
0
 public void Fail()
 {
     if (!TaskbarUtils.Win7TaskBarNotSupported)
     {
         TaskbarUtils.SetProgressState(Handle, TaskbarUtils.ThumbnailProgressState.Error);
     }
 }
Exemplo n.º 4
0
        private static void Main(string[] args)
        {
            try
            {
                TaskbarUtils.Init();

                var connectionChecker = new SqlConnectionChecker(ConnectionString);
                if (!connectionChecker.CheckResult)
                {
                    MessageBox.Show(connectionChecker.ErrorMessage, "Ошибка при проверке подключения к SQL серверу", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    Application.Exit();
                    return;
                }

                else
                {
                    switch (args[0])
                    {
                    case "-u":
                        Application.Run(new UIForm());
                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                string _errorMessage = string.Format("Ошибка. {0}{1}{2}", exception.Message, Environment.NewLine, exception.StackTrace);
                MessageBox.Show("Ошибка запуска приложения:\r\n", _errorMessage);
            }
        }
Exemplo n.º 5
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);
        }
        public List <TaskbarRef> GetTaskBars()
        {
            if (taskbars == null)
            {
                taskbars = TaskbarUtils.ListTaskbars().ToList();
            }

            return(taskbars);
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        private void ClockWindow_MouseClick(object sender, MouseEventArgs e)
        {
            switch (e.Button)
            {
            case MouseButtons.Left:
                // show the calendar flyout next to this clock
                Task.Run(() =>
                {
                    TaskbarUtils.ShowCalendarFlyOut(this.Bounds, Taskbar.DockPosition.GetCorrespondingFlyoutPosition());
                });
                break;

            case MouseButtons.Right:
            {
                // force the popup menu to calculate its height
                popupMenu.SuspendLayout();
                popupMenu.ResumeLayout();

                Point popupLocation;
                // open the context menu, correctly positioned
                // depending on the taskbar location
                switch (Taskbar.DockPosition)
                {
                case TaskbarDockPosition.Top:
                    popupLocation = new Point(this.Bounds.Right - popupMenu.Width, this.Bounds.Bottom);
                    break;

                case TaskbarDockPosition.Left:
                    popupLocation = new Point(this.Bounds.Right, this.Bounds.Bottom - popupMenu.Height);
                    break;

                case TaskbarDockPosition.Right:
                    popupLocation = new Point(this.Bounds.Left - popupMenu.Width, this.Bounds.Bottom - popupMenu.Height);
                    break;

                case TaskbarDockPosition.Bottom:
                default:
                    popupLocation = new Point(this.Bounds.Right - popupMenu.Width, this.Bounds.Top - popupMenu.Height);
                    break;
                }

                popupMenu.Show(popupLocation);
                break;
            }
            }
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Attach this window to the connected taskbar or update the positioning/sizing
        /// after the taskbar size/position has changed
        /// </summary>
        void AttachToTaskbar()
        {
            var taskbarRect = WindowUtils.GetWindowBounds(Taskbar.Handle);

            // 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 clock
            var taskBtnRect = WindowUtils.GetWindowBounds(btnsHwnd);

            switch (Taskbar.DockPosition)
            {
            case TaskbarDockPosition.Top:
            case TaskbarDockPosition.Bottom:
                ActualSize = new Size(TargetSize.Width, taskbarRect.Height);

                // place the clock 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 clock 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;
            }
        }
Exemplo n.º 11
0
        public void WatchDownloadPercentage(IntPtr windowPointer, Task <bool> downloadTask)
        {
            double percent = 0.0;

            while (!downloadTask.IsCanceled && !downloadTask.IsCompleted && !downloadTask.IsFaulted)
            {
                percent = DownloadControl.GetInstance().PercentDownloaded;

                if (percent < 1.0 && !downloadTask.IsCompleted)
                {
                    TaskbarUtils.SetTaskbarItemProgress(windowPointer, TaskbarProgressBarState.Normal, percent);
                }
                else if (!downloadTask.IsCompleted)
                {
                    TaskbarUtils.SetTaskbarItemProgress(windowPointer, TaskbarProgressBarState.Indeterminate, 1.0);
                    break;
                }
            }
        }
        public void RecreateAll()
        {
            taskbars = TaskbarUtils.ListTaskbars().ToList();

            ActivePlacement = Settings.Placement;

            // recreate all windows
            foreach (var w in windows)
            {
                w.RestoreTaskbar();
                w.Close();
            }

            windows.Clear();

            // add the component to each taskbar (primary and secondary)
            foreach (var taskbar in taskbars)
            {
                var f = new WeekWindow(taskbar, Settings, DialogService);
                f.Show();

                Register(f);
            }
        }