-
Notifications
You must be signed in to change notification settings - Fork 0
/
WinAPI.cs
49 lines (40 loc) · 1.39 KB
/
WinAPI.cs
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
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace GameOCRTTS
{
internal static class WinAPI
{
[DllImport("user32.dll")]
internal static extern IntPtr GetForegroundWindow();
internal static IntPtr GetActiveWindow()
{
IntPtr handle = IntPtr.Zero;
return GetForegroundWindow();
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
internal static Rectangle GetActiveWindowRect()
{
IntPtr actwind = GetActiveWindow();
GetWindowRect(actwind, out RECT actwindrect);
Rectangle bounds = new Rectangle
{
X = actwindrect.Left,
Y = actwindrect.Top,
Width = actwindrect.Right - actwindrect.Left,
Height = actwindrect.Bottom - actwindrect.Top
};
return bounds;
}
}
[StructLayout(LayoutKind.Sequential)]
internal struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
}