Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

winapi find child windows title (properties) of web page dialog

I am using winapi to handle web page dialog, and I don't have access to visual studio or other tools except excel vba editor. Also, I am not well experienced with winapi. I want to click on some button of this web page dialog and enter some text.
Using winapi I could find it's handle and tried enumerating child windows, but info received is not proper.

' search for child window accept button
hWndAccept = FindWindowEx(hWndColo, 0, vbNullString, vbNullString)
Debug.Print hWndAccept

and

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

The first function doesn't returns button child windows even if I use "button" type (html button type is may be little bit differnt), so I thought enumerating child window. Doing this I get count of 9 child windows, of which I get title's of two only. getwindows text is not displaying anything.

How could I get properties and other related info about these child windows? I tried finding in winapi documenation but no luck.

like image 449
msinfo Avatar asked Aug 27 '13 19:08

msinfo


1 Answers

The IE browser window is a "heavy" component in that it is a true window with a hWnd. The content inside of the browser window (the web page) is all rendered/painted and doesn't exist as actual windows components (e.g. not a real textbox, button, list, etc) and so the Windows API won't work.

You have a few options.

  1. Instantiate a WebBrowser control in a Form in your project (You can see more about the control in general here)

  2. Connect to an existing one using the Windows API like you can see here but that is rife with issues including:

    • IE security and group policy can disable the ability for components to be on the whitelist to connect to an existing component
    • If this IS allowed you can still run into issues with AV blocking it
    • Changes to the IE window layout gets tricky as v7 vs v8 have a change where the IE "frame" (not an iframe) lies in relation to the "document" inside of a tab.

If you are initiating the navigation (e.g. open IE to go to a certain webpage) to fill out a form based on the document then I'd suggest using the webbrowser control or create the ShDocVw component in code so you can interact with the DOM directly. This way you don't have to "find" the HTML elements using windows API's at all and can work directly with the HTML document and its properties.

like image 153
Shawn E Avatar answered Oct 02 '22 05:10

Shawn E