예제 #1
0
        /// <summary>
        /// Thread watches Taskbar and configures layout of Main button accordingly
        /// </summary>
        private void WatchDesktopBtn()
        {
            double width = -1, height = -1;
            API.RECT r;
            var p = default(Point);
            //Hide start button for Win8.1
            if(Util.OsIs.EightBlueExact)
            {
                API.ShowWindow(_startBtn, API.SWCommands.HIDE);
            }
            while (!ClosedW)
            {
                if (!API.GetWindowRect(_showDesktopBtn, out r))
                {//looks like explorer.exe is dead!
                    Thread.Sleep(10000);//let's wait for explorer to auto-restart
                    var explorers = Process.GetProcessesByName("explorer");
                    if (explorers.Any(e => e.SessionId == MfuList.ProcessSessionId))
                    {//explorer is restarted already?
                        Util.Restart("explorer.exe restarted.");//need reinit handles tree
                    }
                    else
                    {//seems, user killed explorer so hard it is dead to death :)
                        var trd  = Util.Fork(() =>
                        {
                            var dialog = new RestartExplorer();
                            dialog.ShowDialog();
                            if (dialog.DialogResult == System.Windows.Forms.DialogResult.OK)
                            {
                                Util.StartExplorer();
                                Thread.Sleep(2000);
                                Util.Restart("user have chosen to restart.");
                            }
                            else
                                Util.Die("no user-action was to restore normal workflow...");
                        }, "Restart explorer window");
                        trd.SetApartmentState(ApartmentState.STA);
                        trd.Start();
                        trd.Join();
                    }
                }
                //The success way
                //Size the button by ShowDesktop buton
                var curHeight = (r.Bottom - r.Top)/SystemScale;
                var curWidth = (r.Right - r.Left)/SystemScale;
                API.RECT rTaskBar;
                API.GetWindowRect(_taskBar, out rTaskBar); //correcty identify the taskbar location
                bool taskBarVertical = rTaskBar.Bottom - rTaskBar.Top /*height*/ >
                                       rTaskBar.Right - rTaskBar.Left /*width*/;

                if (SettingsManager.Instance.SquareStartButton)
                {//Apply user size modification
                    var sizeCoef = SettingsManager.GetARModifier(!taskBarVertical);
                    if (curHeight > curWidth) //vertical button, horiz. bar
                        curWidth = (int)(curHeight * sizeCoef);
                    else                      //horiz. button, vertical bar
                        curHeight = (int)(curWidth / sizeCoef);
                }
                //A kind of "Minimum size" for Win8.1
                if (Util.OsIs.EightBlueExact)
                {
                    const float w8DefShDsktpWdt = 15f;
                    curWidth = Math.Max(curWidth, w8DefShDsktpWdt);
                    curHeight = Math.Max(curHeight, w8DefShDsktpWdt);
                }
            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(width) != Math.Round(curWidth))
                {
                    width = curWidth;
                    Dispatcher.Invoke(new Action(() =>  b1.Width = curWidth));
                }
                if (Math.Round(height) != Math.Round(curHeight))
                {
                    height = curHeight;
                    Dispatcher.Invoke(new Action(() =>  b1.Height = curHeight));
                }
            // ReSharper restore CompareOfFloatsByEqualityOperator

                //Check if the Main Button location changed within screen
                if (BtnStck.IsInstantited && ((int)p.Y != r.Top || (int)p.X != r.Left))
                {
                    p.Y = r.Top;
                    p.X = r.Left;
                    if (taskBarVertical)
                    {
                        BtnStck.Instance.IsWindowAtTopOfScreen = true;
                    }
                    else //only 25% but that's defaults...
                    {
                        var activeScreen = Screen.FromPoint(new System.Drawing.Point(r.Left, r.Top));
                        BtnStck.Instance.IsWindowAtTopOfScreen = (double)activeScreen.Bounds.Height/2 > r.Top;
                    }
                }

                //If required, apply move to taskbar rebar
                if (Util.OsIs.EightFamily || (SettingsManager.Instance.SquareStartButton && Util.OsIs.SevenOrMore))
                    MoveReBar(taskBarVertical, (int) (curHeight*SystemScale), (int) (curWidth*SystemScale));

                Thread.Sleep(100*(_setParent ? 1 : 2));
                if (!_setParent)
                    Util.Send(() => SetParent(this.GetHandle()));
            }
            //restoring taskbar on exit
            if (Util.OsIs.EightFamily && API.GetWindowRect(_showDesktopBtn, out r))
            {//free space to the left/up is the same as in right/down, which is show desktop btn
                var curHeight = r.Bottom - r.Top;
                var curWidth = r.Right - r.Left;
                bool isVertical = curHeight < curWidth;
                //For Win8.1 we still determine isVertical by ShowDesktop, but position is determined by Start button
                if(Util.OsIs.EightBlueExact && API.GetWindowRect(_startBtn, out r))
                {
                    curHeight = r.Bottom - r.Top;
                    curWidth = r.Right - r.Left;
                }
                MoveReBar(isVertical, curHeight, curWidth);
            }
            //Restoring start button for win 8.1
            if (Util.OsIs.EightBlueExact)
            {
                API.ShowWindow(_startBtn, API.SWCommands.SHOW);
            }
        }
예제 #2
0
        /// <summary>
        /// Thread watches Taskbar and configures layout of Main button accordingly
        /// </summary>
        private void WatchDesktopBtn()
        {
            double width = -1, height = -1;

            API.RECT r;
            var      p = default(Point);

            //Hide start button for Win8.1
            if (Util.OsIs.EightBlueExact)
            {
                API.ShowWindow(_startBtn, API.SWCommands.HIDE);
            }
            while (!ClosedW)
            {
                if (!API.GetWindowRect(_showDesktopBtn, out r))
                {                        //looks like explorer.exe is dead!
                    Thread.Sleep(10000); //let's wait for explorer to auto-restart
                    var explorers = Process.GetProcessesByName("explorer");
                    if (explorers.Any(e => e.SessionId == MfuList.ProcessSessionId))
                    {                                            //explorer is restarted already?
                        Util.Restart("explorer.exe restarted."); //need reinit handles tree
                    }
                    else
                    {//seems, user killed explorer so hard it is dead to death :)
                        var trd = Util.Fork(() =>
                        {
                            var dialog = new RestartExplorer();
                            dialog.ShowDialog();
                            if (dialog.DialogResult == System.Windows.Forms.DialogResult.OK)
                            {
                                Util.StartExplorer();
                                Thread.Sleep(2000);
                                Util.Restart("user have chosen to restart.");
                            }
                            else
                            {
                                Util.Die("no user-action was to restore normal workflow...");
                            }
                        }, "Restart explorer window");
                        trd.SetApartmentState(ApartmentState.STA);
                        trd.Start();
                        trd.Join();
                    }
                }
                //The success way
                //Size the button by ShowDesktop buton
                var      curHeight = (r.Bottom - r.Top) / SystemScale;
                var      curWidth  = (r.Right - r.Left) / SystemScale;
                API.RECT rTaskBar;
                API.GetWindowRect(_taskBar, out rTaskBar); //correcty identify the taskbar location
                bool taskBarVertical = rTaskBar.Bottom - rTaskBar.Top /*height*/ >
                                       rTaskBar.Right - rTaskBar.Left /*width*/;

                if (SettingsManager.Instance.SquareStartButton)
                {                             //Apply user size modification
                    var sizeCoef = SettingsManager.GetARModifier(!taskBarVertical);
                    if (curHeight > curWidth) //vertical button, horiz. bar
                    {
                        curWidth = (int)(curHeight * sizeCoef);
                    }
                    else                      //horiz. button, vertical bar
                    {
                        curHeight = (int)(curWidth / sizeCoef);
                    }
                }
                //A kind of "Minimum size" for Win8.1
                if (Util.OsIs.EightBlueExact)
                {
                    const float w8DefShDsktpWdt = 15f;
                    curWidth  = Math.Max(curWidth, w8DefShDsktpWdt);
                    curHeight = Math.Max(curHeight, w8DefShDsktpWdt);
                }
// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(width) != Math.Round(curWidth))
                {
                    width = curWidth;
                    Dispatcher.Invoke(new Action(() => b1.Width = curWidth));
                }
                if (Math.Round(height) != Math.Round(curHeight))
                {
                    height = curHeight;
                    Dispatcher.Invoke(new Action(() => b1.Height = curHeight));
                }
// ReSharper restore CompareOfFloatsByEqualityOperator

                //Check if the Main Button location changed within screen
                if (BtnStck.IsInstantited && ((int)p.Y != r.Top || (int)p.X != r.Left))
                {
                    p.Y = r.Top;
                    p.X = r.Left;
                    if (taskBarVertical)
                    {
                        BtnStck.Instance.IsWindowAtTopOfScreen = true;
                    }
                    else //only 25% but that's defaults...
                    {
                        var activeScreen = Screen.FromPoint(new System.Drawing.Point(r.Left, r.Top));
                        BtnStck.Instance.IsWindowAtTopOfScreen = (double)activeScreen.Bounds.Height / 2 > r.Top;
                    }
                }

                //If required, apply move to taskbar rebar
                if (Util.OsIs.EightFamily || (SettingsManager.Instance.SquareStartButton && Util.OsIs.SevenOrMore))
                {
                    MoveReBar(taskBarVertical, (int)(curHeight * SystemScale), (int)(curWidth * SystemScale));
                }

                Thread.Sleep(100 * (_setParent ? 1 : 2));
                if (!_setParent)
                {
                    Util.Send(() => SetParent(this.GetHandle()));
                }
            }
            //restoring taskbar on exit
            if (Util.OsIs.EightFamily && API.GetWindowRect(_showDesktopBtn, out r))
            {//free space to the left/up is the same as in right/down, which is show desktop btn
                var  curHeight  = r.Bottom - r.Top;
                var  curWidth   = r.Right - r.Left;
                bool isVertical = curHeight < curWidth;
                //For Win8.1 we still determine isVertical by ShowDesktop, but position is determined by Start button
                if (Util.OsIs.EightBlueExact && API.GetWindowRect(_startBtn, out r))
                {
                    curHeight = r.Bottom - r.Top;
                    curWidth  = r.Right - r.Left;
                }
                MoveReBar(isVertical, curHeight, curWidth);
            }
            //Restoring start button for win 8.1
            if (Util.OsIs.EightBlueExact)
            {
                API.ShowWindow(_startBtn, API.SWCommands.SHOW);
            }
        }