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
Solved

pass info from an MFC app into html script?

Posted on 2003-10-24
7
209 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sumHeights  challenge 17 74
unix example issues 18 99
Please explain the parts of these 2 LINQ expressions 3 53
SSRS Deployment problem 5 66
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
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…

839 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