Solved

pass info from an MFC app into html script?

Posted on 2003-10-24
7
207 Views
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!!!

Tony
0
Comment
Question by:LilMoke
  • 4
  • 3
7 Comments
 
LVL 49

Expert Comment

by:DanRollins
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>
                ...
        </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
 

Author Comment

by:LilMoke
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.

Thanks,
Tony
0
 

Author Comment

by:LilMoke
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!!!

Tony
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 49

Accepted Solution

by:
DanRollins earned 250 total points
ID: 9621854
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
 

Author Comment

by:LilMoke
ID: 9622317
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 9625577
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
 

Author Comment

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

Tony
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

896 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now