Repository navigation
Expand file tree
/
Copy pathNativeWin32.cs
More file actions
128 lines (104 loc) · 4.04 KB
/
Copy pathNativeWin32.cs
File metadata and controls
128 lines (104 loc) · 4.04 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace SharpPlant
{
internal class NativeWin32
{
public delegate int EnumWindowsProcDelegate(int hWnd, int lParam);
public delegate bool EnumChildCallback(int hwnd, ref int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
public const uint BM_CLICK = 0x00F5;
public const int GW_HWNDFIRST = 0;
public const int GW_HWNDLAST = 1;
public const int GW_HWNDNEXT = 2;
public const int GW_HWNDPREV = 3;
public const int GW_OWNER = 4;
public const int GW_CHILD = 5;
public const int MOUSEEVENTF_LEFTDOWN = 0x02;
public const int MOUSEEVENTF_LEFTUP = 0x04;
[DllImport("user32.dll")]
public static extern bool SetCursorPos(int x, int y);
[DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
[DllImport("user32.dll")]
public static extern int FindWindow(
string lpClassName, // class name
string lpWindowName // window name
);
[DllImport("user32.dll")]
public static extern IntPtr GetDlgItem(
IntPtr hDlg, // parent hwnd
int nIdDlgItem // controlID
);
[DllImport("Oleacc.dll")]
public static extern int AccessibleObjectFromWindow(
int hwnd,
uint dwObjectID,
byte[] riid,
ref dynamic ptr
);
[DllImport("User32.dll")]
public static extern bool EnumChildWindows(
int hWndParent,
EnumChildCallback lpEnumFunc,
ref int lParam
);
// Gets the 'nth' Window of the parent dialog based on the class name
public static IntPtr FindWindowByIndex(IntPtr hWndParent, int index)
{
if (index == 0)
return hWndParent;
var ct = 0;
var result = IntPtr.Zero;
do
{
result = FindWindowEx(hWndParent, result, "Button", null);
if (result != IntPtr.Zero)
++ct;
} while (ct < index && result != IntPtr.Zero);
return result;
}
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(
IntPtr parentHandle, // parent HWND
IntPtr childAfter,
string className, // name of the class
string windowTitle // title of the child window
);
[DllImport("user32.dll")]
public static extern int SendMessage(
int hWnd, // handle to destination window
uint msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(
int hWnd // handle to window
);
[DllImport("User32.dll")]
public static extern int GetClassName(
int hWnd,
StringBuilder lpClassName,
int nMaxCount
);
[DllImport("user32.dll")]
public static extern bool LockWindowUpdate(IntPtr hWndLock);
[DllImport("user32")]
public static extern int EnumWindows(EnumWindowsProcDelegate lpEnumFunc, int lParam);
[DllImport("User32.Dll")]
public static extern void GetWindowText(int h, StringBuilder s, int nMaxCount);
[DllImport("user32", EntryPoint = "GetWindowLongA")]
public static extern int GetWindowLongPtr(int hwnd, int nIndex);
[DllImport("user32")]
public static extern int GetParent(int hwnd);
[DllImport("user32")]
public static extern int GetWindow(int hwnd, int wCmd);
[DllImport("user32")]
public static extern int IsWindowVisible(int hwnd);
[DllImport("user32")]
public static extern int GetDesktopWindow();
}
}