Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

IHTML question

Posted on 2002-04-19
8
Medium Priority
?
610 Views
Last Modified: 2013-11-20
Good-day,

I am writing a program in VC 6.0 that will automate input of text on a web page text box.  I am using the CWebBrowser2 control and here is the code that I am using:

MSHTML::IHTMLDocument2Ptr pDoc= m_web.GetDocument();  MSHTML::IHTMLElementCollectionPtr pAllElems= pDoc->all;
MSHTML::IHTMLInputTextElementPtr pTextInput= pAllElems->item("editbox_name");
pTextInput->value = "some text";

This code is working fine; my problem is that I have encountered a web page that has mulitiple frames, and I need to specify which frame to select before I can run this.
Any ideas?
Thanks very much.
0
Comment
Question by:PastorDwayne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 1

Expert Comment

by:Pavlik
ID: 6955122
You should get the frame from IHTMLDocument2.frames.item("frame name"), cast it to IHTMLWindow2 and get document from it. And after that get elements of this document and do with them whatever you want.
0
 

Author Comment

by:PastorDwayne
ID: 6959433
Could you give me an example as to how to use this. Lets say that the form name that I am trying to access is named "form1"

Thanks
0
 
LVL 1

Expert Comment

by:Pavlik
ID: 6960599
Ok. I have 3 files:
1.html - contains frameset
2.html - contains form
IEManip.cpp - does all the work with them.

Here they are:
1.html
--------------------------------------------
<html>
<frameset>
<frame name="frame1" src="file://c:/2.html">
</frame>
</frameset>
</html>
============================================
2.html
--------------------------------------------
<html>
<body>
<form name="form1" action="about:blank">
<input name="i1" type="text">
</form>
</body>
</html>
============================================
IEManip.cpp
--------------------------------------------
#import <shdocvw.dll>
#import <mshtml.tlb>

int main(int argc, char* argv[])
{
  CoInitialize(0);
  {
    SHDocVw::IWebBrowser2Ptr pIE(__uuidof(SHDocVw::InternetExplorer));
    MSHTML::IHTMLDocument2Ptr pHTMLDoc;
   
    pIE->Visible = true;
    pIE->Navigate("file://c:/1.html");
    while(pIE->GetBusy())
      Sleep(100);
    pIE->GetDocument()->QueryInterface(&pHTMLDoc);

    MSHTML::IHTMLWindow2Ptr pHTMLWnd = (IUnknown*)pHTMLDoc->frames->item(&_variant_t("frame1"));
    MSHTML::IHTMLFormElementPtr pForm = (IUnknown*)pHTMLWnd->document->forms->item(&_variant_t("form1"));
    MSHTML::IHTMLInputElementPtr pInput = (IUnknown*)pForm->item(&_variant_t("i1"));
    pInput->value = "Test string";
  }
  CoUninitialize();
  return 0;
}
============================================

You should put 1.html and 2.html to the root of disk C.

Let me know if you have more questions about this.
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

Author Comment

by:PastorDwayne
ID: 6960954
This code looks great... just a few questions about it.  

1.  I would like to incorporate the ActiveX WebBrowser control inside a dialog box rather than IE.

2. I searched the HTML source code for this web page that I am trying to access, and there doesn't seem to be a <frame name> tag anywhere. Is there a default value I can use for this?

Thanks.
0
 
LVL 1

Accepted Solution

by:
Pavlik earned 1000 total points
ID: 6961137
If you don't have frame names, then just select frame by its index.

Remove attribute name from frame tag from 1.html:
<frame src="file://c:/2.html">
And change:
MSHTML::IHTMLWindow2Ptr pHTMLWnd = (IUnknown*)pHTMLDoc->frames->item(&_variant_t("frame1"));
to:
MSHTML::IHTMLWindow2Ptr pHTMLWnd = (IUnknown*)pHTMLDoc->frames->item(&_variant_t(0L));


That's all you need.

> 1.  I would like to incorporate the ActiveX WebBrowser control inside a dialog box rather than IE.
Let's connect it to your code:
=====================================
MSHTML::IHTMLDocument2Ptr pDoc= m_web.GetDocument(); // This is what you have in the first line

//And this is the remaining
MSHTML::IHTMLWindow2Ptr pHTMLWnd = (IUnknown*)pDoc->frames->item(&_variant_t(0L));
MSHTML::IHTMLFormElementPtr pForm = (IUnknown*)pHTMLWnd->document->forms->item(&_variant_t("form1"));
MSHTML::IHTMLInputElementPtr pInput = (IUnknown*)pForm->item(&_variant_t("i1"));
pInput->value = "Test string";
======================================

Just you can get IWebBrowser2 interface from IE and from WebBrowser control. And it will always have document inside.
0
 

Author Comment

by:PastorDwayne
ID: 6962543
I can't seem to get this code to work.  For example, I load the www.yahoo.com page in my WebBrowser and have a button that is attatched to this code:

     
MSHTML::IHTMLDocument2Ptr pDoc= m_web.GetDocument();

MSHTML::IHTMLWindow2Ptr pHTMLWnd = (IUnknown*)pDoc->frames->item(&_variant_t(0L));
MSHTML::IHTMLFormElementPtr pForm = (IUnknown*)pHTMLWnd->document->forms->item(&_variant_t("f"));
MSHTML::IHTMLInputElementPtr pInput = (IUnknown*)pForm->item(&_variant_t("p"));
pInput->value = "Test string";

The yahoo page form name seems to be "f" and the input edit box is "p". But when I try to run this, the program crashes.

Any ideas?

thanks.
0
 
LVL 1

Expert Comment

by:Pavlik
ID: 6963317
The problem here is that Yahoo page doesn't have frames. So you should simply get the form from the root document.

MSHTML::IHTMLFormElementPtr pForm = (IUnknown*)pDoc->forms->item(&_variant_t("f"));
MSHTML::IHTMLInputElementPtr pInput = (IUnknown*)pForm->item(&_variant_t("p"));
pInput->value = "Test string";
Sleep(5000);
pForm->submit();


0
 

Author Comment

by:PastorDwayne
ID: 6973182
Pavlik,

This worked great! Thanks very much for your help.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question