VBA通过使用enumchildwindows进行枚举

时间:2017-08-18 05:38:11

标签: excel vba excel-vba

我正在尝试创建一个与我们的外部应用程序通信的Excel文档。

我发送消息对于WM_GETTEXT从特定窗口运行良好,但我无法进入下一个子窗口,因为类名都是相同的:

enter image description here

我的第一个代码从名为“WindowsForms10.EDIT.app.0.2004eee”的父窗口下的第一个类中抓取文本

 Grange = FindWindow(vbNullString, "General Account Enquiry")
 Account_number = FindWindowEx(Grange, 0&,   "WindowsForms10.EDIT.app.0.2004eee", vbNullString)

 the_count = SendMessage(Account_number, WM_GETTEXTLENGTH, 0&, 0&)

 Buffer$ = Space$(the_count)
 Call SendMessageByString(Account_number, WM_GETTEXT, the_count + 1, Buffer$)

但我还需要从带圆圈的红色框中抓取文本,该框具有相同的类名。我只有API调用的经验,其中类名是唯一的。

我被一个非常有用的stackoverflow撰稿人告诉我使用enumchildwindows循环浏览其他5个同名的子窗口,但经过几天的搜索后,我找不到合适的代码来执行此操作

是否有人能够提供帮助或提供我可以使用的示例代码?

非常感谢

1 个答案:

答案 0 :(得分:1)

看起来我在发布此信息后约5分钟就设法弄明白了,

Grange = FindWindow(vbNullString,"一般帐户查询")

Account_number = FindWindowEx(Grange, 0&, "WindowsForms10.EDIT.app.0.2004eee", vbNullString)
Account_number2 = FindWindowEx(Grange, Account_number, "WindowsForms10.EDIT.app.0.2004eee", vbNullString)
Account_number3 = FindWindowEx(Grange, Account_number2, "WindowsForms10.EDIT.app.0.2004eee", vbNullString)
Account_number4 = FindWindowEx(Grange, Account_number3, "WindowsForms10.EDIT.app.0.2004eee", vbNullString)
Account_number5 = FindWindowEx(Grange, Account_number4, "WindowsForms10.EDIT.app.0.2004eee", vbNullString)
Account_number6 = FindWindowEx(Grange, Account_number5, "WindowsForms10.EDIT.app.0.2004eee", vbNullString)
Account_number7 = FindWindowEx(Grange, Account_number6, "WindowsForms10.EDIT.app.0.2004eee", vbNullString)

the_count = SendMessage(Account_number6, WM_GETTEXTLENGTH, 0&, 0&)

Buffer$ = Space$(the_count)
Call SendMessageByString(Account_number6, WM_GETTEXT, the_count + 1, Buffer$)

ThisWorkbook.Sheets("Sheet1").Range("A2") = Buffer$