Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

How can I programmatically get the displayed text from tcppwebbrowser?

How can I programmatically get the displayed text from tcppwebbrowser?

I'm currently using

  WB1->ExecWB(Shdocvw_tlb::OLECMDID_SELECTALL,0,TNoParam(),TNoParam());
  WB1->ExecWB(Shdocvw_tlb::OLECMDID_COPY,0,TNoParam(),TNoParam());
  WB1->ExecWB(Shdocvw_tlb::OLECMDID_CLEARSELECTION,0,TNoParam(),TNoParam());

  if( Clipboard()->HasFormat(CF_TEXT) )
  {
     *S = Clipboard()->AsText;
     return true;
  }

However, it causes my pc to freak out.  I can't open any new Internet Explorer windows while the program is running after this.
0
mattsimmons
Asked:
mattsimmons
1 Solution
 
AxterCommented:
Here's some code I pull out of the newsgroup:

#include <mshtml.h>

IHTMLDocument2 *HTMLDocument = NULL;
IPersistFile *PersistFile = NULL;

if(SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&HTMLDocument)))
{
    if(SUCCEEDED(HTMLDocument->QueryInterface(IID_IPersistFile, (LPVOID*)&PersistFile)))
    {
        PersistFile->Save(WideString(String("temp.html")), true);
        PersistFile->Release();
    }  HTMLDocument->Release();
}

// Then load the text into a TStringList

TStringList *HTMLSource = new TStringList;
HTMLSource->LoadFromFile("temp.html");
// use HTMLSource then...
delete HTMLSource;


Hope it helps
0
 
mattsimmonsAuthor Commented:
Actually, that solution only reads the source code from the browser, not the displayed text.  I found a solution to my own problem.  

Thank you though.

My own solution...

IHTMLDocument2 * Doc;
IHTMLElement * Element;
try
{
  if(!WB1->Document || !SUCCEEDED(WB1->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&Doc)))
  {
     return false;
  }

  if (!Doc )
  {
    ShowMessage("Failed to load document interface to IE");
    return false;
  }

  Element = Doc->body;
  Doc->Release();

  IESourceText = Element->get_innerHTML();
  IEDisplayedText = Element->get_innerText()
0
 
DanRollinsCommented:
You can and should close this question to get it out of the Open Queue.  Please see:
   
http://www.apollois.com/EE/Help/Closing_Questions.htm#AnsMyOwnQues
for info and tips.
-- Dan
0
 
MindphaserCommented:
mattsimmons asked to have this question closed. If there isn't any objection I will
 
  PAQ & refund

in 72 hours.

** Mindphaser - Community Support Moderator **
0
 
SpideyModCommented:
PAQ'd and all 250 points refunded.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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