Skip to content

Commit

Permalink
fallback on default monitor if current monitor cannot be determined
Browse files Browse the repository at this point in the history
  • Loading branch information
maximcus committed Dec 8, 2016
1 parent 65b58e1 commit 7c1ad11
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
3 changes: 2 additions & 1 deletion WPFTabTip/AnimationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ private static double GetYOffsetToMoveUIElementInToWorkArea(Rectangle uiElementR
const int paddingTop = 30;
const int paddingBottom = 10;

if (workAreaRectangle.Contains(uiElementRectangle)) // UIElement is in work area
if (uiElementRectangle.Top >= workAreaRectangle.Top &&
uiElementRectangle.Bottom <= workAreaRectangle.Bottom) // UIElement is in work area
return noOffset;

if (uiElementRectangle.Top < workAreaRectangle.Top) // Top of UIElement higher than work area
Expand Down
41 changes: 38 additions & 3 deletions WPFTabTip/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ internal class Screen

public Screen(Window window)
{
IntPtr windowHandle = new WindowInteropHelper(window).Handle;
IntPtr monitor = NativeMethods.MonitorFromWindow(windowHandle, NativeMethods.MONITOR_DEFAULTTONEAREST);
IntPtr windowHandle = window != null ? new WindowInteropHelper(window).Handle : IntPtr.Zero;

IntPtr monitor = window != null ? NativeMethods.MonitorFromWindow(windowHandle, NativeMethods.MONITOR_DEFAULTTONEAREST) : NativeMethods.MonitorFromPoint(new NativeMethods.POINT(0, 0), NativeMethods.MonitorOptions.MONITOR_DEFAULTTOPRIMARY);

NativeMethods.NativeMonitorInfo monitorInfo = new NativeMethods.NativeMonitorInfo();
NativeMethods.GetMonitorInfo(monitor, monitorInfo);
Expand Down Expand Up @@ -46,6 +46,41 @@ public struct NativeRectangle
public readonly int Bottom;
}

[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;

public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}

public POINT(System.Drawing.Point pt) : this(pt.X, pt.Y) { }

public static implicit operator System.Drawing.Point(POINT p)
{
return new System.Drawing.Point(p.X, p.Y);
}

public static implicit operator POINT(System.Drawing.Point p)
{
return new POINT(p.X, p.Y);
}
}

[DllImport("user32.dll", SetLastError = true)]
internal static extern IntPtr MonitorFromPoint(POINT pt, MonitorOptions dwFlags);

internal enum MonitorOptions : uint
{
MONITOR_DEFAULTTONULL = 0x00000000,
MONITOR_DEFAULTTOPRIMARY = 0x00000001,
MONITOR_DEFAULTTONEAREST = 0x00000002
}

#pragma warning disable 169

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
Expand Down

0 comments on commit 7c1ad11

Please sign in to comment.