🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #1064

TCppWebBrowser and Copy()

#1064
From: Enrique
Date: Wed, 28 Sep 2005 05:05
143 lines
5576 bytes
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: <433a2438@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-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,cf372965ee346cc4,start
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII
Reply-To: "Enrique" <enridp@yahoo.com.ar>
From: "Enrique" <enridp@yahoo.com.ar>
Newsgroups: borland.public.cppbuilder.internet.web
Subject: TCppWebBrowser and Copy()
Date: Wed, 28 Sep 2005 02:05:41 -0300
Lines: 145
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: 200.45.165.180
Message-ID: <433a2438@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1127883832 200.45.165.180 (27 Sep 2005 22:03:52 -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