-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathPInvokeExtensions.cs
More file actions
66 lines (59 loc) · 1.93 KB
/
Copy pathPInvokeExtensions.cs
File metadata and controls
66 lines (59 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma warning disable CS0618
// ReSharper disable once CheckNamespace
namespace Windows.Win32
{
using global::System.Runtime.CompilerServices;
using global::System.Windows;
using Windows.Win32.Foundation;
using Windows.Win32.UI.WindowsAndMessaging;
internal static class PInvokeExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsEmpty(this RECT rect)
{
return rect.left >= rect.right || rect.top >= rect.bottom;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetWidth(this RECT rect)
{
return rect.right - rect.left;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetHeight(this RECT rect)
{
return rect.bottom - rect.top;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Point GetPosition(this RECT rect)
{
return new Point(rect.left, rect.top);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Size GetSize(this RECT rect)
{
return new Size(rect.GetWidth(), rect.GetHeight());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RECT ToRECT(this Rect rect)
{
return new()
{
left = (int)rect.Left,
top = (int)rect.Top,
right = (int)rect.Right,
bottom = (int)rect.Bottom
};
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RECT ToRECT(this WINDOWPOS windowpos)
{
return new()
{
left = windowpos.x,
top = windowpos.y,
right = windowpos.x + windowpos.cx,
bottom = windowpos.y + windowpos.cy
};
}
}
}