pass info from an MFC app into html script?

Posted on 2003-10-24
Last Modified: 2013-11-25
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!!!

Question by:LilMoke
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
  • 3
LVL 49

Expert Comment

ID: 9620594
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>

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

Author Comment

ID: 9620973
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.


Author Comment

ID: 9621235
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!!!

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 49

Accepted Solution

DanRollins earned 250 total points
ID: 9621854
Glad to thelp!  The best way to thank an Expert here at Experts Exchange is to select that Expert's comment as an answer!  To do that,

1) Look for the [Accept] button in the header above my commnet
2) Click it.
3) Select the "Excellent" radio button
4) Click the [Submit][ button

-- Dan

Author Comment

ID: 9622317

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?

LVL 49

Expert Comment

ID: 9625577
It seems to have accepted.  Tahnks.

As to not using smart pointers...

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

Author Comment

ID: 9626629
Go, 'point' taken... thanks for the help!!!


Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

688 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