我正在尝试从Windows中的extern桌面应用程序中检索信息。
我知道如何从Textboxes(类“Edit”)中提取文本,但我不知道如何从类名为“ThunderRT6ListBox”和“ThunderRT6ComboBox”的控件中提取值。我怎么能这样做?
我有这段代码从文本框中提取文本:
public static class ModApi
{
[DllImport("user32.dll", EntryPoint = "FindWindowA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public 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);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, StringBuilder lParam);
const int LB_GETCOUNT = 0x018B;
const int LB_GETTEXT = 0x0189;
public static string GetText(IntPtr hwnd)
{
var text = new StringBuilder(1024);
if (SendMessageTimeoutText(hwnd, 0xd, 1024, text, 0x2, 1000, 0) != 0)
{
return text.ToString();
}
return "";
}
}
public foo()
{
IntPtr value = new IntPtr(0x019C086A); //ID locate using Spy++
String caption = ModApi.GetText(value);
}
更新1:
从ListBox读取的方式:
public static List<string> GetListBoxContents(IntPtr listBoxHwnd)
{
int cnt = (int)SendMessage(listBoxHwnd, LB_GETCOUNT, IntPtr.Zero, null);
List<string> listBoxContent = new List<string>();
for (int i = 0; i < cnt; i++)
{
StringBuilder sb = new StringBuilder(256);
IntPtr getText = SendMessage(listBoxHwnd, LB_GETTEXT, (IntPtr)i, sb);
listBoxContent.Add(sb.ToString());
}
return listBoxContent;
}
更新2:
从ComboBox读取的方式:
public static List<string> GetComboBoxContents(IntPtr cbBoxHwnd)
{
int cnt = (int)SendMessage(cbBoxHwnd, CB_GETCOUNT, IntPtr.Zero, null);
List<string> listBoxContent = new List<string>();
for (int i = 0; i < cnt; i++)
{
//int txtLength = SendMessage(cbBoxHwnd, CB_GETLBTEXTLEN, i, 0);
StringBuilder sb = new StringBuilder(256);
IntPtr getText = SendMessage(cbBoxHwnd, CB_GETLBTEXT, (IntPtr)i, sb);
listBoxContent.Add(sb.ToString());
}
return listBoxContent;
}
答案 0 :(得分:3)
您正在从eons前处理VB6应用程序。 “迅雷”是VB产品/项目的内部名称(简单的旁注)。
你比你意识到的更近。如果你有控制权的HWND,我认为你这样做:
您可能会再考虑SendMessage的一个声明/别名,它只返回一个int,这会使其中一些调用变得更简单。
如果我有机会,稍后我会用一个更具体的代码示例(或至少是伪代码)清理它,但我得到的印象是你已经在正确的轨道上了,可能只需要这个完成其余部分的基本描述。
祝你好运!