예제 #1
0
 static AppBarEdge GetEdge(ref RECT rc)
 {
     if (rc.top == rc.left && rc.bottom > rc.right)
         return AppBarEdge.ABE_LEFT;
     else if (rc.top == rc.left && rc.bottom < rc.right)
         return AppBarEdge.ABE_TOP;
     else if (rc.top > rc.left)
         return AppBarEdge.ABE_BOTTOM;
     else
         return AppBarEdge.ABE_RIGHT;
 }
예제 #2
0
        public static void AdjustForAutoHideTaskbar(IntPtr hAppMonitor, ref RECT workspace)
        {
            // NOTE: for xp the adjustment for autohidden taskbar makes maximized window movable
            // but I don't know the way to fix it.
            IntPtr htaskbar = User32.FindWindow("Shell_TrayWnd", null);
            if (htaskbar != IntPtr.Zero)
            {
                IntPtr monitorWithTaskbarOnIt = User32.MonitorFromWindow(htaskbar, MonitorOption.MONITOR_DEFAULTTONEAREST);
                if (hAppMonitor.Equals(monitorWithTaskbarOnIt))
                {
                    APPBARDATA abd = new APPBARDATA();
                    abd.cbSize = (uint)Marshal.SizeOf(abd);
                    abd.hWnd = htaskbar;
                    bool autoHide = (Shell32.SHAppBarMessage(AppBarMessage.ABM_GETSTATE, ref abd).ToUInt32() & ABS_AUTOHIDE) == ABS_AUTOHIDE;

                    if (autoHide)
                    {
                        Shell32.SHAppBarMessage(AppBarMessage.ABM_GETTASKBARPOS, ref abd);
                        var uEdge = GetEdge(ref abd.rc);

                        switch (uEdge)
                        {
                            case AppBarEdge.ABE_LEFT:
                                workspace.left += 2;
                                break;
                            case AppBarEdge.ABE_RIGHT:
                                workspace.right -= 2;
                                break;
                            case AppBarEdge.ABE_TOP:
                                workspace.top += 2;
                                break;
                            case AppBarEdge.ABE_BOTTOM:
                                workspace.bottom -= 2;
                                break;
                        }
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// translate screen pixels to wpf units for high-dpi scaling.
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        private Rect TranslateToWpf(RECT r)
        {
            var source = PresentationSource.FromVisual(
                this.Visibility == Visibility.Visible ?
                this : _contentWindow);
            if (source != null)
            {
                var transform = source.CompositionTarget.TransformToDevice;
                if (!transform.IsIdentity)
                {
                    var xScale = transform.M11;
                    var yScale = transform.M22;

                    return new Rect(r.left / xScale, r.top / yScale, r.Width / xScale, r.Height / yScale);
                }
            }
            return new Rect(r.left, r.top, r.Width, r.Height);
        }
예제 #4
0
 /// <summary>
 /// Creates a rectangular region.
 /// </summary>
 /// <param name="rc"> RECT structure that contains the coordinates of the upper-left and lower-right corners of the rectangle that defines the region in logical units.</param>
 /// <returns></returns>
 public static IntPtr CreateRectRgnIndirect(ref RECT rc)
 {
     return NativeMethods.CreateRectRgnIndirect(ref rc);
 }
예제 #5
0
 public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
예제 #6
0
 /// <summary>
 /// Retrieves a handle to the display monitor that has the largest area of intersection with a specified rectangle.
 /// </summary>
 /// <param name="rect">RECT structure that specifies the rectangle of interest in virtual-screen coordinates.</param>
 /// <param name="option">Determines the function's return value if the rectangle does not intersect any display monitor.</param>
 /// <returns></returns>
 public static IntPtr MonitorFromRect(ref RECT rect, MonitorOption option)
 {
     return NativeMethods.MonitorFromRect(ref rect, option);
 }
예제 #7
0
 /// <summary>
 /// Retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
 /// </summary>
 /// <param name="hWnd">A handle to the window.</param>
 /// <param name="rect">RECT structure that receives the screen coordinates of the upper-left and lower-right corners of the window.</param>
 /// <returns></returns>
 public static bool GetWindowRect(IntPtr hWnd, ref RECT rect)
 {
     return NativeMethods.GetWindowRect(hWnd, ref rect);
 }