Article View: borland.public.cppbuilder.internet.web
Article #1078Re: TCppWebBrowser and Copy()
From: Mark Guerrieri
Date: Mon, 03 Oct 2005 16:25
Date: Mon, 03 Oct 2005 16:25
159 lines
6109 bytes
6109 bytes
Call OleInitialize before creating your TCppWebBrowser object to enable
Cut/Copy/Paste etc.
Mark
"Enrique" <enridp@yahoo.com.ar> wrote in message
news:433a2438@newsgroups.borland.com...
> I cannot copy anything from the browser. I was reading and i found that
this
> seems to be a problem from TCppWebBrowser.
> searching in google i found a function that solves this problem (i paste
it
> at the end). but it's not solves MY problem.
> In my html pages i have a javascript function that searches and copy some
> text:
> <script language="Javascript">
> <!--
> function CopiarTxt(texto)
> {
> if(!document.all)
> return;
> var contenido = document.body.createTextRange();
> var temporal = contenido.duplicate();
> var existe = temporal.findText(texto,0,0);
> if(existe)
> {
> temporal.scrollIntoView(true);
> temporal.select();
> temporal.execCommand("Copy");
> }
> }
> //-->
> </script>
>
> It works perfectly out of TCppWebBRowser, and i think the problem is the
> line:
> temporal.execCommand("Copy");
> because the copy command doesn't work.
> Anyone knows how to solve this?
> enrique.
> --------------------------------
> the function:
> --------------------------------
> #include <mshtml.h>
>
>
//--------------------------------------------------------------------------
> -
> // Funktion CopySelectionToClipboard() kopiert die aktuelle Auswahl im
> // TCppWebBrowser in die Zwischenablage
>
//--------------------------------------------------------------------------
> -
> // �bergabeparameter:
> //
> // TCppWebBrowser* pCppWebBrowser: Zeiger auf die TCppWebBrowser-Instanz
> // bool blHtml : Format der Daten
> // (true: HTML-Code, false: Plain Text)
>
//--------------------------------------------------------------------------
> -
> void CopySelectionToClipboard(TCppWebBrowser* pCppWebBrowser, bool blHtml)
> {
> IHTMLDocument2 *HTMLDocument = NULL;
> LONG ilFramesCount = 0;
> wchar_t* wcpSelectedText;
>
> // Falls eine Seite geladen:
> if(SUCCEEDED(pCppWebBrowser->Document->QueryInterface(
> IID_IHTMLDocument2, (LPVOID*)&HTMLDocument)))
> {
> // ggf. auch Frames-Code extrahieren:
> IHTMLFramesCollection2 *pFrames = NULL;
> if(SUCCEEDED(HTMLDocument->get_frames(&pFrames)))
> {
> // Anzahl der Frames bestimmen:
> pFrames->get_length(&ilFramesCount);
>
> if(ilFramesCount == 0)
> {
> IHTMLSelectionObject* pSelection;
> if(SUCCEEDED(HTMLDocument->get_selection(&pSelection)))
> {
> IHTMLTxtRange* pRange;
> if(SUCCEEDED(pSelection->createRange((LPDISPATCH*)&(pRange))))
> {
> if(blHtml)
> {
> if(SUCCEEDED(pRange->get_htmlText(&wcpSelectedText)))
>
> Clipboard()->SetTextBuf(AnsiString(wcpSelectedText).c_str());
> }
> else if(SUCCEEDED(pRange->get_text(&wcpSelectedText)))
>
Clipboard()->SetTextBuf(AnsiString(wcpSelectedText).c_str());
> pRange->Release();
> }
> pSelection->Release();
> }
> }
> else
> {
> VARIANT vFrame;
> VARIANT ret;
> vFrame.vt = VT_UINT;
> // f�r jedes Frame:
> for(LONG ilFrameIndex = 0; ilFrameIndex < ilFramesCount;
> ilFrameIndex++)
> {
> vFrame.lVal = ilFrameIndex;
> if(SUCCEEDED(pFrames->item(&vFrame, &ret)))
> {
> // Zeiger auf IHTMLWindow2 des Frames besorgen:
> IHTMLWindow2 *pWindow = NULL;
> if(SUCCEEDED(ret.pdispVal->QueryInterface(IID_IHTMLWindow2,
> (LPVOID*)&pWindow)))
> {
> // Zeiger auf IHTMLDocument2 des Frames besorgen:
> IHTMLDocument2 *pDoc = NULL;
> if(SUCCEEDED(pWindow->get_document(&pDoc)))
> {
> IHTMLSelectionObject* pSelection;
> if(SUCCEEDED(pDoc->get_selection(&pSelection)))
> {
> IHTMLTxtRange* pRange;
>
> if(SUCCEEDED(pSelection->createRange((LPDISPATCH*)&(pRange))))
> {
> if(blHtml)
> {
> if(SUCCEEDED(pRange->get_htmlText(&wcpSelectedText))
> &&
> AnsiString(wcpSelectedText).Trim() != EmptyStr)
>
> Clipboard()->SetTextBuf(AnsiString(wcpSelectedText).c_str());
> }
> else if(SUCCEEDED(pRange->get_text(&wcpSelectedText))
&&
> AnsiString(wcpSelectedText).Trim() != EmptyStr)
>
> Clipboard()->SetTextBuf(AnsiString(wcpSelectedText).c_str());
> pRange->Release();
> }
> pSelection->Release();
> }
> pDoc->Release();
> }
> pWindow->Release();
> }
> }
> }
> }
> pFrames->Release();
> }
> HTMLDocument->Release();
> }
> }
>
>
Technical Details
Message-ID:
<43415adb$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<433a2438@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,cf372965ee346cc4 X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII From: "Mark Guerrieri" <mguerrieri@nospam_cmsgrp.com> Newsgroups: borland.public.cppbuilder.internet.web References: <433a2438@newsgroups.borland.com> Subject: Re: TCppWebBrowser and Copy() Date: Mon, 3 Oct 2005 12:25:04 -0400 Lines: 161 Organization: Creative Marketing Strategies X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 209.50.174.82 Message-ID: <43415adb$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1128356571 209.50.174.82 (3 Oct 2005 09:22:51 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail