Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Webbrowser - simulate user actions on website-controls via QueryInterface

Webbrowser - simulate user actions on website-controls via QueryInterface

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++phphtmlannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mathefreak
    wrote on last edited by
    #1

    Hi, I've got one question using the WebBrowserControl. In my app a self refreshing website http://www.forexpf.ru/quote_show.php[^] is loaded in a webbrowser-control. The text content of the site is captured by QueryInterface() into a String to parse some data. This works fine, but ... On the website there is a list box and an button at the bottom, from which you can choose the interval for automatic refreshing the site. On initial loading 1min is chosen, but I want to change this to the shortest value (30sec). All the stuff is hidden, so the input should come from code (maybe via QueryInterface?). Are there any ideas to grab the list-control and the button and change the value? Here are the sample code for grabbing the content: - simple MFC-Dialog - one Webbrowser control (m_WebBrowserCtrl) - website is loaded and refreshed by button click - by clicking on a button the content of the site (plain text, not the html source) is copied into a CString variable to parse the data. void CWebbrowser_TestDlg::OnCopy() { IHTMLDocument2* m_pHTMLDocument2; LPDISPATCH lpDispatch; lpDispatch = m_WebBrowserCtrl.GetDocument(); HRESULT hr; if (lpDispatch) { hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&m_pHTMLDocument2); lpDispatch->Release(); ASSERT(SUCCEEDED(hr)); } CString sText; IHTMLElement *iSource; BSTR bstrSource; m_pHTMLDocument2->get_body(&iSource); iSource->get_outerText(&bstrSource); sText = bstrSource; MessageBox(sText); } TIA and greets M.

    R 1 Reply Last reply
    0
    • M Mathefreak

      Hi, I've got one question using the WebBrowserControl. In my app a self refreshing website http://www.forexpf.ru/quote_show.php[^] is loaded in a webbrowser-control. The text content of the site is captured by QueryInterface() into a String to parse some data. This works fine, but ... On the website there is a list box and an button at the bottom, from which you can choose the interval for automatic refreshing the site. On initial loading 1min is chosen, but I want to change this to the shortest value (30sec). All the stuff is hidden, so the input should come from code (maybe via QueryInterface?). Are there any ideas to grab the list-control and the button and change the value? Here are the sample code for grabbing the content: - simple MFC-Dialog - one Webbrowser control (m_WebBrowserCtrl) - website is loaded and refreshed by button click - by clicking on a button the content of the site (plain text, not the html source) is copied into a CString variable to parse the data. void CWebbrowser_TestDlg::OnCopy() { IHTMLDocument2* m_pHTMLDocument2; LPDISPATCH lpDispatch; lpDispatch = m_WebBrowserCtrl.GetDocument(); HRESULT hr; if (lpDispatch) { hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&m_pHTMLDocument2); lpDispatch->Release(); ASSERT(SUCCEEDED(hr)); } CString sText; IHTMLElement *iSource; BSTR bstrSource; m_pHTMLDocument2->get_body(&iSource); iSource->get_outerText(&bstrSource); sText = bstrSource; MessageBox(sText); } TIA and greets M.

      R Offline
      R Offline
      Rajkumar R
      wrote on last edited by
      #2

      Hi, I guess you need to get the element of button and select box Give an id to the element in the web page get the document 3 interface

      m_pHTMLDocument2->QueryInterface<IHTMLDocument3>(&spHTMLDocument3);
      spHTMLDocument3->getElementById(spbstrID/*your id*/, &spHtmlElm);

      /* you can also use getElementsByName if you know the element name */

      spHtmlElm->QueryInterface<IHTMLButtonElement>(&spBtnElm);
      if (spBtnElm)
      {
      /* if the element was a button element set the required value */
      spBtnElm->put_value(spBSTRValue);
      }

      For list element you need to create option element to add an list item. Best Regards Raj

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups