-
Notifications
You must be signed in to change notification settings - Fork 0
/
Win32.cs
109 lines (86 loc) · 3.67 KB
/
Win32.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
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
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace BafflerStandalone
{
public class Win32
{
[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
public static extern int SetWindowsHookEx(int idHook, Win32.WindowsHookProc lpfn, IntPtr hInstance, int threadId);
[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
public static extern bool UnhookWindowsHookEx(int idHook);
[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
public static extern int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
public static extern uint GetDlgItemText(IntPtr hDlg, int nIDDlgItem, [Out] StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
public static extern IntPtr GetDlgItem(IntPtr hDlg, int nIDDlgItem);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool GetWindowRect(IntPtr handle, ref Win32.RECT r);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
[DllImport("kernel32.dll")]
public static extern bool FreeLibrary(IntPtr hModule);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
public static string GetClassName(IntPtr hWnd)
{
StringBuilder stringBuilder = new StringBuilder(100);
Win32.GetClassName(hWnd, stringBuilder, stringBuilder.Capacity);
return stringBuilder.ToString();
}
public static string GetWindowText(IntPtr hWnd)
{
int windowTextLength = Win32.GetWindowTextLength(hWnd);
StringBuilder stringBuilder = new StringBuilder(windowTextLength + 1);
Win32.GetWindowText(hWnd, stringBuilder, stringBuilder.Capacity);
return stringBuilder.ToString();
}
public static string GetDlgItemText(IntPtr hDlg, int nIDDlgItem)
{
IntPtr dlgItem = Win32.GetDlgItem(hDlg, nIDDlgItem);
if (dlgItem == IntPtr.Zero)
{
return null;
}
int windowTextLength = Win32.GetWindowTextLength(dlgItem);
StringBuilder stringBuilder = new StringBuilder(windowTextLength + 1);
Win32.GetWindowText(dlgItem, stringBuilder, stringBuilder.Capacity);
return stringBuilder.ToString();
}
public const int WH_CBT = 5;
public const int HCBT_ACTIVATE = 5;
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
public delegate int WindowsHookProc(int nCode, IntPtr wParam, IntPtr lParam);
public class Bit
{
public static int HiWord(int iValue)
{
return iValue >> 16 & 0xFFFF;
}
public static int LoWord(int iValue)
{
return iValue & 0xFFFF;
}
}
}
}