Link to home
Start Free TrialLog in
Avatar of LilMoke
LilMoke

asked on

pass info from an MFC app into html script?

Hello, this question may be for Dan Rollins!!!  I saw a posting where he explained how to get info from html to MFC.  I already know how to do tyhat, but I need to know the best way to put data back into a form.

I have an edit field in my html document in a form section and I need to set it to a value from MFC before the page appears.  I have a CHtmlView.

I have been struggling with this for quite awhile and it is important that I solve this as soon as possible.  Any help would be greatly appreciated!!!

Tony
Avatar of DanRollins
DanRollins
Flag of United States of America image

If you control the html (for instance, if you generate the html file yourself, write it to a local file, and then display it in the view)  and then it is a simple matter of inserting value="xxxxxx" in the <input type=text> tag.

More than likely, you are getting the page from a website and you want to pre-fill some of the input itmes.  You can't actually do it *before* the page is displayed, but you can do it a millisecond afterwards, which is usually just as good:

1) You can't do anything until the OnDocumentComplete() fn is executed (you probably know that).  

2) I assume you are allreday using #import to get access to the HTML DOM smart pointers

3) You need to know the ID or name of the target field.  You must use a text editor to eyeball the html source.  You will find something like:

        <form name=xxxx ...>
                Enter your Last Name here: <input type=text name='lastName' size=30>
                ...
        </form>

so the target ID is "lastName".  You can use code like the following to change its value:

      MSHTML::IHTMLDocument2Ptr pDoc= m_ctlBrowser.GetDocument();
      MSHTML::IHTMLElementCollectionPtr pAllElems= pDoc->all;

      int nCnt= pAllElems->length; // eyeball check.  It WORKS!

      MSHTML::IHTMLInputTextElementPtr pElem= pAllElems->item("lastName"); // << from the html

      pElem->Putvalue ("Buford Brimly" );

4) You are done.  Award points an select "Execllent" for the grade :)

-- Dan
Avatar of LilMoke
LilMoke

ASKER

Thanks Dan,  unfortunately, I am not using smart pointers.  I can go ahead an use them, but it may be easier if I do not have to.  Is there a way to do this without using them?  If not, I will go ahead and implement your suggestion.

Thanks,
Tony
Avatar of LilMoke

ASKER

Dan, I did implement a variation with smart pointers and it works.  I am still curious if there is a way to do this without them, but my problem is solved never the less.  Thanks!!!

Tony
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LilMoke

ASKER

Dan,

I am still curious if there is a way to do this without smart pointers, do you know of anyway to accomplish that?

I tried to accept and it said, "You may not accept this answer" all in red!!!  I would love to accept, but why can't I?

Thanks,
Tony
It seems to have accepted.  Tahnks.

As to not using smart pointers...
Why?

Working with COM objects in C++ is very difficult.  The language has no native support for the idea of late-binding to objects that were not accessible at compile-time (unlike Visual Basic, JavaScript, C#, and all othermodern programming languages).  So the people at Microsoft came up with a way to translate an IDL file into a compiler-usable .H file and the resulting code is much more readable and usable than alternative methods.

To be honest, COM programming is not my forte...  I just look for example code, try to find matching documentation,  and then try various things until something works.  The *last* thing I want to do is find away to stop using something that makes programming easier :)

-- Dan
Avatar of LilMoke

ASKER

Go, 'point' taken... thanks for the help!!!

Tony