Esempio n. 1
0
 public static extern bool    GetWindowPlacement(IntPtr hWnd, out WINDOWPLACEMENT lpwndpl);
Esempio n. 2
0
        /// <summary>
        /// スクリーン内の補正
        /// </summary>
        /// <param name="wp">WINDOWPLACEMENT</param>
        /// <returns>結果(true:補正なし,false:補正あり)</returns>
        public static bool    CheckScreen(ref WINDOWPLACEMENT wp)
        {
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(
                wp.rcNormalPosition_left,
                wp.rcNormalPosition_top,
                wp.rcNormalPosition_right - wp.rcNormalPosition_left,
                wp.rcNormalPosition_bottom - wp.rcNormalPosition_top);

            // スクリーン内に存在するか検証
            System.Windows.Forms.Screen scr = System.Windows.Forms.Screen.FromRectangle(rect);

            // タスクバーを除いた領域内で検証する
            System.Drawing.Rectangle area = scr.WorkingArea;
            if (area.Contains(rect))
            {
                return(true);
            }

            // 表示位置を補正する
            int l = rect.Left, t = rect.Top;

            if (area.Left > rect.Left)
            {
                l = area.Left;
            }
            if (area.Right < rect.Right)
            {
                l = rect.Left - (rect.Right - area.Right);
            }
            if (area.Top > rect.Top)
            {
                t = area.Top;
            }
            if (area.Bottom < rect.Bottom)
            {
                t = rect.Top - (rect.Bottom - area.Bottom);
            }

            System.Drawing.Rectangle tmp = new System.Drawing.Rectangle(l, t, rect.Width, rect.Height);
            if (area.Contains(tmp))
            {
                wp.rcNormalPosition_left   = l;
                wp.rcNormalPosition_top    = t;
                wp.rcNormalPosition_right  = wp.rcNormalPosition_left + rect.Width;
                wp.rcNormalPosition_bottom = wp.rcNormalPosition_top + rect.Height;
                return(false);
            }
            // 中央に補正する
            Rect work = SystemParameters.WorkArea;

            rect.X = (int)((work.Width - rect.Width) / 2.0);
            rect.Y = (int)((work.Height - rect.Height) / 2.0);
            if (rect.Left < 0 || rect.Top < 0)
            {
                // 納まらない場合はサイズを調整する
                wp.rcNormalPosition_left   = 0;
                wp.rcNormalPosition_top    = 0;
                wp.rcNormalPosition_right  = (int)work.Width;
                wp.rcNormalPosition_bottom = (int)work.Height;
            }
            else
            {
                wp.rcNormalPosition_left   = rect.X;
                wp.rcNormalPosition_top    = rect.Y;
                wp.rcNormalPosition_right  = wp.rcNormalPosition_left + rect.Width;
                wp.rcNormalPosition_bottom = wp.rcNormalPosition_top + rect.Height;
            }
            return(false);
        }
Esempio n. 3
0
 public static extern bool    SetWindowPlacement(IntPtr hWnd, [In] ref WINDOWPLACEMENT lpwndpl);