C# 中的代码
public static class ModApi
{
[DllImport("user32.dll", EntryPoint = "FindWindowA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
[DllImport("user32.dll", EntryPoint = "SendMessageTimeout", SetLastError = true, CharSet = CharSet.Auto)]
public static extern uint SendMessageTimeoutText(IntPtr hWnd, int Msg, int countOfChars, StringBuilder text, uint flags, uint uTImeoutj, uint result);
[DllImport("user32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static internal extern bool EnumChildWindows(IntPtr hWndParent, funcCallBackChild funcCallBack, IntPtr lParam);
public delegate bool funcCallBackChild(IntPtr hWnd, IntPtr lParam);
public static ArrayList TextBoxStrings = new ArrayList();
public static void ParseWindowControls(string WindowTitle)
{
IntPtr hWnd = FindWindow(null, WindowTitle);
TextBoxStrings.Clear();
funcCallBackChild MyCallBack = EnumChildWindowsProc;
EnumChildWindows(hWnd, MyCallBack, IntPtr.Zero);
}
private static bool EnumChildWindowsProc(IntPtr hWndParent, IntPtr lParam)
{
var buffer = new StringBuilder(256);
long Retval = GetClassName(hWndParent, buffer, buffer.Capacity);
if (buffer.ToString() == "Edit" || buffer.ToString() == "Static")
{
TextBoxStrings.Add(GetText(hWndParent));
}
return true;
}
private static string GetText(IntPtr hwnd)
{
var text = new StringBuilder(1024);
if (SendMessageTimeoutText(hwnd, 0xd, 1024, text, 0x2, 1000, 0) != 0)
{
return text.ToString();
}
return "";
}
}