Example #1
0
        public static TaskbarState GetWinTaskbarState()
        {
            TaskbarState retState = new TaskbarState();
            var          hwnd     = User32.FindWindow(ClassName, null);

            User32.GetWindowRect(hwnd, out retState.TaskbarSize);

            var screen = Screen.AllScreens.FirstOrDefault(x => x.Bounds.Contains(
                                                              new Rectangle(
                                                                  retState.TaskbarSize.left,
                                                                  retState.TaskbarSize.top,
                                                                  retState.TaskbarSize.right - retState.TaskbarSize.left,
                                                                  retState.TaskbarSize.bottom - retState.TaskbarSize.top)
                                                              ));

            retState.TaskbarPosition = TaskbarPosition.Bottom;

            if (screen != null)
            {
                if (retState.TaskbarSize.bottom == screen.Bounds.Bottom && retState.TaskbarSize.top == screen.Bounds.Top)
                {
                    retState.TaskbarPosition = (retState.TaskbarSize.left == screen.Bounds.Left) ? TaskbarPosition.Left : TaskbarPosition.Right;
                }
                if (retState.TaskbarSize.right == screen.Bounds.Right && retState.TaskbarSize.left == screen.Bounds.Left)
                {
                    retState.TaskbarPosition = (retState.TaskbarSize.top == screen.Bounds.Top) ? TaskbarPosition.Top : TaskbarPosition.Bottom;
                }
            }

            return(retState);
        }
        public static TaskbarState GetWinTaskbarState()
        {
            APPBARDATA   ABD      = new APPBARDATA();
            TaskbarState retState = new TaskbarState();
            var          hwnd     = User32.FindWindow(ClassName, null);

            ABD.cbSize = Marshal.SizeOf(ABD);
            ABD.uEdge  = 0;
            ABD.hWnd   = hwnd;
            ABD.lParam = 1;

            RECT scaledTaskbarRect;

            User32.GetWindowRect(hwnd, out scaledTaskbarRect);

            var taskbarNonDPIAwareSize = Shell32.SHAppBarMessage((int)ABMsg.ABM_GETTASKBARPOS, ref ABD);

            var scalingAmount = (double)(scaledTaskbarRect.bottom - scaledTaskbarRect.top) / (ABD.rc.bottom - ABD.rc.top);

            retState.TaskbarSize        = default(RECT);
            retState.TaskbarSize.top    = (int)(ABD.rc.top * scalingAmount);
            retState.TaskbarSize.bottom = (int)(ABD.rc.bottom * scalingAmount);
            retState.TaskbarSize.left   = (int)(ABD.rc.left * scalingAmount);
            retState.TaskbarSize.right  = (int)(ABD.rc.right * scalingAmount);

            var screen = Screen.AllScreens.FirstOrDefault(x => x.Bounds.Contains(
                                                              new Rectangle(
                                                                  retState.TaskbarSize.left,
                                                                  retState.TaskbarSize.top,
                                                                  retState.TaskbarSize.right - retState.TaskbarSize.left,
                                                                  retState.TaskbarSize.bottom - retState.TaskbarSize.top)
                                                              ));

            retState.TaskbarPosition = TaskbarPosition.Bottom;

            if (screen != null)
            {
                if (retState.TaskbarSize.bottom == screen.Bounds.Bottom && retState.TaskbarSize.top == screen.Bounds.Top)
                {
                    retState.TaskbarPosition = (retState.TaskbarSize.left == screen.Bounds.Left) ? TaskbarPosition.Left : TaskbarPosition.Right;
                }
                if (retState.TaskbarSize.right == screen.Bounds.Right && retState.TaskbarSize.left == screen.Bounds.Left)
                {
                    retState.TaskbarPosition = (retState.TaskbarSize.top == screen.Bounds.Top) ? TaskbarPosition.Top : TaskbarPosition.Bottom;
                }
            }

            return(retState);
        }
Example #3
0
        public static TaskbarState GetWinTaskbarState()
        {
            APPBARDATA   ABD      = new APPBARDATA();
            TaskbarState retState = new TaskbarState();

            ABD.cbSize = Marshal.SizeOf(ABD);
            ABD.uEdge  = 0;
            ABD.hWnd   = User32.FindWindow(ClassName, null);
            ABD.lParam = 1;

            var tsize = Shell32.SHAppBarMessage((int)ABMsg.ABM_GETTASKBARPOS, ref ABD);

            retState.TaskbarSize = ABD.rc;

            var screen = Screen.AllScreens.FirstOrDefault(x => x.Bounds.Contains(
                                                              new Rectangle(
                                                                  retState.TaskbarSize.left,
                                                                  retState.TaskbarSize.top,
                                                                  retState.TaskbarSize.right - retState.TaskbarSize.left,
                                                                  retState.TaskbarSize.bottom - retState.TaskbarSize.top)
                                                              ));

            retState.TaskbarPosition = TaskbarPosition.Bottom;

            if (screen != null)
            {
                if (retState.TaskbarSize.bottom == screen.Bounds.Bottom && retState.TaskbarSize.top == screen.Bounds.Top)
                {
                    retState.TaskbarPosition = (retState.TaskbarSize.left == screen.Bounds.Left) ? TaskbarPosition.Left : TaskbarPosition.Right;
                }
                if (retState.TaskbarSize.right == screen.Bounds.Right && retState.TaskbarSize.left == screen.Bounds.Left)
                {
                    retState.TaskbarPosition = (retState.TaskbarSize.top == screen.Bounds.Top) ? TaskbarPosition.Top : TaskbarPosition.Bottom;
                }
            }

            return(retState);
        }
        public static TaskbarState GetWinTaskbarState()
        {
            APPBARDATA ABD = new APPBARDATA();
            TaskbarState retState = new TaskbarState();
            var hwnd = User32.FindWindow(ClassName, null);

            ABD.cbSize = Marshal.SizeOf(ABD);
            ABD.uEdge = 0;
            ABD.hWnd = hwnd;
            ABD.lParam = 1;

            RECT scaledTaskbarRect;
            User32.GetWindowRect(hwnd, out scaledTaskbarRect);

            var taskbarNonDPIAwareSize = Shell32.SHAppBarMessage((int)ABMsg.ABM_GETTASKBARPOS, ref ABD);

            var scalingAmount = (double)(scaledTaskbarRect.bottom - scaledTaskbarRect.top) / (ABD.rc.bottom - ABD.rc.top);

            retState.TaskbarSize = default(RECT);
            retState.TaskbarSize.top = (int)(ABD.rc.top * scalingAmount);
            retState.TaskbarSize.bottom = (int)(ABD.rc.bottom * scalingAmount);
            retState.TaskbarSize.left = (int)(ABD.rc.left * scalingAmount);
            retState.TaskbarSize.right = (int)(ABD.rc.right * scalingAmount);

            var screen = Screen.AllScreens.FirstOrDefault(x => x.Bounds.Contains(
                            new Rectangle(
                                retState.TaskbarSize.left,
                                retState.TaskbarSize.top,
                                retState.TaskbarSize.right - retState.TaskbarSize.left,
                                retState.TaskbarSize.bottom - retState.TaskbarSize.top)
                         ));

            retState.TaskbarPosition = TaskbarPosition.Bottom;

            if (screen != null)
            {
                if (retState.TaskbarSize.bottom == screen.Bounds.Bottom && retState.TaskbarSize.top == screen.Bounds.Top)
                {
                    retState.TaskbarPosition = (retState.TaskbarSize.left == screen.Bounds.Left) ? TaskbarPosition.Left : TaskbarPosition.Right;
                }
                if (retState.TaskbarSize.right == screen.Bounds.Right && retState.TaskbarSize.left == screen.Bounds.Left)
                {
                    retState.TaskbarPosition = (retState.TaskbarSize.top == screen.Bounds.Top) ? TaskbarPosition.Top : TaskbarPosition.Bottom;
                }
            }

            return retState;
        }