コード例 #1
0
        /// <summary>
        /// The AdjustWorkingAreaForAutoHide function defines the working area depending of TaskBar position and AutoHide status
        /// </summary>
        /// <param name="monitorContainingApplication">The monitor that overlaps the window</param>
        /// <param name="mmi">The MINMAXINFO structure of a maximized window</param>
        /// <returns>Returns MINMAXINFO structure for a maximized window</returns>
        private MINMAXINFO AdjustWorkingAreaForAutoHide(IntPtr monitorContainingApplication, MINMAXINFO mmi)
        {
            // Get a handle to the top-level window whose class name and window name match the "Shell_TrayWnd" string
            IntPtr hwnd = FindWindow("Shell_TrayWnd", null);
            if (hwnd == null) return mmi;

            // Get a handle to the monitor that overlaps the window or the nearest
            IntPtr monitorWithTaskbarOnIt = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
            if (!monitorContainingApplication.Equals(monitorWithTaskbarOnIt)) return mmi;

            // Gets the structure with information about a system appbar message
            APPBARDATA abd = new APPBARDATA();
            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd = hwnd;
            // Send an appbar message to the system
            SHAppBarMessage((int)ABMsg.ABM_GETTASKBARPOS, ref abd);
            // Define the AutoHide status of TaskBar
            bool autoHide = System.Convert.ToBoolean(SHAppBarMessage((int)ABMsg.ABM_GETSTATE, ref abd));
            if (!autoHide) return mmi;

            // Get a position of TaskBar
            int uEdge = GetEdge(abd.rc);
            // Get a size of window depending of TaskBar position
            switch (uEdge)
            {
                case (int)ABEdge.ABE_LEFT:
                    mmi.MaxPosition.X += 2;
                    mmi.MaxTrackSize.X -= 2;
                    mmi.MaxSize.X -= 2;
                    break;
                case (int)ABEdge.ABE_RIGHT:
                    mmi.MaxSize.X -= 2;
                    mmi.MaxTrackSize.X -= 2;
                    break;
                case (int)ABEdge.ABE_TOP:
                    mmi.MaxPosition.Y += 2;
                    mmi.MaxTrackSize.Y -= 2;
                    mmi.MaxSize.Y -= 2;
                    break;
                case (int)ABEdge.ABE_BOTTOM:
                    mmi.MaxSize.Y -= 2;
                    mmi.MaxTrackSize.Y -= 2;
                    break;
                default:
                    return mmi;
            }
            return mmi;
        }
コード例 #2
0
ファイル: WindowSize.cs プロジェクト: Displayedd/LineDraw
        private static MINMAXINFO AdjustWorkingAreaForAutoHide(IntPtr monitorContainingApplication, MINMAXINFO mmi)
        {
            IntPtr hwnd = FindWindow("Shell_TrayWnd", null);
            if (hwnd == null)
                return mmi;

            IntPtr monitorWithTaskbarOnIt = MonitorFromWindow(hwnd, MonitorOptions.MONITOR_DEFAULTTONEAREST);
            if (!monitorContainingApplication.Equals(monitorWithTaskbarOnIt))
                return mmi;

            APPBARDATA abd = new APPBARDATA();
            abd.cbSize = Marshal.SizeOf(abd);
            abd.hWnd = hwnd;
            SHAppBarMessage((int)ABMsg.ABM_GETTASKBARPOS, ref abd);
            int uEdge = GetEdge(abd.rc);

            bool autoHide = System.Convert.ToBoolean(SHAppBarMessage((int)ABMsg.ABM_GETSTATE, ref abd));
            if (!autoHide)
                return mmi;

            switch (uEdge)
            {
                case (int)ABEdge.ABE_LEFT:
                    mmi.ptMaxPosition.X += 2;
                    mmi.ptMaxTrackSize.X -= 2;
                    mmi.ptMaxSize.X -= 2;
                    break;
                case (int)ABEdge.ABE_RIGHT:
                    mmi.ptMaxSize.X -= 2;
                    mmi.ptMaxTrackSize.X -= 2;
                    break;
                case (int)ABEdge.ABE_TOP:
                    mmi.ptMaxPosition.Y += 2;
                    mmi.ptMaxTrackSize.Y -= 2;
                    mmi.ptMaxSize.Y -= 2;
                    break;
                case (int)ABEdge.ABE_BOTTOM:
                    mmi.ptMaxSize.Y -= 2;
                    mmi.ptMaxTrackSize.Y -= 2;
                    break;
                default:
                    return mmi;
            }
            return mmi;
        }