1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <mshtml.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SHDocVw_OCX"
#pragma link "SHDocVw_OCX"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TVariant vFlags = {0}, vTargetFrameName={0}, vPostData={0}, vHeaders={0};
CppWebBrowser1->Navigate((TVariant)"<a href="http://www.site.com/page.html" target="_blank">http://www.site.com/page.html</a>", &vFlags, &vTargetFrameName, &vPostData, &vHeaders);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
AnsiString aContenuText = "";
AnsiString aContenuHTML = "";
Variant vDocument = CppWebBrowser1->ControlInterface->Document;
if (((IDispatch *)vDocument) != NULL)
{
Variant vBody = vDocument.OlePropertyGet("Body");
Variant vContenuText = vBody.OlePropertyGet("InnerText");
Variant vContenuHTML = vBody.OlePropertyGet("InnerHTML");
aContenuText = vContenuText;
aContenuHTML = vContenuHTML;
}
Variant vFileName, vReadOnly, vWDocuments, vWDocument;
Variant vMSWord;
try
{
vMSWord = Variant::CreateObject("Word.Application");
}
catch(...)
{
vMSWord = Variant::CreateObject("Word.Application");
}
vMSWord.OlePropertySet("Visible", true);
vReadOnly = false; // lecture seule
vWDocuments = vMSWord.OlePropertyGet("Documents");
vWDocument = vWDocuments.OleFunction("Add");
vMSWord.OlePropertyGet("Selection").OleProcedure("TypeText",WideString(aContenuHTML));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
IHTMLDocument3 *html = NULL;
IHTMLElement *element = NULL;
BSTR string = L"";
try
{
if (CppWebBrowser1->Document != NULL)
{
OleCheck(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument3,(LPVOID*)&html));
OleCheck(html->get_documentElement(&element));
OleCheck(element->get_outerHTML(&string));
}
}
catch (EOleSysError &eOSE)
{
if (element != NULL)
{
element->Release();
}
if (html != NULL)
{
html->Release();
}
throw eOSE;
}
// return (AnsiString) string;
Variant vFileName, vReadOnly, vWDocuments, vWDocument;
Variant vMSWord;
try
{
vMSWord = Variant::CreateObject("Word.Application");
}
catch(...)
{
vMSWord = Variant::CreateObject("Word.Application");
}
vMSWord.OlePropertySet("Visible", true);
vReadOnly = false; // lecture seule
vWDocuments = vMSWord.OlePropertyGet("Documents");
vWDocument = vWDocuments.OleFunction("Add");
vMSWord.OlePropertyGet("Selection").OleProcedure("TypeText",WideString(string));
}
//--------------------------------------------------------------------------- |
Partager