msi*_*nfo 6 windows excel winapi vba
我使用winapi来处理网页对话框,除了excel vba编辑器,我无法访问visual studio或其他工具.另外,我对winapi的经验不足.我想点击此网页对话框的某个按钮并输入一些文字.
使用winapi我可以找到它的句柄并尝试枚举子窗口,但收到的信息不正确.
' search for child window accept button
hWndAccept = FindWindowEx(hWndColo, 0, vbNullString, vbNullString)
Debug.Print hWndAccept
Run Code Online (Sandbox Code Playgroud)
和
Public Function EnumChildProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim slength As Long
Dim wintext As String ' window title text length and buffer
Dim retval As Long ' return value
Dim textlen As Long
Static winnum As Integer ' counter keeps track of how many windows have been enumerated
winnum = winnum + 1
textlen = GetWindowTextLength(hWnd) + 1
' Make sufficient room in the buffer.
wintext = Space(textlen)
' Retrieve the text of window Form1.
slength = GetWindowText(hWnd, wintext, textlen)
' Remove the empty space from the string, if any.
wintext = Left(wintext, slength)
' Display the result.
Debug.Print winnum & wintext
EnumChildProc = 1 ' nonzero return value means continue enumeration
End Function
Run Code Online (Sandbox Code Playgroud)
即使我使用"按钮"类型(html按钮类型可能有点不同),第一个函数也不返回按钮子窗口,所以我想枚举子窗口.这样做我得到了9个子窗口,其中我只获得了两个标题.getwindows文本没有显示任何内容.
我如何获得有关这些子窗口的属性和其他相关信息?我尝试在winapi文件中找到但没有运气.
小智 2
IE 浏览器窗口是一个“重”组件,因为它是一个带有 hWnd 的真正窗口。浏览器窗口(网页)内的内容都是渲染/绘制的,并不作为实际的窗口组件存在(例如不是真正的文本框、按钮、列表等),因此 Windows API 将不起作用。
你有几个选择。
在项目的表单中实例化 WebBrowser 控件(您可以在此处查看有关该控件的更多信息)
使用 Windows API 连接到现有的 API,如您在此处看到的那样,但这充满了问题,包括:
如果您要启动导航(例如打开 IE 转到某个网页)以根据文档填写表单,那么我建议使用 webbrowser 控件或在代码中创建 ShDocVw 组件,以便您可以直接与 DOM 交互。这样,您根本不必使用 Windows API“查找”HTML 元素,并且可以直接使用 HTML 文档及其属性。