-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDCS.cs
72 lines (61 loc) · 2.02 KB
/
DCS.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Threading.Tasks;
using System.Numerics; // Vector
using System.Runtime.InteropServices; // DLL business
using System.Diagnostics; // Process
public class DCS
{
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public 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
}
public static async void Monitor(Fingers parent)
{
Vector4 result = new Vector4();
Vector4 lastResult = new Vector4();
IntPtr hWnd;
RECT rect;
while (true)
{
hWnd = GetDCSWindow();
if (hWnd != IntPtr.Zero)
{
GetWindowRect(hWnd, out rect);
result.X = rect.Left;
result.Y = rect.Top;
result.Z = rect.Bottom - rect.Top; // height
result.W = rect.Right - rect.Left; // width
if (result.Z > 600 && !lastResult.Equals(result))
{
parent.HandleDCSWindow(result);
lastResult = result;
}
}
await Task.Delay(5000);
}
}
public static IntPtr GetDCSWindow()
{
IntPtr hWnd = IntPtr.Zero;
foreach (Process pList in Process.GetProcesses())
{
if (pList.MainWindowTitle.Equals("")) continue;
if (pList.ProcessName.Equals("DCS") &&
pList.MainWindowTitle.Contains("Digital Combat Simulator") &&
!pList.MainWindowTitle.Contains("_server"))
{
return pList.MainWindowHandle;
}
}
return hWnd;
}
}