[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

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
0
LilMoke
Asked:
LilMoke
  • 4
  • 3
1 Solution
 
DanRollinsCommented:
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
0
 
LilMokeAuthor Commented:
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
0
 
LilMokeAuthor Commented:
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
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
DanRollinsCommented:
LilMoke,
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
0
 
LilMokeAuthor Commented:
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
0
 
DanRollinsCommented:
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
0
 
LilMokeAuthor Commented:
Go, 'point' taken... thanks for the help!!!

Tony
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now