6

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.

Nicholas Post
  • 1,857
  • 1
  • 18
  • 31
msinfo
  • 1,147
  • 6
  • 21
  • 39
  • 1
    Buttons on a web page are not native Windows controls. You need to use other technologies for that scenario, like [UI Automation](http://msdn.microsoft.com/en-us/library/windows/desktop/ee684009.aspx). For web pages in Internet Explorer see [UI Automation for W3C Accessible Rich Internet Applications Specification](http://msdn.microsoft.com/en-us/library/windows/desktop/ee684013.aspx). – IInspectable Aug 27 '13 at 20:40
  • It seems, we can't use it, because we are using xp machines, and are not allowed to install .NET or any other SDK. My next thought is to change/manipulate JS and GET/POST methods. – msinfo Aug 27 '13 at 21:05
  • Manipulating JScript is going to be a hassle to sneak by virus protection software. – IInspectable Aug 27 '13 at 21:16
  • While you noted that you don't have access to Visual Studio, you can get [Microsoft Visual Studio Express 2012](http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products) free of charge. – IInspectable Aug 27 '13 at 22:42
  • @msinfo please see [**this**](http://stackoverflow.com/questions/17041881/hook-into-a-child-class-systreeview32-of-vbe-window) and [**this**](http://stackoverflow.com/questions/17043924/access-child-nodes-of-systreeview32). Also consider sending `clicks` with a comination of [**this**](http://stackoverflow.com/questions/15922300/passing-value-to-excel-inputbox-from-vb-net) –  Aug 28 '13 at 08:24
  • @mehow Your links do not address the question. Controls on a web page and native Windows controls are unrelated. Techniques that work for native controls will not work for web pages. – IInspectable Aug 28 '13 at 08:49
  • 1
    half way there. you find the ie window, resize it to the button and input box and you can navigate all around it using api and clicks and send keys :) may not be the best way of doing it but definitely an alternative. –  Aug 28 '13 at 08:55
  • @mehow It is halfway there, to another goal. Again, controls on a web page - even if they look identical to native controls - are not. The links you provide operate on **native** controls. The question is about controls on a web page. If you want to interact with controls on a web page use UI Automation as linked to from my first comment. – IInspectable Aug 28 '13 at 16:07
  • i understand what you are saying. I am just giving an alternative –  Aug 28 '13 at 16:26

1 Answers1

2

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.

Shawn E
  • 472
  • 2
  • 8
  • Yes, I did that but, the window which I want to control, is a web page dialog, which gets popped up, when I click a link on web page. Using Shdocvw componenet indeed I can loop through open IE windows, but HWND of web page dialog doesn't shows up(but parents come). And I have a doubt, using WinApi I can find HWND of Web page dialog, and in Shdocvw, there is HWND property. So can I set a IE object to Web page dialog, by which I can control it. Or Web page dialog behave different than normal web page. Any possibility/example of using SHDOCVW or MSHTML library for Web page dialog. – msinfo Sep 03 '13 at 21:15
  • 1
    @msinfo There isn't a HWND that I can find using spy++. However if you're trying to capture the event that prompts the dialog you can do so directly on the DOM element that is triggering it (onClick, onMouseDown, etc.) [See here](http://support.microsoft.com/kb/311284) for more info – Shawn E Sep 04 '13 at 13:57